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();
94 @Resource("gr/ebs/gss/resources/demo.png")
95 AbstractImagePrototype viewImage();
98 public static native String getDate()/*-{
99 return (new Date()).toUTCString();
103 * The widget's constructor.
105 * @param newImages the image bundle passed on by the parent object
107 public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) {
108 // The popup's constructor's argument is a boolean specifying that it
109 // auto-close itself when the user clicks outside of it.
112 setAnimationEnabled(true);
115 // The command that does some validation before downloading a file.
116 Command downloadCmd = new Command() {
118 public void execute() {
120 GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
124 pasteItem = new MenuItem("<span>" + newImages.paste().getHTML() + " Paste</span>", true, new PasteCommand(this));
126 MenuBar contextMenu = new MenuBar(true);
128 contextMenu.addItem(pasteItem);
129 if (GSS.get().getFolders().getCurrent() != null)
130 if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
131 contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this));
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.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this));
139 contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
140 } else if (isTrash) {
141 contextMenu.addItem("<span>" + newImages.versions().getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
142 contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
144 final Command unselectAllCommand = new Command() {
146 public void execute() {
148 if(GSS.get().isFileListShowing())
149 GSS.get().getFileList().clearSelectedRows();
150 else if(GSS.get().isSearchResultsShowing())
151 GSS.get().getSearchResults().clearSelectedRows();
154 cutItem = new MenuItem("<span>" + newImages.cut().getHTML() + " Cut</span>", true, new CutCommand(this));
155 copyItem = new MenuItem("<span>" + newImages.copy().getHTML() + " Copy</span>", true, new CopyCommand(this));
157 updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this));
159 trashItem = new MenuItem("<span>" + newImages.emptyTrash().getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
160 deleteItem = new MenuItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
162 sharingItem = new MenuItem("<span>" + newImages.sharing().getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
163 propItem = new MenuItem("<span>" + newImages.viewText().getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
165 TreeItem currentFolder = gss.getFolders().getCurrent();
166 if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
167 contextMenu.addItem(updateItem);
168 String[] link = {"", ""};
169 gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
170 downloadItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
171 contextMenu.addItem(downloadItem);
172 gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
173 saveAsItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
174 contextMenu.addItem(saveAsItem);
175 contextMenu.addItem(cutItem);
176 contextMenu.addItem(copyItem);
177 if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
178 contextMenu.addItem(pasteItem);
179 contextMenu.addItem("<span>" + images.unselectAll().getHTML() + " Unselect</span>", true, unselectAllCommand);
180 contextMenu.addItem(trashItem);
181 contextMenu.addItem(deleteItem);
182 contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
183 contextMenu.addItem(sharingItem);
184 contextMenu.addItem(propItem);
187 if (gss.getClipboard().hasFileItem())
188 pasteItem.setVisible(true);
190 pasteItem.setVisible(false);
193 void onMultipleSelection() {
194 updateItem.setVisible(false);
195 propItem.setVisible(false);
196 downloadItem.setVisible(false);
197 saveAsItem.setVisible(false);
198 sharingItem.setVisible(false);
201 public void onClick(Widget sender) {
202 if (GSS.get().getCurrentSelection() != null)
203 if (GSS.get().getCurrentSelection() instanceof FileResource) {
204 FileResource res = (FileResource) GSS.get().getCurrentSelection();
205 FileContextMenu menu;
207 menu = new FileContextMenu(images, true, false);
209 menu = new FileContextMenu(images, false, false);
210 int left = sender.getAbsoluteLeft();
211 int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
212 menu.setPopupPosition(left, top);
214 } else if (GSS.get().getCurrentSelection() instanceof List) {
215 FileContextMenu menu;
216 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
217 menu = new FileContextMenu(images, true, false);
219 menu = new FileContextMenu(images, false, false);
220 menu.onMultipleSelection();
222 int left = sender.getAbsoluteLeft();
223 int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
224 menu.setPopupPosition(left, top);
229 public void onEvent(Event event) {
230 if (GSS.get().getCurrentSelection() != null)
231 if (GSS.get().getCurrentSelection() instanceof FileResource) {
232 FileResource res = (FileResource) GSS.get().getCurrentSelection();
233 FileContextMenu menu;
235 menu = new FileContextMenu(images, true, false);
237 menu = new FileContextMenu(images, false, false);
238 int left = event.getClientX();
239 int top = event.getClientY();
240 menu.setPopupPosition(left, top);
242 } else if (GSS.get().getCurrentSelection() instanceof List) {
243 FileContextMenu menu;
244 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
245 menu = new FileContextMenu(images, true, false);
247 menu = new FileContextMenu(images, false, false);
248 menu.onMultipleSelection();
250 int left = event.getClientX();
251 int top = event.getClientY();
252 menu.setPopupPosition(left, top);
257 public void onEmptyEvent(Event event) {
258 FileContextMenu menu;
259 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
260 menu = new FileContextMenu(images, true, true);
261 else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null)
262 menu = new FileContextMenu(images, false, true);
264 int left = event.getClientX();
265 int top = event.getClientY();
266 menu.setPopupPosition(left, top);