root / src / gr / grnet / pithos / web / client / EditMenu.java @ bdda6b2f
History | View | Annotate | Download (9 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 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.FileResource; |
43 | a57faaf0 | Christos Stathis | |
44 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.GroupUserResource; |
45 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
46 | a57faaf0 | Christos Stathis | |
47 | a57faaf0 | Christos Stathis | import java.util.List; |
48 | a57faaf0 | Christos Stathis | |
49 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
50 | a57faaf0 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
51 | a57faaf0 | Christos Stathis | import com.google.gwt.resources.client.ClientBundle; |
52 | a57faaf0 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
53 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Command; |
54 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
55 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.MenuBar; |
56 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.MenuItem; |
57 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
58 | a57faaf0 | Christos Stathis | |
59 | a57faaf0 | Christos Stathis | /**
|
60 | a57faaf0 | Christos Stathis | * The 'Edit' menu implementation.
|
61 | a57faaf0 | Christos Stathis | */
|
62 | a57faaf0 | Christos Stathis | public class EditMenu extends PopupPanel implements ClickHandler { |
63 | a57faaf0 | Christos Stathis | |
64 | a57faaf0 | Christos Stathis | /**
|
65 | a57faaf0 | Christos Stathis | * The widget's images.
|
66 | a57faaf0 | Christos Stathis | */
|
67 | a57faaf0 | Christos Stathis | private final Images images; |
68 | a57faaf0 | Christos Stathis | |
69 | a57faaf0 | Christos Stathis | private final MenuBar contextMenu = new MenuBar(true); |
70 | a57faaf0 | Christos Stathis | |
71 | a57faaf0 | Christos Stathis | /**
|
72 | a57faaf0 | Christos Stathis | * An image bundle for this widget's images.
|
73 | a57faaf0 | Christos Stathis | */
|
74 | a57faaf0 | Christos Stathis | public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images { |
75 | a57faaf0 | Christos Stathis | |
76 | a57faaf0 | Christos Stathis | /**
|
77 | a57faaf0 | Christos Stathis | * Will bundle the file 'editcut.png' residing in the package
|
78 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
79 | a57faaf0 | Christos Stathis | *
|
80 | a57faaf0 | Christos Stathis | * @return the image prototype
|
81 | a57faaf0 | Christos Stathis | */
|
82 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/editcut.png") |
83 | a57faaf0 | Christos Stathis | ImageResource cut(); |
84 | a57faaf0 | Christos Stathis | |
85 | a57faaf0 | Christos Stathis | /**
|
86 | a57faaf0 | Christos Stathis | * Will bundle the file 'editcopy.png' residing in the package
|
87 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
88 | a57faaf0 | Christos Stathis | *
|
89 | a57faaf0 | Christos Stathis | * @return the image prototype
|
90 | a57faaf0 | Christos Stathis | */
|
91 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/editcopy.png") |
92 | a57faaf0 | Christos Stathis | ImageResource copy(); |
93 | a57faaf0 | Christos Stathis | |
94 | a57faaf0 | Christos Stathis | /**
|
95 | a57faaf0 | Christos Stathis | * Will bundle the file 'editpaste.png' residing in the package
|
96 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
97 | a57faaf0 | Christos Stathis | *
|
98 | a57faaf0 | Christos Stathis | * @return the image prototype
|
99 | a57faaf0 | Christos Stathis | */
|
100 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/editpaste.png") |
101 | a57faaf0 | Christos Stathis | ImageResource paste(); |
102 | a57faaf0 | Christos Stathis | |
103 | a57faaf0 | Christos Stathis | /**
|
104 | a57faaf0 | Christos Stathis | * Will bundle the file 'editdelete.png' residing in the package
|
105 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
106 | a57faaf0 | Christos Stathis | *
|
107 | a57faaf0 | Christos Stathis | * @return the image prototype
|
108 | a57faaf0 | Christos Stathis | */
|
109 | a57faaf0 | Christos Stathis | @Override
|
110 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/editdelete.png") |
111 | a57faaf0 | Christos Stathis | ImageResource delete(); |
112 | a57faaf0 | Christos Stathis | |
113 | a57faaf0 | Christos Stathis | /**
|
114 | a57faaf0 | Christos Stathis | * Will bundle the file 'translate.png' residing in the package
|
115 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
116 | a57faaf0 | Christos Stathis | *
|
117 | a57faaf0 | Christos Stathis | * @return the image prototype
|
118 | a57faaf0 | Christos Stathis | */
|
119 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/translate.png") |
120 | a57faaf0 | Christos Stathis | ImageResource selectAll(); |
121 | a57faaf0 | Christos Stathis | |
122 | a57faaf0 | Christos Stathis | /**
|
123 | a57faaf0 | Christos Stathis | * Will bundle the file 'border_remove.png' residing in the package
|
124 | a57faaf0 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
125 | a57faaf0 | Christos Stathis | *
|
126 | a57faaf0 | Christos Stathis | * @return the image prototype
|
127 | a57faaf0 | Christos Stathis | */
|
128 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/border_remove.png") |
129 | a57faaf0 | Christos Stathis | ImageResource unselectAll(); |
130 | a57faaf0 | Christos Stathis | } |
131 | a57faaf0 | Christos Stathis | |
132 | a57faaf0 | Christos Stathis | /**
|
133 | a57faaf0 | Christos Stathis | * The widget's constructor.
|
134 | a57faaf0 | Christos Stathis | *
|
135 | a57faaf0 | Christos Stathis | * @param newImages the image bundle passed on by the parent object
|
136 | a57faaf0 | Christos Stathis | */
|
137 | a57faaf0 | Christos Stathis | public EditMenu(final Images newImages) { |
138 | a57faaf0 | Christos Stathis | // The popup's constructor's argument is a boolean specifying that it
|
139 | a57faaf0 | Christos Stathis | // auto-close itself when the user clicks outside of it.
|
140 | a57faaf0 | Christos Stathis | super(true); |
141 | a57faaf0 | Christos Stathis | setAnimationEnabled(true);
|
142 | a57faaf0 | Christos Stathis | images = newImages; |
143 | a57faaf0 | Christos Stathis | createMenu(); |
144 | a57faaf0 | Christos Stathis | add(contextMenu); |
145 | a57faaf0 | Christos Stathis | } |
146 | a57faaf0 | Christos Stathis | |
147 | a57faaf0 | Christos Stathis | @Override
|
148 | a57faaf0 | Christos Stathis | public void onClick(ClickEvent event) { |
149 | a57faaf0 | Christos Stathis | final EditMenu menu = new EditMenu(images); |
150 | a57faaf0 | Christos Stathis | final int left = event.getRelativeElement().getAbsoluteLeft(); |
151 | a57faaf0 | Christos Stathis | final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); |
152 | a57faaf0 | Christos Stathis | menu.setPopupPosition(left, top); |
153 | a57faaf0 | Christos Stathis | menu.show(); |
154 | a57faaf0 | Christos Stathis | } |
155 | a57faaf0 | Christos Stathis | |
156 | a57faaf0 | Christos Stathis | public MenuBar createMenu() { |
157 | a57faaf0 | Christos Stathis | contextMenu.clearItems(); |
158 | a57faaf0 | Christos Stathis | contextMenu.setAutoOpen(false);
|
159 | a57faaf0 | Christos Stathis | |
160 | a57faaf0 | Christos Stathis | final Command selectAllCommand = new Command() { |
161 | a57faaf0 | Christos Stathis | |
162 | a57faaf0 | Christos Stathis | @Override
|
163 | a57faaf0 | Christos Stathis | public void execute() { |
164 | a57faaf0 | Christos Stathis | hide(); |
165 | a57faaf0 | Christos Stathis | if(GSS.get().isFileListShowing())
|
166 | a57faaf0 | Christos Stathis | GSS.get().getFileList().selectAllRows(); |
167 | a57faaf0 | Christos Stathis | } |
168 | a57faaf0 | Christos Stathis | }; |
169 | a57faaf0 | Christos Stathis | final Command unselectAllCommand = new Command() { |
170 | a57faaf0 | Christos Stathis | |
171 | a57faaf0 | Christos Stathis | @Override
|
172 | a57faaf0 | Christos Stathis | public void execute() { |
173 | a57faaf0 | Christos Stathis | hide(); |
174 | a57faaf0 | Christos Stathis | if(GSS.get().isFileListShowing())
|
175 | a57faaf0 | Christos Stathis | GSS.get().getFileList().clearSelectedRows(); |
176 | a57faaf0 | Christos Stathis | } |
177 | a57faaf0 | Christos Stathis | }; |
178 | a57faaf0 | Christos Stathis | |
179 | a57faaf0 | Christos Stathis | boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper |
180 | a57faaf0 | Christos Stathis | || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List); |
181 | a57faaf0 | Christos Stathis | String cutLabel = "Cut"; |
182 | a57faaf0 | Christos Stathis | String copyLabel ="Copy"; |
183 | a57faaf0 | Christos Stathis | String pasteLabel = "Paste"; |
184 | a57faaf0 | Christos Stathis | if(GSS.get().getCurrentSelection() != null) |
185 | a57faaf0 | Christos Stathis | if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){ |
186 | a57faaf0 | Christos Stathis | cutLabel = "Cut Folder";
|
187 | a57faaf0 | Christos Stathis | copyLabel = "Copy Folder";
|
188 | a57faaf0 | Christos Stathis | } |
189 | a57faaf0 | Christos Stathis | else if(GSS.get().getCurrentSelection() instanceof FileResource){ |
190 | a57faaf0 | Christos Stathis | cutLabel = "Cut File";
|
191 | a57faaf0 | Christos Stathis | copyLabel = "Copy File";
|
192 | a57faaf0 | Christos Stathis | } |
193 | a57faaf0 | Christos Stathis | else if(GSS.get().getCurrentSelection() instanceof List){ |
194 | a57faaf0 | Christos Stathis | cutLabel = "Cut Files";
|
195 | a57faaf0 | Christos Stathis | copyLabel = "Copy Files";
|
196 | a57faaf0 | Christos Stathis | } |
197 | a57faaf0 | Christos Stathis | if(GSS.get().getClipboard().getItem() != null) |
198 | a57faaf0 | Christos Stathis | if(GSS.get().getClipboard().getItem().getFile() != null) |
199 | a57faaf0 | Christos Stathis | pasteLabel = "Paste File";
|
200 | a57faaf0 | Christos Stathis | else if(GSS.get().getClipboard().getItem().getFiles() != null) |
201 | a57faaf0 | Christos Stathis | pasteLabel = "Paste Files";
|
202 | a57faaf0 | Christos Stathis | else if(GSS.get().getClipboard().getItem().getRestResourceWrapper() != null) |
203 | a57faaf0 | Christos Stathis | pasteLabel = "Paste Folder";
|
204 | a57faaf0 | Christos Stathis | MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"</span>", true, new CutCommand(this)); |
205 | a57faaf0 | Christos Stathis | cutItem.getElement().setId("topMenu.edit.cut");
|
206 | a57faaf0 | Christos Stathis | contextMenu.addItem(cutItem).setVisible(cutcopyVisible); |
207 | a57faaf0 | Christos Stathis | |
208 | a57faaf0 | Christos Stathis | MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(this)); |
209 | a57faaf0 | Christos Stathis | copyItem.getElement().setId("topMenu.edit.copy");
|
210 | a57faaf0 | Christos Stathis | contextMenu.addItem(copyItem).setVisible(cutcopyVisible); |
211 | a57faaf0 | Christos Stathis | |
212 | 63366925 | Christos Stathis | MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this)); |
213 | a57faaf0 | Christos Stathis | pasteItem.getElement().setId("topMenu.edit.paste");
|
214 | a57faaf0 | Christos Stathis | if (GSS.get().getClipboard().getItem() != null) |
215 | a57faaf0 | Christos Stathis | if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null){ |
216 | a57faaf0 | Christos Stathis | contextMenu.addItem(pasteItem); |
217 | a57faaf0 | Christos Stathis | } |
218 | a57faaf0 | Christos Stathis | else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){ |
219 | a57faaf0 | Christos Stathis | //do not show paste
|
220 | a57faaf0 | Christos Stathis | } |
221 | a57faaf0 | Christos Stathis | else if (GSS.get().getTreeView().getSelection() instanceof RestResourceWrapper){ |
222 | a57faaf0 | Christos Stathis | contextMenu.addItem(pasteItem); |
223 | a57faaf0 | Christos Stathis | } |
224 | a57faaf0 | Christos Stathis | MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
225 | a57faaf0 | Christos Stathis | moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
|
226 | a57faaf0 | Christos Stathis | contextMenu .addItem(moveToTrashItem) |
227 | a57faaf0 | Christos Stathis | .setVisible(cutcopyVisible); |
228 | a57faaf0 | Christos Stathis | |
229 | f1aabd89 | Christos Stathis | MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images)); |
230 | a57faaf0 | Christos Stathis | deleteItem.getElement().setId("topMenu.edit.delete");
|
231 | a57faaf0 | Christos Stathis | contextMenu .addItem(deleteItem) |
232 | a57faaf0 | Christos Stathis | .setVisible(cutcopyVisible); |
233 | a57faaf0 | Christos Stathis | |
234 | a57faaf0 | Christos Stathis | MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, selectAllCommand); |
235 | a57faaf0 | Christos Stathis | selectAllItem.getElement().setId("topMenu.edit.selectAll");
|
236 | a57faaf0 | Christos Stathis | contextMenu.addItem(selectAllItem); |
237 | a57faaf0 | Christos Stathis | |
238 | a57faaf0 | Christos Stathis | MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, unselectAllCommand); |
239 | a57faaf0 | Christos Stathis | unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
|
240 | a57faaf0 | Christos Stathis | contextMenu.addItem(unSelectAllItem); |
241 | a57faaf0 | Christos Stathis | return contextMenu;
|
242 | a57faaf0 | Christos Stathis | } |
243 | a57faaf0 | Christos Stathis | |
244 | a57faaf0 | Christos Stathis | |
245 | a57faaf0 | Christos Stathis | |
246 | a57faaf0 | Christos Stathis | } |