Revision 58777026 web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java
b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java | ||
---|---|---|
1 | 1 |
/* |
2 |
* Copyright (c) 2011 Greek Research and Technology Network |
|
2 |
* Copyright 2011 GRNET S.A. All rights reserved. |
|
3 |
* |
|
4 |
* Redistribution and use in source and binary forms, with or |
|
5 |
* without modification, are permitted provided that the following |
|
6 |
* conditions are met: |
|
7 |
* |
|
8 |
* 1. Redistributions of source code must retain the above |
|
9 |
* copyright notice, this list of conditions and the following |
|
10 |
* disclaimer. |
|
11 |
* |
|
12 |
* 2. Redistributions in binary form must reproduce the above |
|
13 |
* copyright notice, this list of conditions and the following |
|
14 |
* disclaimer in the documentation and/or other materials |
|
15 |
* provided with the distribution. |
|
16 |
* |
|
17 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
18 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
22 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
23 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
24 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
25 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
27 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
28 |
* POSSIBILITY OF SUCH DAMAGE. |
|
29 |
* |
|
30 |
* The views and conclusions contained in the software and |
|
31 |
* documentation are those of the authors and should not be |
|
32 |
* interpreted as representing official policies, either expressed |
|
33 |
* or implied, of GRNET S.A. |
|
3 | 34 |
*/ |
4 | 35 |
package gr.grnet.pithos.web.client; |
5 | 36 |
|
... | ... | |
12 | 43 |
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand; |
13 | 44 |
import gr.grnet.pithos.web.client.commands.ToTrashCommand; |
14 | 45 |
import gr.grnet.pithos.web.client.commands.UploadFileCommand; |
46 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
|
15 | 47 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
16 | 48 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
17 | 49 |
import gr.grnet.pithos.web.client.rest.resource.RestResource; |
... | ... | |
35 | 67 |
/** |
36 | 68 |
* The 'File Context' menu implementation. |
37 | 69 |
*/ |
38 |
public class FileContextMenu extends PopupPanel implements ClickHandler {
|
|
70 |
public class FileContextMenu extends PopupPanel { |
|
39 | 71 |
|
40 | 72 |
/** |
41 | 73 |
* The widget's images. |
... | ... | |
95 | 127 |
* |
96 | 128 |
* @param newImages the image bundle passed on by the parent object |
97 | 129 |
*/ |
98 |
public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) {
|
|
130 |
public FileContextMenu(Images newImages, Folder selectedFolder, boolean isTrash) {
|
|
99 | 131 |
// The popup's constructor's argument is a boolean specifying that it |
100 | 132 |
// auto-close itself when the user clicks outside of it. |
101 | 133 |
super(true); |
102 | 134 |
GSS gss = GSS.get(); |
103 | 135 |
setAnimationEnabled(true); |
104 | 136 |
images = newImages; |
137 |
MenuBar contextMenu = new MenuBar(true); |
|
105 | 138 |
|
106 |
// The command that does some validation before downloading a file. |
|
107 |
Command downloadCmd = new Command() { |
|
108 |
|
|
109 |
@Override |
|
110 |
public void execute() { |
|
111 |
hide(); |
|
112 |
GSS.get().getTopPanel().getFileMenu().preDownloadCheck(); |
|
113 |
} |
|
114 |
}; |
|
115 |
|
|
116 |
pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this)); |
|
117 |
pasteItem.getElement().setId("FileContextMenu.paste"); |
|
118 |
RestResource sel = GSS.get().getTreeView().getSelection(); |
|
119 |
MenuBar contextMenu = new MenuBar(true); |
|
120 |
if (isEmpty) { |
|
121 |
contextMenu.addItem(pasteItem); |
|
122 |
if (sel != null) |
|
123 |
/*TODO:CELLTREE |
|
124 |
if (GSS.get().getTreeView().isFileItem(GSS.get().getTreeView().getCurrent())) |
|
125 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
|
126 |
else if (GSS.get().getTreeView().isMySharedItem(GSS.get().getTreeView().getCurrent()) || GSS .get() |
|
127 |
.getTreeView() |
|
128 |
.isOthersSharedItem(GSS .get() |
|
129 |
.getTreeView() |
|
130 |
.getCurrent())) |
|
131 |
if(sel instanceof FolderResource) |
|
132 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
|
133 |
*/ |
|
134 |
if(sel instanceof RestResourceWrapper && !(sel instanceof TrashFolderResource)){ |
|
135 |
MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
|
136 |
upload.getElement().setId("fileContextMenu.upload"); |
|
137 |
contextMenu.addItem(upload); |
|
138 |
} |
|
139 |
MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
|
140 |
refresh.getElement().setId("fileContextMenu.refresh"); |
|
141 |
contextMenu.addItem(refresh); |
|
142 |
|
|
143 |
} else if (isTrash) { |
|
144 |
MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this)); |
|
145 |
restore.getElement().setId("fileContextMenu.restore"); |
|
139 |
pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this)); |
|
140 |
contextMenu.addItem(pasteItem); |
|
141 |
|
|
142 |
MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
|
143 |
contextMenu.addItem(upload); |
|
144 |
|
|
145 |
MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
|
146 |
contextMenu.addItem(refresh); |
|
147 |
|
|
148 |
if (isTrash) { |
|
149 |
MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this)); |
|
146 | 150 |
contextMenu.addItem(restore); |
147 |
|
|
148 |
MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
|
149 |
delete.getElement().setId("fileContextMenu.delete"); |
|
151 |
|
|
152 |
MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
|
150 | 153 |
contextMenu.addItem(delete); |
151 | 154 |
} else { |
152 |
final Command unselectAllCommand = new Command() { |
|
153 |
|
|
154 |
@Override |
|
155 |
public void execute() { |
|
156 |
hide(); |
|
157 |
if(GSS.get().isFileListShowing()) |
|
158 |
GSS.get().getFileList().clearSelectedRows(); |
|
159 |
} |
|
160 |
}; |
|
161 | 155 |
cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this)); |
162 |
cutItem.getElement().setId("fileContextMenu.cut");
|
|
163 |
|
|
156 |
contextMenu.addItem(cutItem);
|
|
157 |
|
|
164 | 158 |
copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this)); |
165 |
copyItem.getElement().setId("fileContextMenu.copy");
|
|
166 |
|
|
159 |
contextMenu.addItem(copyItem);
|
|
160 |
|
|
167 | 161 |
updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
168 |
updateItem.getElement().setId("fileContextMenu.upload");
|
|
162 |
contextMenu.addItem(updateItem);
|
|
169 | 163 |
|
170 | 164 |
trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
171 |
trashItem.getElement().setId("fileContextMenu.moveToTrash");
|
|
172 |
|
|
165 |
contextMenu.addItem(trashItem);
|
|
166 |
|
|
173 | 167 |
deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
174 |
deleteItem.getElement().setId("fileContextMenu.delete");
|
|
168 |
contextMenu.addItem(deleteItem);
|
|
175 | 169 |
|
176 | 170 |
sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1)); |
177 |
sharingItem.getElement().setId("fileContextMenu.sharing");
|
|
178 |
|
|
171 |
contextMenu.addItem(sharingItem);
|
|
172 |
|
|
179 | 173 |
propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0)); |
180 |
propItem.getElement().setId("fileContextMenu.properties"); |
|
174 |
contextMenu.addItem(propItem); |
|
175 |
|
|
181 | 176 |
|
182 |
|
|
183 |
if(sel!=null && sel instanceof FolderResource) |
|
184 |
contextMenu.addItem(updateItem); |
|
185 | 177 |
String[] link = {"", ""}; |
186 | 178 |
gss.getTopPanel().getFileMenu().createDownloadLink(link, false); |
179 |
// The command that does some validation before downloading a file. |
|
180 |
Command downloadCmd = new Command() { |
|
181 |
|
|
182 |
@Override |
|
183 |
public void execute() { |
|
184 |
hide(); |
|
185 |
GSS.get().getTopPanel().getFileMenu().preDownloadCheck(); |
|
186 |
} |
|
187 |
}; |
|
187 | 188 |
downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd); |
188 |
downloadItem.getElement().setId("fileContextMenu.download"); |
|
189 | 189 |
contextMenu.addItem(downloadItem); |
190 | 190 |
|
191 | 191 |
gss.getTopPanel().getFileMenu().createDownloadLink(link, true); |
192 | 192 |
saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd); |
193 |
saveAsItem.getElement().setId("fileContextMenu.saveAs"); |
|
194 | 193 |
contextMenu.addItem(saveAsItem); |
195 |
contextMenu.addItem(cutItem); |
|
196 |
contextMenu.addItem(copyItem); |
|
197 |
if(sel!=null && sel instanceof FolderResource) |
|
198 |
contextMenu.addItem(pasteItem); |
|
194 |
|
|
195 |
final Command unselectAllCommand = new Command() { |
|
196 |
|
|
197 |
@Override |
|
198 |
public void execute() { |
|
199 |
hide(); |
|
200 |
if(GSS.get().isFileListShowing()) |
|
201 |
GSS.get().getFileList().clearSelectedRows(); |
|
202 |
} |
|
203 |
}; |
|
199 | 204 |
MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand); |
200 |
unSelect.getElement().setId("fileContextMenu.unSelect"); |
|
201 | 205 |
contextMenu.addItem(unSelect); |
202 |
|
|
203 |
contextMenu.addItem(trashItem); |
|
204 |
contextMenu.addItem(deleteItem); |
|
205 |
|
|
206 |
MenuItem refresh = new MenuItem("<span id='fileContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
|
207 |
refresh.getElement().setId("fileContextMenu.refresh"); |
|
208 |
contextMenu.addItem(refresh); |
|
209 |
|
|
210 |
contextMenu.addItem(sharingItem); |
|
211 |
contextMenu.addItem(propItem); |
|
206 |
|
|
212 | 207 |
} |
213 | 208 |
add(contextMenu); |
214 |
if (gss.getClipboard().hasFileItem()) |
|
215 |
pasteItem.setVisible(true); |
|
216 |
else |
|
217 |
pasteItem.setVisible(false); |
|
218 |
} |
|
219 | 209 |
|
220 |
void onMultipleSelection() { |
|
221 |
updateItem.setVisible(false); |
|
222 |
downloadItem.setVisible(false); |
|
223 |
saveAsItem.setVisible(false); |
|
224 |
sharingItem.setVisible(false); |
|
225 |
} |
|
226 |
@Override |
|
227 |
public void onClick(ClickEvent event) { |
|
228 |
if (GSS.get().getCurrentSelection() != null) |
|
229 |
if (GSS.get().getCurrentSelection() instanceof FileResource) { |
|
230 |
FileResource res = (FileResource) GSS.get().getCurrentSelection(); |
|
231 |
FileContextMenu menu; |
|
232 |
if (res.isDeleted()) |
|
233 |
menu = new FileContextMenu(images, true, false); |
|
234 |
else |
|
235 |
menu = new FileContextMenu(images, false, false); |
|
236 |
int left = event.getRelativeElement().getAbsoluteLeft(); |
|
237 |
int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); |
|
238 |
menu.setPopupPosition(left, top); |
|
239 |
menu.show(); |
|
240 |
} else if (GSS.get().getCurrentSelection() instanceof List) { |
|
241 |
FileContextMenu menu; |
|
242 |
/*TODO: CELLTREE |
|
243 |
if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent())) |
|
244 |
menu = new FileContextMenu(images, true, false); |
|
245 |
else { |
|
246 |
menu = new FileContextMenu(images, false, false); |
|
247 |
menu.onMultipleSelection(); |
|
248 |
} |
|
249 |
*/ |
|
250 |
menu = new FileContextMenu(images, false, false); |
|
251 |
menu.onMultipleSelection(); |
|
252 |
int left = event.getRelativeElement().getAbsoluteLeft(); |
|
253 |
int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); |
|
254 |
menu.setPopupPosition(left, top); |
|
255 |
menu.show(); |
|
256 |
} |
|
210 |
// if (gss.getClipboard().hasFileItem()) |
|
211 |
// pasteItem.setVisible(true); |
|
212 |
// else |
|
213 |
// pasteItem.setVisible(false); |
|
257 | 214 |
} |
258 |
|
|
259 |
|
|
260 |
public void onContextEvent(ContextMenuEvent event) { |
|
261 |
if (GSS.get().getCurrentSelection() != null) |
|
262 |
if (GSS.get().getCurrentSelection() instanceof FileResource) { |
|
263 |
FileResource res = (FileResource) GSS.get().getCurrentSelection(); |
|
264 |
FileContextMenu menu; |
|
265 |
if (res.isDeleted()) |
|
266 |
menu = new FileContextMenu(images, true, false); |
|
267 |
else |
|
268 |
menu = new FileContextMenu(images, false, false); |
|
269 |
int left = event.getNativeEvent().getClientX(); |
|
270 |
int top = event.getNativeEvent().getClientY(); |
|
271 |
menu.setPopupPosition(left, top); |
|
272 |
menu.show(); |
|
273 |
|
|
274 |
} else if (GSS.get().getCurrentSelection() instanceof List) { |
|
275 |
FileContextMenu menu; |
|
276 |
/*TODO: CELLTREE |
|
277 |
if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent())) |
|
278 |
menu = new FileContextMenu(images, true, false); |
|
279 |
else { |
|
280 |
menu = new FileContextMenu(images, false, false); |
|
281 |
menu.onMultipleSelection(); |
|
282 |
} |
|
283 |
*/ |
|
284 |
int left = event.getNativeEvent().getClientX(); |
|
285 |
int top = event.getNativeEvent().getClientY(); |
|
286 |
//menu.setPopupPosition(left, top); |
|
287 |
//menu.show(); |
|
288 |
} |
|
289 |
} |
|
290 |
|
|
291 |
public FileContextMenu onEvent(Event event) { |
|
292 |
FileContextMenu menu=null; |
|
293 |
if (GSS.get().getCurrentSelection() != null) |
|
294 |
if (GSS.get().getCurrentSelection() instanceof FileResource) { |
|
295 |
FileResource res = (FileResource) GSS.get().getCurrentSelection(); |
|
296 |
|
|
297 |
if (res.isDeleted()) |
|
298 |
menu = new FileContextMenu(images, true, false); |
|
299 |
else |
|
300 |
menu = new FileContextMenu(images, false, false); |
|
301 |
int left = event.getClientX(); |
|
302 |
int top = event.getClientY(); |
|
303 |
menu.setPopupPosition(left, top); |
|
304 |
menu.show(); |
|
305 |
} else if (GSS.get().getCurrentSelection() instanceof List) { |
|
306 |
/*TODO: CELLTREE |
|
307 |
if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getSelection())) |
|
308 |
menu = new FileContextMenu(images, true, false); |
|
309 |
else { |
|
310 |
menu = new FileContextMenu(images, false, false); |
|
311 |
menu.onMultipleSelection(); |
|
312 |
}*/ |
|
313 |
menu = new FileContextMenu(images, false, false); |
|
314 |
menu.onMultipleSelection(); |
|
315 |
int left = event.getClientX(); |
|
316 |
int top = event.getClientY(); |
|
317 |
menu.setPopupPosition(left, top); |
|
318 |
menu.show(); |
|
319 |
} |
|
320 |
return menu; |
|
321 |
} |
|
322 |
|
|
323 |
public FileContextMenu onEmptyEvent(Event event) { |
|
324 |
FileContextMenu menu=null; |
|
325 |
/*TODO: CELLTREE |
|
326 |
if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent())) |
|
327 |
menu = new FileContextMenu(images, true, true); |
|
328 |
else if(((DnDTreeItem)GSS.get().getTreeView().getCurrent()).getFolderResource() != null) |
|
329 |
menu = new FileContextMenu(images, false, true); |
|
330 |
else return menu; |
|
331 |
*/ |
|
332 |
menu = new FileContextMenu(images, false, true); |
|
333 |
int left = event.getClientX(); |
|
334 |
int top = event.getClientY(); |
|
335 |
menu.setPopupPosition(left, top); |
|
336 |
menu.show(); |
|
337 |
return menu; |
|
338 |
} |
|
339 |
|
|
340 |
|
|
341 | 215 |
} |
Also available in: Unified diff