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.Widget;
46 * The 'File Context' menu implementation.
48 public class FileContextMenu extends PopupPanel implements ClickListener {
51 * The widget's images.
53 private final Images images;
55 private MenuItem cutItem;
57 private MenuItem copyItem;
59 private MenuItem pasteItem;
61 private MenuItem updateItem;
63 private MenuItem sharingItem;
65 private MenuItem propItem;
67 private MenuItem trashItem;
69 private MenuItem deleteItem;
71 private MenuItem downloadItem;
74 * The image bundle for this widget's images that reuses images defined in
77 public interface Images extends FileMenu.Images, EditMenu.Images {
79 @Resource("gr/ebs/gss/resources/mimetypes/document.png")
80 AbstractImagePrototype fileContextMenu();
82 @Resource("gr/ebs/gss/resources/doc_versions.png")
83 AbstractImagePrototype versions();
85 @Resource("gr/ebs/gss/resources/group.png")
86 AbstractImagePrototype sharing();
88 @Resource("gr/ebs/gss/resources/border_remove.png")
89 AbstractImagePrototype unselectAll();
92 public static native String getDate()/*-{
93 return (new Date()).toUTCString();
97 * The widget's constructor.
99 * @param newImages the image bundle passed on by the parent object
101 public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) {
102 // The popup's constructor's argument is a boolean specifying that it
103 // auto-close itself when the user clicks outside of it.
105 setAnimationEnabled(true);
108 // The command that does some validation before downloading a file.
109 Command downloadCmd = new Command() {
111 public void execute() {
113 GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
117 pasteItem = new MenuItem("<span>" + newImages.paste().getHTML() + " Paste</span>", true, new PasteCommand(this));
119 MenuBar contextMenu = new MenuBar(true);
121 contextMenu.addItem(pasteItem);
122 if (GSS.get().getFolders().getCurrent() != null)
123 if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
124 contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this, images));
125 else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS .get()
127 .isOthersSharedItem(GSS .get()
130 if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
131 contextMenu.addItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this, images));
132 } else if (isTrash) {
133 contextMenu.addItem("<span>" + newImages.versions().getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
134 contextMenu.addItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
136 final Command unselectAllCommand = new Command() {
138 public void execute() {
140 if(GSS.get().isFileListShowing())
141 GSS.get().getFileList().clearSelectedRows();
142 else if(GSS.get().isSearchResultsShowing())
143 GSS.get().getSearchResults().clearSelectedRows();
146 cutItem = new MenuItem("<span>" + newImages.cut().getHTML() + " Cut</span>", true, new CutCommand(this));
147 copyItem = new MenuItem("<span>" + newImages.copy().getHTML() + " Copy</span>", true, new CopyCommand(this));
149 updateItem = new MenuItem("<span>" + newImages.fileUpdate().getHTML() + " Upload</span>", true, new UploadFileCommand(this, images));
151 trashItem = new MenuItem("<span>" + newImages.emptyTrash().getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
152 deleteItem = new MenuItem("<span>" + newImages.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
154 sharingItem = new MenuItem("<span>" + newImages.sharing().getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
155 propItem = new MenuItem("<span>" + newImages.viewText().getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
157 contextMenu.addItem(updateItem);
158 String[] link = {"", ""};
159 GSS.get().getTopPanel().getFileMenu().createDownloadLink(link);
160 downloadItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
161 contextMenu.addItem(downloadItem);
162 contextMenu.addItem(cutItem);
163 contextMenu.addItem(copyItem);
164 contextMenu.addItem(pasteItem);
165 contextMenu.addItem("<span>" + images.unselectAll().getHTML() + " Unselect</span>", true, unselectAllCommand);
166 contextMenu.addItem(trashItem);
167 contextMenu.addItem(deleteItem);
168 contextMenu.addItem("<span>" + images.refresh().getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
169 contextMenu.addItem(sharingItem);
170 contextMenu.addItem(propItem);
173 if (GSS.get().getClipboard().hasFileItem())
174 pasteItem.setVisible(true);
176 pasteItem.setVisible(false);
179 void onMultipleSelection() {
180 updateItem.setVisible(false);
181 propItem.setVisible(false);
182 downloadItem.setVisible(false);
183 sharingItem.setVisible(false);
186 public void onClick(Widget sender) {
187 if (GSS.get().getCurrentSelection() != null)
188 if (GSS.get().getCurrentSelection() instanceof FileResource) {
189 FileResource res = (FileResource) GSS.get().getCurrentSelection();
190 FileContextMenu menu;
192 menu = new FileContextMenu(images, true, false);
194 menu = new FileContextMenu(images, false, false);
195 int left = sender.getAbsoluteLeft();
196 int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
197 menu.setPopupPosition(left, top);
199 } else if (GSS.get().getCurrentSelection() instanceof List) {
200 FileContextMenu menu;
201 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
202 menu = new FileContextMenu(images, true, false);
204 menu = new FileContextMenu(images, false, false);
205 menu.onMultipleSelection();
207 int left = sender.getAbsoluteLeft();
208 int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
209 menu.setPopupPosition(left, top);
214 public void onEvent(Event 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.getClientX();
224 int top = event.getClientY();
225 menu.setPopupPosition(left, top);
227 } else if (GSS.get().getCurrentSelection() instanceof List) {
228 FileContextMenu menu;
229 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
230 menu = new FileContextMenu(images, true, false);
232 menu = new FileContextMenu(images, false, false);
233 menu.onMultipleSelection();
235 int left = event.getClientX();
236 int top = event.getClientY();
237 menu.setPopupPosition(left, top);
242 public void onEmptyEvent(Event event) {
243 FileContextMenu menu;
244 if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
245 menu = new FileContextMenu(images, true, true);
246 else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null)
247 menu = new FileContextMenu(images, false, true);
249 int left = event.getClientX();
250 int top = event.getClientY();
251 menu.setPopupPosition(left, top);