2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client;
21 import gr.ebs.gss.client.commands.CopyCommand;
22 import gr.ebs.gss.client.commands.CutCommand;
23 import gr.ebs.gss.client.commands.DeleteCommand;
24 import gr.ebs.gss.client.commands.PasteCommand;
25 import gr.ebs.gss.client.commands.PropertiesCommand;
26 import gr.ebs.gss.client.commands.RefreshCommand;
27 import gr.ebs.gss.client.commands.RestoreTrashCommand;
28 import gr.ebs.gss.client.commands.ToTrashCommand;
29 import gr.ebs.gss.client.commands.UploadFileCommand;
30 import gr.ebs.gss.client.dnd.DnDTreeItem;
31 import gr.ebs.gss.client.rest.resource.FileResource;
32 import gr.ebs.gss.client.rest.resource.FolderResource;
34 import java.util.List;
36 import com.google.gwt.event.dom.client.ClickEvent;
37 import com.google.gwt.event.dom.client.ClickHandler;
38 import com.google.gwt.event.dom.client.ContextMenuEvent;
39 import com.google.gwt.resources.client.ClientBundle;
40 import com.google.gwt.resources.client.ImageResource;
41 import com.google.gwt.user.client.Command;
42 import com.google.gwt.user.client.Event;
43 import com.google.gwt.user.client.ui.AbstractImagePrototype;
44 import com.google.gwt.user.client.ui.MenuBar;
45 import com.google.gwt.user.client.ui.MenuItem;
46 import com.google.gwt.user.client.ui.PopupPanel;
47 import com.google.gwt.user.client.ui.TreeItem;
50 * The 'File Context' menu implementation.
52 public class FileContextMenu extends PopupPanel implements ClickHandler {
55 * The widget's images.
57 private final Images images;
59 private MenuItem cutItem;
61 private MenuItem copyItem;
63 private MenuItem pasteItem;
65 private MenuItem updateItem;
67 private MenuItem sharingItem;
69 private MenuItem propItem;
71 private MenuItem trashItem;
73 private MenuItem deleteItem;
75 private MenuItem downloadItem;
77 private MenuItem saveAsItem;
80 * The image bundle for this widget's images that reuses images defined in
83 public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
85 @Source("gr/ebs/gss/resources/mimetypes/document.png")
86 ImageResource fileContextMenu();
88 @Source("gr/ebs/gss/resources/doc_versions.png")
89 ImageResource versions();
92 @Source("gr/ebs/gss/resources/group.png")
93 ImageResource sharing();
96 @Source("gr/ebs/gss/resources/border_remove.png")
97 ImageResource unselectAll();
99 @Source("gr/ebs/gss/resources/demo.png")
100 ImageResource viewImage();
103 public static native String getDate()/*-{
104 return (new Date()).toUTCString();
108 * The widget's constructor.
110 * @param newImages the image bundle passed on by the parent object
112 public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) {
113 // The popup's constructor's argument is a boolean specifying that it
114 // auto-close itself when the user clicks outside of it.
117 setAnimationEnabled(true);
120 // The command that does some validation before downloading a file.
121 Command downloadCmd = new Command() {
124 public void execute() {
126 GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
130 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this));
131 pasteItem.getElement().setId("fileContextMenu.paste");
133 MenuBar contextMenu = new MenuBar(true);
135 contextMenu.addItem(pasteItem);
136 if (GSS.get().getFolders().getCurrent() != null)
137 if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent())){
138 MenuItem uploadItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
139 uploadItem.getElement().setId("fileContextMenu.upload");
140 contextMenu.addItem(uploadItem);
142 else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS .get()
144 .isOthersSharedItem(GSS .get()
147 if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource){
148 MenuItem uploadItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
149 uploadItem.getElement().setId("fileContextMenu.upload");
150 contextMenu.addItem(uploadItem);
153 MenuItem refreshItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
154 refreshItem.getElement().setId("fileContextItem.refresh");
155 contextMenu.addItem(refreshItem);
156 } else if (isTrash) {
157 MenuItem restoreItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
158 restoreItem.getElement().setId("fileContextMenu.restore");
160 MenuItem deleteItem2 = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
161 deleteItem2.getElement().setId("fileContextMenu.delete");
163 contextMenu.addItem(restoreItem);
164 contextMenu.addItem(deleteItem2);
166 final Command unselectAllCommand = new Command() {
169 public void execute() {
171 if(GSS.get().isFileListShowing())
172 GSS.get().getFileList().clearSelectedRows();
173 else if(GSS.get().isSearchResultsShowing())
174 GSS.get().getSearchResults().clearSelectedRows();
177 cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
178 cutItem.getElement().setId("fileContextMenu.cut");
180 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
181 copyItem.getElement().setId("fileContextMenu.copy");
183 updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
184 updateItem.getElement().setId("fileContextMenu.upload");
186 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
187 trashItem.getElement().setId("fileContextMenu.moveToTrash");
189 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
190 deleteItem.getElement().setId("fileContextMenu.delete");
192 sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
193 sharingItem.getElement().setId("fileContextMenu.sharing");
195 propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
196 propItem.getElement().setId("fileContextMenu.properties");
198 TreeItem currentFolder = gss.getFolders().getCurrent();
199 if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
200 contextMenu.addItem(updateItem);
201 String[] link = {"", ""};
202 gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
203 downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
204 downloadItem.getElement().setId("fileContextMenu.download");
205 contextMenu.addItem(downloadItem);
207 gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
209 saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
210 saveAsItem.getElement().setId("fileContextMenu.saveAs");
212 contextMenu.addItem(saveAsItem);
213 contextMenu.addItem(cutItem);
214 contextMenu.addItem(copyItem);
216 if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
217 contextMenu.addItem(pasteItem);
219 MenuItem unSelectItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand);
220 unSelectItem.getElement().setId("fileContextMenu.unSelect");
222 contextMenu.addItem(unSelectItem);
223 contextMenu.addItem(trashItem);
224 contextMenu.addItem(deleteItem);
226 MenuItem refreshItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
227 refreshItem.getElement().setId("fileContextMenu.refresh");
229 contextMenu.addItem(refreshItem);
230 contextMenu.addItem(sharingItem);
231 contextMenu.addItem(propItem);
234 if (gss.getClipboard().hasFileItem())
235 pasteItem.setVisible(true);
237 pasteItem.setVisible(false);
240 void onMultipleSelection() {
241 updateItem.setVisible(false);
242 downloadItem.setVisible(false);
243 saveAsItem.setVisible(false);
244 sharingItem.setVisible(false);
247 public void onClick(ClickEvent event) {
248 if (GSS.get().getCurrentSelection() != null)
249 if (GSS.get().getCurrentSelection() instanceof FileResource) {
250 FileResource res = (FileResource) GSS.get().getCurrentSelection();
251 FileContextMenu menu;
253 menu = new FileContextMenu(images, true, false);
255 menu = new FileContextMenu(images, false, false);
256 int left = event.getRelativeElement().getAbsoluteLeft();
257 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
258 menu.setPopupPosition(left, top);
260 } else if (GSS.get().getCurrentSelection() instanceof List) {
261 FileContextMenu menu;
262 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
263 menu = new FileContextMenu(images, true, false);
265 menu = new FileContextMenu(images, false, false);
266 menu.onMultipleSelection();
268 int left = event.getRelativeElement().getAbsoluteLeft();
269 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
270 menu.setPopupPosition(left, top);
276 public void onContextEvent(ContextMenuEvent event) {
277 if (GSS.get().getCurrentSelection() != null)
278 if (GSS.get().getCurrentSelection() instanceof FileResource) {
279 FileResource res = (FileResource) GSS.get().getCurrentSelection();
280 FileContextMenu menu;
282 menu = new FileContextMenu(images, true, false);
284 menu = new FileContextMenu(images, false, false);
285 int left = event.getNativeEvent().getClientX();
286 int top = event.getNativeEvent().getClientY();
287 menu.setPopupPosition(left, top);
290 } else if (GSS.get().getCurrentSelection() instanceof List) {
291 FileContextMenu menu;
292 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
293 menu = new FileContextMenu(images, true, false);
295 menu = new FileContextMenu(images, false, false);
296 menu.onMultipleSelection();
298 int left = event.getNativeEvent().getClientX();
299 int top = event.getNativeEvent().getClientY();
300 menu.setPopupPosition(left, top);
305 public FileContextMenu onEvent(Event event) {
306 FileContextMenu menu=null;
307 if (GSS.get().getCurrentSelection() != null)
308 if (GSS.get().getCurrentSelection() instanceof FileResource) {
309 FileResource res = (FileResource) GSS.get().getCurrentSelection();
312 menu = new FileContextMenu(images, true, false);
314 menu = new FileContextMenu(images, false, false);
315 int left = event.getClientX();
316 int top = event.getClientY();
317 menu.setPopupPosition(left, top);
319 } else if (GSS.get().getCurrentSelection() instanceof List) {
321 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
322 menu = new FileContextMenu(images, true, false);
324 menu = new FileContextMenu(images, false, false);
325 menu.onMultipleSelection();
327 int left = event.getClientX();
328 int top = event.getClientY();
329 menu.setPopupPosition(left, top);
335 public FileContextMenu onEmptyEvent(Event event) {
336 FileContextMenu menu=null;
337 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
338 menu = new FileContextMenu(images, true, true);
339 else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null)
340 menu = new FileContextMenu(images, false, true);
342 int left = event.getClientX();
343 int top = event.getClientY();
344 menu.setPopupPosition(left, top);