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.user.client.Command;
37 import com.google.gwt.user.client.Event;
38 import com.google.gwt.user.client.ui.AbstractImagePrototype;
39 import com.google.gwt.user.client.ui.ClickListener;
40 import com.google.gwt.user.client.ui.MenuBar;
41 import com.google.gwt.user.client.ui.MenuItem;
42 import com.google.gwt.user.client.ui.PopupPanel;
43 import com.google.gwt.user.client.ui.TreeItem;
44 import com.google.gwt.user.client.ui.Widget;
47 * The 'File Context' menu implementation.
49 public class FileContextMenu extends PopupPanel implements ClickListener {
52 * The widget's images.
54 private final Images images;
56 private MenuItem cutItem;
58 private MenuItem copyItem;
60 private MenuItem pasteItem;
62 private MenuItem updateItem;
64 private MenuItem sharingItem;
66 private MenuItem propItem;
68 private MenuItem trashItem;
70 private MenuItem deleteItem;
72 private MenuItem downloadItem;
74 private MenuItem saveAsItem;
77 * The image bundle for this widget's images that reuses images defined in
80 public interface Images extends FileMenu.Images, EditMenu.Images {
82 @Resource("gr/ebs/gss/resources/mimetypes/document.png")
83 AbstractImagePrototype fileContextMenu();
85 @Resource("gr/ebs/gss/resources/doc_versions.png")
86 AbstractImagePrototype versions();
88 @Resource("gr/ebs/gss/resources/group.png")
89 AbstractImagePrototype sharing();
91 @Resource("gr/ebs/gss/resources/border_remove.png")
92 AbstractImagePrototype unselectAll();
95 public static native String getDate()/*-{
96 return (new Date()).toUTCString();
100 * The widget's constructor.
102 * @param newImages the image bundle passed on by the parent object
104 public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) {
105 // The popup's constructor's argument is a boolean specifying that it
106 // auto-close itself when the user clicks outside of it.
109 setAnimationEnabled(true);
112 // The command that does some validation before downloading a file.
113 Command downloadCmd = new Command() {
115 public void execute() {
117 GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
121 pasteItem = new MenuItem("<span>" + newImages.paste().getHTML() + " Paste</span>", true, new PasteCommand(this));
123 MenuBar contextMenu = new MenuBar(true);
125 contextMenu.addItem(pasteItem);
126 if (GSS.get().getFolders().getCurrent() != null)
127 if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
128 contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this));
129 else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS .get()
131 .isOthersSharedItem(GSS .get()
134 if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
135 contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this));
136 contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
137 } else if (isTrash) {
138 contextMenu.addItem("<span>" + newImages.versions().getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
139 contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
141 final Command unselectAllCommand = new Command() {
143 public void execute() {
145 if(GSS.get().isFileListShowing())
146 GSS.get().getFileList().clearSelectedRows();
147 else if(GSS.get().isSearchResultsShowing())
148 GSS.get().getSearchResults().clearSelectedRows();
151 cutItem = new MenuItem("<span>" + newImages.cut().getHTML() + " Cut</span>", true, new CutCommand(this));
152 copyItem = new MenuItem("<span>" + newImages.copy().getHTML() + " Copy</span>", true, new CopyCommand(this));
154 updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this));
156 trashItem = new MenuItem("<span>" + newImages.emptyTrash().getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
157 deleteItem = new MenuItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
159 sharingItem = new MenuItem("<span>" + newImages.sharing().getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
160 propItem = new MenuItem("<span>" + newImages.viewText().getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
162 TreeItem currentFolder = gss.getFolders().getCurrent();
163 if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
164 contextMenu.addItem(updateItem);
165 String[] link = {"", ""};
166 gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
167 downloadItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
168 contextMenu.addItem(downloadItem);
169 gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
170 saveAsItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
171 contextMenu.addItem(saveAsItem);
172 contextMenu.addItem(cutItem);
173 contextMenu.addItem(copyItem);
174 if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
175 contextMenu.addItem(pasteItem);
176 contextMenu.addItem("<span>" + images.unselectAll().getHTML() + " Unselect</span>", true, unselectAllCommand);
177 contextMenu.addItem(trashItem);
178 contextMenu.addItem(deleteItem);
179 contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
180 contextMenu.addItem(sharingItem);
181 contextMenu.addItem(propItem);
184 if (gss.getClipboard().hasFileItem())
185 pasteItem.setVisible(true);
187 pasteItem.setVisible(false);
190 void onMultipleSelection() {
191 updateItem.setVisible(false);
192 propItem.setVisible(false);
193 downloadItem.setVisible(false);
194 sharingItem.setVisible(false);
197 public void onClick(Widget sender) {
198 if (GSS.get().getCurrentSelection() != null)
199 if (GSS.get().getCurrentSelection() instanceof FileResource) {
200 FileResource res = (FileResource) GSS.get().getCurrentSelection();
201 FileContextMenu menu;
203 menu = new FileContextMenu(images, true, false);
205 menu = new FileContextMenu(images, false, false);
206 int left = sender.getAbsoluteLeft();
207 int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
208 menu.setPopupPosition(left, top);
210 } else if (GSS.get().getCurrentSelection() instanceof List) {
211 FileContextMenu menu;
212 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
213 menu = new FileContextMenu(images, true, false);
215 menu = new FileContextMenu(images, false, false);
216 menu.onMultipleSelection();
218 int left = sender.getAbsoluteLeft();
219 int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
220 menu.setPopupPosition(left, top);
225 public void onEvent(Event event) {
226 if (GSS.get().getCurrentSelection() != null)
227 if (GSS.get().getCurrentSelection() instanceof FileResource) {
228 FileResource res = (FileResource) GSS.get().getCurrentSelection();
229 FileContextMenu menu;
231 menu = new FileContextMenu(images, true, false);
233 menu = new FileContextMenu(images, false, false);
234 int left = event.getClientX();
235 int top = event.getClientY();
236 menu.setPopupPosition(left, top);
238 } else if (GSS.get().getCurrentSelection() instanceof List) {
239 FileContextMenu menu;
240 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
241 menu = new FileContextMenu(images, true, false);
243 menu = new FileContextMenu(images, false, false);
244 menu.onMultipleSelection();
246 int left = event.getClientX();
247 int top = event.getClientY();
248 menu.setPopupPosition(left, top);
253 public void onEmptyEvent(Event event) {
254 FileContextMenu menu;
255 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
256 menu = new FileContextMenu(images, true, true);
257 else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null)
258 menu = new FileContextMenu(images, false, true);
260 int left = event.getClientX();
261 int top = event.getClientY();
262 menu.setPopupPosition(left, top);