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.resources.client.ClientBundle;
39 import com.google.gwt.resources.client.ImageResource;
40 import com.google.gwt.user.client.Command;
41 import com.google.gwt.user.client.Event;
42 import com.google.gwt.user.client.ui.AbstractImagePrototype;
43 import com.google.gwt.user.client.ui.MenuBar;
44 import com.google.gwt.user.client.ui.MenuItem;
45 import com.google.gwt.user.client.ui.PopupPanel;
46 import com.google.gwt.user.client.ui.TreeItem;
49 * The 'File Context' menu implementation.
51 public class FileContextMenu extends PopupPanel implements ClickHandler {
54 * The widget's images.
56 private final Images images;
58 private MenuItem cutItem;
60 private MenuItem copyItem;
62 private MenuItem pasteItem;
64 private MenuItem updateItem;
66 private MenuItem sharingItem;
68 private MenuItem propItem;
70 private MenuItem trashItem;
72 private MenuItem deleteItem;
74 private MenuItem downloadItem;
76 private MenuItem saveAsItem;
79 * The image bundle for this widget's images that reuses images defined in
82 public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
84 @Source("gr/ebs/gss/resources/mimetypes/document.png")
85 ImageResource fileContextMenu();
87 @Source("gr/ebs/gss/resources/doc_versions.png")
88 ImageResource versions();
90 @Source("gr/ebs/gss/resources/group.png")
91 ImageResource sharing();
93 @Source("gr/ebs/gss/resources/border_remove.png")
94 ImageResource unselectAll();
96 @Source("gr/ebs/gss/resources/demo.png")
97 ImageResource viewImage();
100 public static native String getDate()/*-{
101 return (new Date()).toUTCString();
105 * The widget's constructor.
107 * @param newImages the image bundle passed on by the parent object
109 public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) {
110 // The popup's constructor's argument is a boolean specifying that it
111 // auto-close itself when the user clicks outside of it.
114 setAnimationEnabled(true);
117 // The command that does some validation before downloading a file.
118 Command downloadCmd = new Command() {
120 public void execute() {
122 GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
126 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this));
128 MenuBar contextMenu = new MenuBar(true);
130 contextMenu.addItem(pasteItem);
131 if (GSS.get().getFolders().getCurrent() != null)
132 if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
133 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
134 else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS .get()
136 .isOthersSharedItem(GSS .get()
139 if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
140 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
141 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
142 } else if (isTrash) {
143 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
144 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
146 final Command unselectAllCommand = new Command() {
148 public void execute() {
150 if(GSS.get().isFileListShowing())
151 GSS.get().getFileList().clearSelectedRows();
152 else if(GSS.get().isSearchResultsShowing())
153 GSS.get().getSearchResults().clearSelectedRows();
156 cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
157 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
159 updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
161 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
162 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
164 sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
165 propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
167 TreeItem currentFolder = gss.getFolders().getCurrent();
168 if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
169 contextMenu.addItem(updateItem);
170 String[] link = {"", ""};
171 gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
172 downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
173 contextMenu.addItem(downloadItem);
174 gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
175 saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
176 contextMenu.addItem(saveAsItem);
177 contextMenu.addItem(cutItem);
178 contextMenu.addItem(copyItem);
179 if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
180 contextMenu.addItem(pasteItem);
181 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand);
182 contextMenu.addItem(trashItem);
183 contextMenu.addItem(deleteItem);
184 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
185 contextMenu.addItem(sharingItem);
186 contextMenu.addItem(propItem);
189 if (gss.getClipboard().hasFileItem())
190 pasteItem.setVisible(true);
192 pasteItem.setVisible(false);
195 void onMultipleSelection() {
196 updateItem.setVisible(false);
197 downloadItem.setVisible(false);
198 saveAsItem.setVisible(false);
199 sharingItem.setVisible(false);
202 public void onClick(ClickEvent event) {
203 if (GSS.get().getCurrentSelection() != null)
204 if (GSS.get().getCurrentSelection() instanceof FileResource) {
205 FileResource res = (FileResource) GSS.get().getCurrentSelection();
206 FileContextMenu menu;
208 menu = new FileContextMenu(images, true, false);
210 menu = new FileContextMenu(images, false, false);
211 int left = event.getRelativeElement().getAbsoluteLeft();
212 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
213 menu.setPopupPosition(left, top);
215 } else if (GSS.get().getCurrentSelection() instanceof List) {
216 FileContextMenu menu;
217 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
218 menu = new FileContextMenu(images, true, false);
220 menu = new FileContextMenu(images, false, false);
221 menu.onMultipleSelection();
223 int left = event.getRelativeElement().getAbsoluteLeft();
224 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
225 menu.setPopupPosition(left, top);
230 public void onEvent(Event event) {
231 if (GSS.get().getCurrentSelection() != null)
232 if (GSS.get().getCurrentSelection() instanceof FileResource) {
233 FileResource res = (FileResource) GSS.get().getCurrentSelection();
234 FileContextMenu menu;
236 menu = new FileContextMenu(images, true, false);
238 menu = new FileContextMenu(images, false, false);
239 int left = event.getClientX();
240 int top = event.getClientY();
241 menu.setPopupPosition(left, top);
243 } else if (GSS.get().getCurrentSelection() instanceof List) {
244 FileContextMenu menu;
245 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
246 menu = new FileContextMenu(images, true, false);
248 menu = new FileContextMenu(images, false, false);
249 menu.onMultipleSelection();
251 int left = event.getClientX();
252 int top = event.getClientY();
253 menu.setPopupPosition(left, top);
258 public void onEmptyEvent(Event event) {
259 FileContextMenu menu;
260 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
261 menu = new FileContextMenu(images, true, true);
262 else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null)
263 menu = new FileContextMenu(images, false, true);
265 int left = event.getClientX();
266 int top = event.getClientY();
267 menu.setPopupPosition(left, top);