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.rest.resource.FileResource;
31 import gr.ebs.gss.client.rest.resource.FolderResource;
32 import gr.ebs.gss.client.rest.resource.RestResource;
33 import gr.ebs.gss.client.rest.resource.RestResourceWrapper;
34 import gr.ebs.gss.client.rest.resource.TrashFolderResource;
36 import java.util.List;
38 import com.google.gwt.event.dom.client.ClickEvent;
39 import com.google.gwt.event.dom.client.ClickHandler;
40 import com.google.gwt.event.dom.client.ContextMenuEvent;
41 import com.google.gwt.resources.client.ClientBundle;
42 import com.google.gwt.resources.client.ImageResource;
43 import com.google.gwt.user.client.Command;
44 import com.google.gwt.user.client.Event;
45 import com.google.gwt.user.client.ui.AbstractImagePrototype;
46 import com.google.gwt.user.client.ui.MenuBar;
47 import com.google.gwt.user.client.ui.MenuItem;
48 import com.google.gwt.user.client.ui.PopupPanel;
51 * The 'File Context' menu implementation.
53 public class FileContextMenu extends PopupPanel implements ClickHandler {
56 * The widget's images.
58 private final Images images;
60 private MenuItem cutItem;
62 private MenuItem copyItem;
64 private MenuItem pasteItem;
66 private MenuItem updateItem;
68 private MenuItem sharingItem;
70 private MenuItem propItem;
72 private MenuItem trashItem;
74 private MenuItem deleteItem;
76 private MenuItem downloadItem;
78 private MenuItem saveAsItem;
81 * The image bundle for this widget's images that reuses images defined in
84 public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
86 @Source("gr/ebs/gss/resources/mimetypes/document.png")
87 ImageResource fileContextMenu();
89 @Source("gr/ebs/gss/resources/doc_versions.png")
90 ImageResource versions();
93 @Source("gr/ebs/gss/resources/group.png")
94 ImageResource sharing();
97 @Source("gr/ebs/gss/resources/border_remove.png")
98 ImageResource unselectAll();
100 @Source("gr/ebs/gss/resources/demo.png")
101 ImageResource viewImage();
104 public static native String getDate()/*-{
105 return (new Date()).toUTCString();
109 * The widget's constructor.
111 * @param newImages the image bundle passed on by the parent object
113 public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) {
114 // The popup's constructor's argument is a boolean specifying that it
115 // auto-close itself when the user clicks outside of it.
118 setAnimationEnabled(true);
121 // The command that does some validation before downloading a file.
122 Command downloadCmd = new Command() {
125 public void execute() {
127 GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
131 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this));
132 pasteItem.getElement().setId("FileContextMenu.paste");
133 RestResource sel = GSS.get().getTreeView().getSelection();
134 MenuBar contextMenu = new MenuBar(true);
136 contextMenu.addItem(pasteItem);
139 if (GSS.get().getTreeView().isFileItem(GSS.get().getTreeView().getCurrent()))
140 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
141 else if (GSS.get().getTreeView().isMySharedItem(GSS.get().getTreeView().getCurrent()) || GSS .get()
143 .isOthersSharedItem(GSS .get()
146 if(sel instanceof FolderResource)
147 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
149 if(sel instanceof RestResourceWrapper && !(sel instanceof TrashFolderResource)){
150 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
151 upload.getElement().setId("fileContextMenu.upload");
152 contextMenu.addItem(upload);
154 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
155 refresh.getElement().setId("fileContextMenu.refresh");
156 contextMenu.addItem(refresh);
158 } else if (isTrash) {
159 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
160 restore.getElement().setId("fileContextMenu.restore");
161 contextMenu.addItem(restore);
163 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
164 delete.getElement().setId("fileContextMenu.delete");
165 contextMenu.addItem(delete);
167 final Command unselectAllCommand = new Command() {
170 public void execute() {
172 if(GSS.get().isFileListShowing())
173 GSS.get().getFileList().clearSelectedRows();
174 else if(GSS.get().isSearchResultsShowing())
175 GSS.get().getSearchResults().clearSelectedRows();
178 cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
179 cutItem.getElement().setId("fileContextMenu.cut");
181 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
182 copyItem.getElement().setId("fileContextMenu.copy");
184 updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
185 updateItem.getElement().setId("fileContextMenu.upload");
187 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
188 trashItem.getElement().setId("fileContextMenu.moveToTrash");
190 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
191 deleteItem.getElement().setId("fileContextMenu.delete");
193 sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
194 sharingItem.getElement().setId("fileContextMenu.sharing");
196 propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
197 propItem.getElement().setId("fileContextMenu.properties");
200 if(sel!=null && sel instanceof FolderResource)
201 contextMenu.addItem(updateItem);
202 String[] link = {"", ""};
203 gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
204 downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
205 downloadItem.getElement().setId("fileContextMenu.download");
206 contextMenu.addItem(downloadItem);
208 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");
211 contextMenu.addItem(saveAsItem);
212 contextMenu.addItem(cutItem);
213 contextMenu.addItem(copyItem);
214 if(sel!=null && sel instanceof FolderResource)
215 contextMenu.addItem(pasteItem);
216 MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand);
217 unSelect.getElement().setId("fileContextMenu.unSelect");
218 contextMenu.addItem(unSelect);
220 contextMenu.addItem(trashItem);
221 contextMenu.addItem(deleteItem);
223 MenuItem refresh = new MenuItem("<span id='fileContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
224 // refresh.getElement().setId("fileContextMenu.refresh");
225 contextMenu.addItem(refresh);
227 contextMenu.addItem(sharingItem);
228 contextMenu.addItem(propItem);
231 if (gss.getClipboard().hasFileItem())
232 pasteItem.setVisible(true);
234 pasteItem.setVisible(false);
237 void onMultipleSelection() {
238 updateItem.setVisible(false);
239 downloadItem.setVisible(false);
240 saveAsItem.setVisible(false);
241 sharingItem.setVisible(false);
244 public void onClick(ClickEvent event) {
245 if (GSS.get().getCurrentSelection() != null)
246 if (GSS.get().getCurrentSelection() instanceof FileResource) {
247 FileResource res = (FileResource) GSS.get().getCurrentSelection();
248 FileContextMenu menu;
250 menu = new FileContextMenu(images, true, false);
252 menu = new FileContextMenu(images, false, false);
253 int left = event.getRelativeElement().getAbsoluteLeft();
254 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
255 menu.setPopupPosition(left, top);
257 } else if (GSS.get().getCurrentSelection() instanceof List) {
258 FileContextMenu menu;
260 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
261 menu = new FileContextMenu(images, true, false);
263 menu = new FileContextMenu(images, false, false);
264 menu.onMultipleSelection();
267 menu = new FileContextMenu(images, false, false);
268 menu.onMultipleSelection();
269 int left = event.getRelativeElement().getAbsoluteLeft();
270 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
271 menu.setPopupPosition(left, top);
277 public void onContextEvent(ContextMenuEvent event) {
278 if (GSS.get().getCurrentSelection() != null)
279 if (GSS.get().getCurrentSelection() instanceof FileResource) {
280 FileResource res = (FileResource) GSS.get().getCurrentSelection();
281 FileContextMenu menu;
283 menu = new FileContextMenu(images, true, false);
285 menu = new FileContextMenu(images, false, false);
286 int left = event.getNativeEvent().getClientX();
287 int top = event.getNativeEvent().getClientY();
288 menu.setPopupPosition(left, top);
291 } else if (GSS.get().getCurrentSelection() instanceof List) {
292 FileContextMenu menu;
294 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
295 menu = new FileContextMenu(images, true, false);
297 menu = new FileContextMenu(images, false, false);
298 menu.onMultipleSelection();
301 int left = event.getNativeEvent().getClientX();
302 int top = event.getNativeEvent().getClientY();
303 //menu.setPopupPosition(left, top);
308 public FileContextMenu onEvent(Event event) {
309 FileContextMenu menu=null;
310 if (GSS.get().getCurrentSelection() != null)
311 if (GSS.get().getCurrentSelection() instanceof FileResource) {
312 FileResource res = (FileResource) GSS.get().getCurrentSelection();
315 menu = new FileContextMenu(images, true, false);
317 menu = new FileContextMenu(images, false, false);
318 int left = event.getClientX();
319 int top = event.getClientY();
320 menu.setPopupPosition(left, top);
322 } else if (GSS.get().getCurrentSelection() instanceof List) {
324 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getSelection()))
325 menu = new FileContextMenu(images, true, false);
327 menu = new FileContextMenu(images, false, false);
328 menu.onMultipleSelection();
330 menu = new FileContextMenu(images, false, false);
331 menu.onMultipleSelection();
332 int left = event.getClientX();
333 int top = event.getClientY();
334 menu.setPopupPosition(left, top);
340 public FileContextMenu onEmptyEvent(Event event) {
341 FileContextMenu menu=null;
343 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
344 menu = new FileContextMenu(images, true, true);
345 else if(((DnDTreeItem)GSS.get().getTreeView().getCurrent()).getFolderResource() != null)
346 menu = new FileContextMenu(images, false, true);
349 menu = new FileContextMenu(images, false, true);
350 int left = event.getClientX();
351 int top = event.getClientY();
352 menu.setPopupPosition(left, top);