root / src / gr / grnet / pithos / web / client / EditMenu.java @ 8092e326
History | View | Annotate | Download (8.8 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | 63366925 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a57faaf0 | Christos Stathis | */
|
35 | a57faaf0 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a57faaf0 | Christos Stathis | |
37 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.CopyCommand; |
38 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.CutCommand; |
39 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.DeleteCommand; |
40 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.PasteCommand; |
41 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.ToTrashCommand; |
42 | 1e413f9b | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
43 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.FileResource; |
44 | a57faaf0 | Christos Stathis | |
45 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; |
46 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
47 | a57faaf0 | Christos Stathis | |
48 | a57faaf0 | Christos Stathis | import java.util.List; |
49 | a57faaf0 | Christos Stathis | |
50 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
51 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
52 | a57faaf0 | Christos Stathis | import com.google.gwt.resources.client.ClientBundle; |
53 | a57faaf0 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
54 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Command; |
55 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
56 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.MenuBar; |
57 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.MenuItem; |
58 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
59 | a57faaf0 | Christos Stathis | |
60 | a57faaf0 | Christos Stathis | /**
|
61 | a57faaf0 | Christos Stathis | * The 'Edit' menu implementation.
|
62 | a57faaf0 | Christos Stathis | */
|
63 | a57faaf0 | Christos Stathis | public class EditMenu extends PopupPanel implements ClickHandler { |
64 | a57faaf0 | Christos Stathis | |
65 | a57faaf0 | Christos Stathis | /**
|
66 | a57faaf0 | Christos Stathis | * The widget's images.
|
67 | a57faaf0 | Christos Stathis | */
|
68 | a57faaf0 | Christos Stathis | private final Images images; |
69 | a57faaf0 | Christos Stathis | |
70 | a57faaf0 | Christos Stathis | private final MenuBar contextMenu = new MenuBar(true); |
71 | a57faaf0 | Christos Stathis | |
72 | a57faaf0 | Christos Stathis | /**
|
73 | a57faaf0 | Christos Stathis | * An image bundle for this widget's images.
|
74 | a57faaf0 | Christos Stathis | */
|
75 | a57faaf0 | Christos Stathis | public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images { |
76 | a57faaf0 | Christos Stathis | |
77 | a57faaf0 | Christos Stathis | /**
|
78 | a57faaf0 | Christos Stathis | * Will bundle the file 'editcut.png' residing in the package
|
79 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
80 | a57faaf0 | Christos Stathis | *
|
81 | a57faaf0 | Christos Stathis | * @return the image prototype
|
82 | a57faaf0 | Christos Stathis | */
|
83 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/editcut.png") |
84 | a57faaf0 | Christos Stathis | ImageResource cut(); |
85 | a57faaf0 | Christos Stathis | |
86 | a57faaf0 | Christos Stathis | /**
|
87 | a57faaf0 | Christos Stathis | * Will bundle the file 'editcopy.png' residing in the package
|
88 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
89 | a57faaf0 | Christos Stathis | *
|
90 | a57faaf0 | Christos Stathis | * @return the image prototype
|
91 | a57faaf0 | Christos Stathis | */
|
92 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/editcopy.png") |
93 | a57faaf0 | Christos Stathis | ImageResource copy(); |
94 | a57faaf0 | Christos Stathis | |
95 | a57faaf0 | Christos Stathis | /**
|
96 | a57faaf0 | Christos Stathis | * Will bundle the file 'editpaste.png' residing in the package
|
97 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
98 | a57faaf0 | Christos Stathis | *
|
99 | a57faaf0 | Christos Stathis | * @return the image prototype
|
100 | a57faaf0 | Christos Stathis | */
|
101 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/editpaste.png") |
102 | a57faaf0 | Christos Stathis | ImageResource paste(); |
103 | a57faaf0 | Christos Stathis | |
104 | a57faaf0 | Christos Stathis | /**
|
105 | a57faaf0 | Christos Stathis | * Will bundle the file 'editdelete.png' residing in the package
|
106 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
107 | a57faaf0 | Christos Stathis | *
|
108 | a57faaf0 | Christos Stathis | * @return the image prototype
|
109 | a57faaf0 | Christos Stathis | */
|
110 | a57faaf0 | Christos Stathis | @Override
|
111 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/editdelete.png") |
112 | a57faaf0 | Christos Stathis | ImageResource delete(); |
113 | a57faaf0 | Christos Stathis | |
114 | a57faaf0 | Christos Stathis | /**
|
115 | a57faaf0 | Christos Stathis | * Will bundle the file 'translate.png' residing in the package
|
116 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
117 | a57faaf0 | Christos Stathis | *
|
118 | a57faaf0 | Christos Stathis | * @return the image prototype
|
119 | a57faaf0 | Christos Stathis | */
|
120 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/translate.png") |
121 | a57faaf0 | Christos Stathis | ImageResource selectAll(); |
122 | a57faaf0 | Christos Stathis | |
123 | a57faaf0 | Christos Stathis | /**
|
124 | a57faaf0 | Christos Stathis | * Will bundle the file 'border_remove.png' residing in the package
|
125 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
126 | a57faaf0 | Christos Stathis | *
|
127 | a57faaf0 | Christos Stathis | * @return the image prototype
|
128 | a57faaf0 | Christos Stathis | */
|
129 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/border_remove.png") |
130 | a57faaf0 | Christos Stathis | ImageResource unselectAll(); |
131 | a57faaf0 | Christos Stathis | } |
132 | a57faaf0 | Christos Stathis | |
133 | a57faaf0 | Christos Stathis | /**
|
134 | a57faaf0 | Christos Stathis | * The widget's constructor.
|
135 | a57faaf0 | Christos Stathis | *
|
136 | a57faaf0 | Christos Stathis | * @param newImages the image bundle passed on by the parent object
|
137 | a57faaf0 | Christos Stathis | */
|
138 | a57faaf0 | Christos Stathis | public EditMenu(final Images newImages) { |
139 | a57faaf0 | Christos Stathis | // The popup's constructor's argument is a boolean specifying that it
|
140 | a57faaf0 | Christos Stathis | // auto-close itself when the user clicks outside of it.
|
141 | a57faaf0 | Christos Stathis | super(true); |
142 | a57faaf0 | Christos Stathis | setAnimationEnabled(true);
|
143 | a57faaf0 | Christos Stathis | images = newImages; |
144 | a57faaf0 | Christos Stathis | createMenu(); |
145 | a57faaf0 | Christos Stathis | add(contextMenu); |
146 | a57faaf0 | Christos Stathis | } |
147 | a57faaf0 | Christos Stathis | |
148 | a57faaf0 | Christos Stathis | @Override
|
149 | a57faaf0 | Christos Stathis | public void onClick(ClickEvent event) { |
150 | a57faaf0 | Christos Stathis | final EditMenu menu = new EditMenu(images); |
151 | a57faaf0 | Christos Stathis | final int left = event.getRelativeElement().getAbsoluteLeft(); |
152 | a57faaf0 | Christos Stathis | final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); |
153 | a57faaf0 | Christos Stathis | menu.setPopupPosition(left, top); |
154 | a57faaf0 | Christos Stathis | menu.show(); |
155 | a57faaf0 | Christos Stathis | } |
156 | a57faaf0 | Christos Stathis | |
157 | a57faaf0 | Christos Stathis | public MenuBar createMenu() { |
158 | a57faaf0 | Christos Stathis | contextMenu.clearItems(); |
159 | a57faaf0 | Christos Stathis | contextMenu.setAutoOpen(false);
|
160 | a57faaf0 | Christos Stathis | |
161 | a57faaf0 | Christos Stathis | final Command selectAllCommand = new Command() { |
162 | a57faaf0 | Christos Stathis | |
163 | a57faaf0 | Christos Stathis | @Override
|
164 | a57faaf0 | Christos Stathis | public void execute() { |
165 | a57faaf0 | Christos Stathis | hide(); |
166 | a57faaf0 | Christos Stathis | if(GSS.get().isFileListShowing())
|
167 | a57faaf0 | Christos Stathis | GSS.get().getFileList().selectAllRows(); |
168 | a57faaf0 | Christos Stathis | } |
169 | a57faaf0 | Christos Stathis | }; |
170 | a57faaf0 | Christos Stathis | final Command unselectAllCommand = new Command() { |
171 | a57faaf0 | Christos Stathis | |
172 | a57faaf0 | Christos Stathis | @Override
|
173 | a57faaf0 | Christos Stathis | public void execute() { |
174 | a57faaf0 | Christos Stathis | hide(); |
175 | a57faaf0 | Christos Stathis | if(GSS.get().isFileListShowing())
|
176 | a57faaf0 | Christos Stathis | GSS.get().getFileList().clearSelectedRows(); |
177 | a57faaf0 | Christos Stathis | } |
178 | a57faaf0 | Christos Stathis | }; |
179 | a57faaf0 | Christos Stathis | |
180 | a57faaf0 | Christos Stathis | boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper |
181 | a57faaf0 | Christos Stathis | || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List); |
182 | a57faaf0 | Christos Stathis | String cutLabel = "Cut"; |
183 | a57faaf0 | Christos Stathis | String copyLabel ="Copy"; |
184 | a57faaf0 | Christos Stathis | String pasteLabel = "Paste"; |
185 | a57faaf0 | Christos Stathis | if(GSS.get().getCurrentSelection() != null) |
186 | a57faaf0 | Christos Stathis | if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){ |
187 | a57faaf0 | Christos Stathis | cutLabel = "Cut Folder";
|
188 | a57faaf0 | Christos Stathis | copyLabel = "Copy Folder";
|
189 | a57faaf0 | Christos Stathis | } |
190 | a57faaf0 | Christos Stathis | else if(GSS.get().getCurrentSelection() instanceof FileResource){ |
191 | a57faaf0 | Christos Stathis | cutLabel = "Cut File";
|
192 | a57faaf0 | Christos Stathis | copyLabel = "Copy File";
|
193 | a57faaf0 | Christos Stathis | } |
194 | a57faaf0 | Christos Stathis | else if(GSS.get().getCurrentSelection() instanceof List){ |
195 | a57faaf0 | Christos Stathis | cutLabel = "Cut Files";
|
196 | a57faaf0 | Christos Stathis | copyLabel = "Copy Files";
|
197 | a57faaf0 | Christos Stathis | } |
198 | a57faaf0 | Christos Stathis | if(GSS.get().getClipboard().getItem() != null) |
199 | 1e413f9b | Christos Stathis | if(GSS.get().getClipboard().getItem() instanceof List) { |
200 | 1e413f9b | Christos Stathis | if (((List) GSS.get().getClipboard().getItem()).size() > 1) |
201 | 1e413f9b | Christos Stathis | pasteLabel = "Paste Files";
|
202 | 1e413f9b | Christos Stathis | else
|
203 | 1e413f9b | Christos Stathis | pasteLabel = "Paste File";
|
204 | 1e413f9b | Christos Stathis | } |
205 | 1e413f9b | Christos Stathis | else if(GSS.get().getClipboard().getItem() instanceof Folder) |
206 | a57faaf0 | Christos Stathis | pasteLabel = "Paste Folder";
|
207 | 1e413f9b | Christos Stathis | MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"</span>", true, new CutCommand(GSS.get(), this, null)); |
208 | a57faaf0 | Christos Stathis | cutItem.getElement().setId("topMenu.edit.cut");
|
209 | a57faaf0 | Christos Stathis | contextMenu.addItem(cutItem).setVisible(cutcopyVisible); |
210 | a57faaf0 | Christos Stathis | |
211 | 1e413f9b | Christos Stathis | MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(GSS.get(), this, null)); |
212 | a57faaf0 | Christos Stathis | copyItem.getElement().setId("topMenu.edit.copy");
|
213 | a57faaf0 | Christos Stathis | contextMenu.addItem(copyItem).setVisible(cutcopyVisible); |
214 | a57faaf0 | Christos Stathis | |
215 | 1e413f9b | Christos Stathis | MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(GSS.get(), this, null)); |
216 | a57faaf0 | Christos Stathis | pasteItem.getElement().setId("topMenu.edit.paste");
|
217 | a57faaf0 | Christos Stathis | if (GSS.get().getClipboard().getItem() != null) |
218 | 1e413f9b | Christos Stathis | contextMenu.addItem(pasteItem); |
219 | 81918908 | Christos Stathis | MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, null)); |
220 | a57faaf0 | Christos Stathis | moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
|
221 | a57faaf0 | Christos Stathis | contextMenu .addItem(moveToTrashItem) |
222 | a57faaf0 | Christos Stathis | .setVisible(cutcopyVisible); |
223 | a57faaf0 | Christos Stathis | |
224 | f1aabd89 | Christos Stathis | MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images)); |
225 | a57faaf0 | Christos Stathis | deleteItem.getElement().setId("topMenu.edit.delete");
|
226 | a57faaf0 | Christos Stathis | contextMenu .addItem(deleteItem) |
227 | a57faaf0 | Christos Stathis | .setVisible(cutcopyVisible); |
228 | a57faaf0 | Christos Stathis | |
229 | a57faaf0 | Christos Stathis | MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, selectAllCommand); |
230 | a57faaf0 | Christos Stathis | selectAllItem.getElement().setId("topMenu.edit.selectAll");
|
231 | a57faaf0 | Christos Stathis | contextMenu.addItem(selectAllItem); |
232 | a57faaf0 | Christos Stathis | |
233 | a57faaf0 | Christos Stathis | MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, unselectAllCommand); |
234 | a57faaf0 | Christos Stathis | unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
|
235 | a57faaf0 | Christos Stathis | contextMenu.addItem(unSelectAllItem); |
236 | a57faaf0 | Christos Stathis | return contextMenu;
|
237 | a57faaf0 | Christos Stathis | } |
238 | a57faaf0 | Christos Stathis | |
239 | a57faaf0 | Christos Stathis | |
240 | a57faaf0 | Christos Stathis | |
241 | a57faaf0 | Christos Stathis | } |