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.PropertiesCommand;
25 import gr.ebs.gss.client.commands.RestoreTrashCommand;
26 import gr.ebs.gss.client.commands.ToTrashCommand;
27 import gr.ebs.gss.client.commands.UploadFileCommand;
28 import gr.ebs.gss.client.dnd.DnDTreeItem;
29 import gr.ebs.gss.client.rest.resource.FileResource;
30 import gr.ebs.gss.client.rest.resource.FolderResource;
32 import java.util.List;
34 import com.google.gwt.user.client.Command;
35 import com.google.gwt.user.client.Event;
36 import com.google.gwt.user.client.Window;
37 import com.google.gwt.user.client.ui.AbstractImagePrototype;
38 import com.google.gwt.user.client.ui.ClickListener;
39 import com.google.gwt.user.client.ui.MenuBar;
40 import com.google.gwt.user.client.ui.MenuItem;
41 import com.google.gwt.user.client.ui.PopupPanel;
42 import com.google.gwt.user.client.ui.Widget;
45 * The 'File Context' menu implementation.
47 public class FileContextMenu extends PopupPanel implements ClickListener {
50 * The widget's images.
52 private final Images images;
54 private MenuItem cutItem;
56 private MenuItem copyItem;
58 private MenuItem updateItem;
60 private MenuItem propItem;
62 private MenuItem trashItem;
64 private MenuItem deleteItem;
66 private MenuItem downloadItem;
69 * The image bundle for this widget's images that reuses images defined in
72 public interface Images extends FileMenu.Images, EditMenu.Images {
75 * Will bundle the file 'document_menu.png' residing in the package
76 * 'gr.ebs.gss.resources.mimetypes'.
78 * @return the image prototype
80 @Resource("gr/ebs/gss/resources/mimetypes/document_menu.png")
81 AbstractImagePrototype fileContextMenu();
84 * Will bundle the file 'doc_versions.png' residing in the package
85 * 'gr.ebs.gss.resources'.
87 * @return the image prototype
89 @Resource("gr/ebs/gss/resources/doc_versions.png")
90 AbstractImagePrototype versions();
93 public static native String getDate()/*-{
94 return (new Date()).toUTCString();
98 * The widget's constructor.
100 * @param newImages the image bundle passed on by the parent object
102 public FileContextMenu(final Images newImages, boolean isTrash, boolean isEmpty) {
103 // The popup's constructor's argument is a boolean specifying that it
104 // auto-close itself when the user clicks outside of it.
106 setAnimationEnabled(true);
109 // A dummy command that we will execute from unimplemented leaves.
110 final Command cmd = new Command() {
112 public void execute() {
114 Window.alert("You selected a menu item!");
118 // The command that does some validation before downloading a file.
119 final Command downloadCmd = new Command() {
121 public void execute() {
123 GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
127 final MenuBar contextMenu = new MenuBar(true);
129 if (GSS.get().getFolders().getCurrent() != null)
130 if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
131 contextMenu.addItem("<span>" + newImages.fileNew().getHTML() + " Upload</span>", true, new UploadFileCommand(this, images));
132 else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS .get()
134 .isOthersSharedItem(GSS .get()
137 if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
138 contextMenu.addItem("<span>" + newImages.fileNew().getHTML() + " Upload</span>", true, new UploadFileCommand(this, images));
139 } else if (isTrash) {
140 contextMenu.addItem("<span>" + newImages.versions().getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
141 contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
144 cutItem = new MenuItem("<span>" + newImages.cut().getHTML() + " Cut</span>", true, new CutCommand(this));
145 copyItem = new MenuItem("<span>" + newImages.copy().getHTML() + " Copy</span>", true, new CopyCommand(this));
146 updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this, images));
148 propItem = new MenuItem("<span>" + newImages.viewText().getHTML() + " Properties</span>", true, new PropertiesCommand(this, images));
149 trashItem = new MenuItem("<span>" + newImages.emptyTrash().getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
150 deleteItem = new MenuItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
152 contextMenu.addItem(cutItem);
153 contextMenu.addItem(copyItem);
154 contextMenu.addItem(updateItem);
156 contextMenu.addItem(propItem);
157 contextMenu.addItem(trashItem);
158 contextMenu.addItem(deleteItem);
159 String[] link = {"", ""};
160 GSS.get().getTopPanel().getFileMenu().createDownloadLink(link);
161 downloadItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
162 contextMenu.addItem(downloadItem);
170 void onMultipleSelection() {
171 updateItem.setVisible(false);
172 propItem.setVisible(false);
173 downloadItem.setVisible(false);
179 * @see com.google.gwt.user.client.ui.ClickListener#onClick(com.google.gwt.user.client.ui.Widget)
181 public void onClick(final Widget sender) {
183 if (GSS.get().getCurrentSelection() != null)
184 if (GSS.get().getCurrentSelection() instanceof FileResource) {
185 FileResource res = (FileResource) GSS.get().getCurrentSelection();
186 FileContextMenu menu;
188 menu = new FileContextMenu(images, true, false);
190 menu = new FileContextMenu(images, false, false);
191 int left = sender.getAbsoluteLeft();
192 int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
193 menu.setPopupPosition(left, top);
195 } else if (GSS.get().getCurrentSelection() instanceof List) {
196 List<FileResource> dto = (List<FileResource>) GSS.get().getCurrentSelection();
197 FileContextMenu menu;
198 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
199 menu = new FileContextMenu(images, true, false);
201 menu = new FileContextMenu(images, false, false);
202 menu.onMultipleSelection();
204 int left = sender.getAbsoluteLeft();
205 int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
206 menu.setPopupPosition(left, top);
211 public void onEmptyEvent(Event event) {
212 FileContextMenu menu;
213 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
214 menu = new FileContextMenu(images, true, true);
215 else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null)
216 menu = new FileContextMenu(images, false, true);
218 int left = event.getClientX();
219 int top = event.getClientY();
220 menu.setPopupPosition(left, top);