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 RestResource sel = GSS.get().getTreeView().getSelection();
133 MenuBar contextMenu = new MenuBar(true);
135 contextMenu.addItem(pasteItem);
138 if (GSS.get().getTreeView().isFileItem(GSS.get().getTreeView().getCurrent()))
139 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
140 else if (GSS.get().getTreeView().isMySharedItem(GSS.get().getTreeView().getCurrent()) || GSS .get()
142 .isOthersSharedItem(GSS .get()
145 if(sel instanceof FolderResource)
146 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
148 if(sel instanceof RestResourceWrapper && !(sel instanceof TrashFolderResource)){
149 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
151 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
153 } else if (isTrash) {
154 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
155 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
157 final Command unselectAllCommand = new Command() {
160 public void execute() {
162 if(GSS.get().isFileListShowing())
163 GSS.get().getFileList().clearSelectedRows();
164 else if(GSS.get().isSearchResultsShowing())
165 GSS.get().getSearchResults().clearSelectedRows();
168 cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
169 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
171 updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
173 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
174 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
176 sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
177 propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
180 if(sel!=null && sel instanceof FolderResource)
181 contextMenu.addItem(updateItem);
182 String[] link = {"", ""};
183 gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
184 downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
185 contextMenu.addItem(downloadItem);
186 gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
187 saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
188 contextMenu.addItem(saveAsItem);
189 contextMenu.addItem(cutItem);
190 contextMenu.addItem(copyItem);
191 if(sel!=null && sel instanceof FolderResource)
192 contextMenu.addItem(pasteItem);
193 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand);
194 contextMenu.addItem(trashItem);
195 contextMenu.addItem(deleteItem);
196 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
197 contextMenu.addItem(sharingItem);
198 contextMenu.addItem(propItem);
201 if (gss.getClipboard().hasFileItem())
202 pasteItem.setVisible(true);
204 pasteItem.setVisible(false);
207 void onMultipleSelection() {
208 updateItem.setVisible(false);
209 downloadItem.setVisible(false);
210 saveAsItem.setVisible(false);
211 sharingItem.setVisible(false);
214 public void onClick(ClickEvent event) {
215 if (GSS.get().getCurrentSelection() != null)
216 if (GSS.get().getCurrentSelection() instanceof FileResource) {
217 FileResource res = (FileResource) GSS.get().getCurrentSelection();
218 FileContextMenu menu;
220 menu = new FileContextMenu(images, true, false);
222 menu = new FileContextMenu(images, false, false);
223 int left = event.getRelativeElement().getAbsoluteLeft();
224 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
225 menu.setPopupPosition(left, top);
227 } else if (GSS.get().getCurrentSelection() instanceof List) {
228 FileContextMenu menu;
230 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
231 menu = new FileContextMenu(images, true, false);
233 menu = new FileContextMenu(images, false, false);
234 menu.onMultipleSelection();
237 menu = new FileContextMenu(images, false, false);
238 menu.onMultipleSelection();
239 int left = event.getRelativeElement().getAbsoluteLeft();
240 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
241 menu.setPopupPosition(left, top);
247 public void onContextEvent(ContextMenuEvent 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.getNativeEvent().getClientX();
257 int top = event.getNativeEvent().getClientY();
258 menu.setPopupPosition(left, top);
261 } else if (GSS.get().getCurrentSelection() instanceof List) {
262 FileContextMenu menu;
264 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
265 menu = new FileContextMenu(images, true, false);
267 menu = new FileContextMenu(images, false, false);
268 menu.onMultipleSelection();
271 int left = event.getNativeEvent().getClientX();
272 int top = event.getNativeEvent().getClientY();
273 //menu.setPopupPosition(left, top);
278 public FileContextMenu onEvent(Event event) {
279 FileContextMenu menu=null;
280 if (GSS.get().getCurrentSelection() != null)
281 if (GSS.get().getCurrentSelection() instanceof FileResource) {
282 FileResource res = (FileResource) GSS.get().getCurrentSelection();
285 menu = new FileContextMenu(images, true, false);
287 menu = new FileContextMenu(images, false, false);
288 int left = event.getClientX();
289 int top = event.getClientY();
290 menu.setPopupPosition(left, top);
292 } else if (GSS.get().getCurrentSelection() instanceof List) {
294 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getSelection()))
295 menu = new FileContextMenu(images, true, false);
297 menu = new FileContextMenu(images, false, false);
298 menu.onMultipleSelection();
300 menu = new FileContextMenu(images, false, false);
301 menu.onMultipleSelection();
302 int left = event.getClientX();
303 int top = event.getClientY();
304 menu.setPopupPosition(left, top);
310 public FileContextMenu onEmptyEvent(Event event) {
311 FileContextMenu menu=null;
313 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
314 menu = new FileContextMenu(images, true, true);
315 else if(((DnDTreeItem)GSS.get().getTreeView().getCurrent()).getFolderResource() != null)
316 menu = new FileContextMenu(images, false, true);
319 menu = new FileContextMenu(images, false, true);
320 int left = event.getClientX();
321 int top = event.getClientY();
322 menu.setPopupPosition(left, top);