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.rest.resource.FileResource;
31 import gr.ebs.gss.client.rest.resource.FolderResource;
32 import gr.ebs.gss.client.rest.resource.RestResource;
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.event.dom.client.ContextMenuEvent;
39 import com.google.gwt.resources.client.ClientBundle;
40 import com.google.gwt.resources.client.ImageResource;
41 import com.google.gwt.user.client.Command;
42 import com.google.gwt.user.client.Event;
43 import com.google.gwt.user.client.ui.AbstractImagePrototype;
44 import com.google.gwt.user.client.ui.MenuBar;
45 import com.google.gwt.user.client.ui.MenuItem;
46 import com.google.gwt.user.client.ui.PopupPanel;
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();
91 @Source("gr/ebs/gss/resources/group.png")
92 ImageResource sharing();
95 @Source("gr/ebs/gss/resources/border_remove.png")
96 ImageResource unselectAll();
98 @Source("gr/ebs/gss/resources/demo.png")
99 ImageResource viewImage();
102 public static native String getDate()/*-{
103 return (new Date()).toUTCString();
107 * The widget's constructor.
109 * @param newImages the image bundle passed on by the parent object
111 public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) {
112 // The popup's constructor's argument is a boolean specifying that it
113 // auto-close itself when the user clicks outside of it.
116 setAnimationEnabled(true);
119 // The command that does some validation before downloading a file.
120 Command downloadCmd = new Command() {
123 public void execute() {
125 GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
129 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this));
130 RestResource sel = GSS.get().getTreeView().getSelection();
131 MenuBar contextMenu = new MenuBar(true);
133 contextMenu.addItem(pasteItem);
136 if (GSS.get().getTreeView().isFileItem(GSS.get().getTreeView().getCurrent()))
137 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
138 else if (GSS.get().getTreeView().isMySharedItem(GSS.get().getTreeView().getCurrent()) || GSS .get()
140 .isOthersSharedItem(GSS .get()
143 if(sel instanceof FolderResource)
144 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
146 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
147 } else if (isTrash) {
148 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
149 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
151 final Command unselectAllCommand = new Command() {
154 public void execute() {
156 if(GSS.get().isFileListShowing())
157 GSS.get().getFileList().clearSelectedRows();
158 else if(GSS.get().isSearchResultsShowing())
159 GSS.get().getSearchResults().clearSelectedRows();
162 cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
163 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
165 updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
167 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
168 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
170 sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
171 propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
174 if(sel!=null && sel instanceof FolderResource)
175 contextMenu.addItem(updateItem);
176 String[] link = {"", ""};
177 gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
178 downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
179 contextMenu.addItem(downloadItem);
180 gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
181 saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
182 contextMenu.addItem(saveAsItem);
183 contextMenu.addItem(cutItem);
184 contextMenu.addItem(copyItem);
185 if(sel!=null && sel instanceof FolderResource)
186 contextMenu.addItem(pasteItem);
187 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand);
188 contextMenu.addItem(trashItem);
189 contextMenu.addItem(deleteItem);
190 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
191 contextMenu.addItem(sharingItem);
192 contextMenu.addItem(propItem);
195 if (gss.getClipboard().hasFileItem())
196 pasteItem.setVisible(true);
198 pasteItem.setVisible(false);
201 void onMultipleSelection() {
202 updateItem.setVisible(false);
203 downloadItem.setVisible(false);
204 saveAsItem.setVisible(false);
205 sharingItem.setVisible(false);
208 public void onClick(ClickEvent event) {
209 if (GSS.get().getCurrentSelection() != null)
210 if (GSS.get().getCurrentSelection() instanceof FileResource) {
211 FileResource res = (FileResource) GSS.get().getCurrentSelection();
212 FileContextMenu menu;
214 menu = new FileContextMenu(images, true, false);
216 menu = new FileContextMenu(images, false, false);
217 int left = event.getRelativeElement().getAbsoluteLeft();
218 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
219 menu.setPopupPosition(left, top);
221 } else if (GSS.get().getCurrentSelection() instanceof List) {
222 FileContextMenu menu;
224 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
225 menu = new FileContextMenu(images, true, false);
227 menu = new FileContextMenu(images, false, false);
228 menu.onMultipleSelection();
231 menu = new FileContextMenu(images, false, false);
232 menu.onMultipleSelection();
233 int left = event.getRelativeElement().getAbsoluteLeft();
234 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
235 menu.setPopupPosition(left, top);
241 public void onContextEvent(ContextMenuEvent event) {
242 if (GSS.get().getCurrentSelection() != null)
243 if (GSS.get().getCurrentSelection() instanceof FileResource) {
244 FileResource res = (FileResource) GSS.get().getCurrentSelection();
245 FileContextMenu menu;
247 menu = new FileContextMenu(images, true, false);
249 menu = new FileContextMenu(images, false, false);
250 int left = event.getNativeEvent().getClientX();
251 int top = event.getNativeEvent().getClientY();
252 menu.setPopupPosition(left, top);
255 } else if (GSS.get().getCurrentSelection() instanceof List) {
256 FileContextMenu menu;
258 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
259 menu = new FileContextMenu(images, true, false);
261 menu = new FileContextMenu(images, false, false);
262 menu.onMultipleSelection();
265 int left = event.getNativeEvent().getClientX();
266 int top = event.getNativeEvent().getClientY();
267 //menu.setPopupPosition(left, top);
272 public FileContextMenu onEvent(Event event) {
273 FileContextMenu menu=null;
274 if (GSS.get().getCurrentSelection() != null)
275 if (GSS.get().getCurrentSelection() instanceof FileResource) {
276 FileResource res = (FileResource) GSS.get().getCurrentSelection();
279 menu = new FileContextMenu(images, true, false);
281 menu = new FileContextMenu(images, false, false);
282 int left = event.getClientX();
283 int top = event.getClientY();
284 menu.setPopupPosition(left, top);
286 } else if (GSS.get().getCurrentSelection() instanceof List) {
288 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getSelection()))
289 menu = new FileContextMenu(images, true, false);
291 menu = new FileContextMenu(images, false, false);
292 menu.onMultipleSelection();
294 menu = new FileContextMenu(images, false, false);
295 menu.onMultipleSelection();
296 int left = event.getClientX();
297 int top = event.getClientY();
298 menu.setPopupPosition(left, top);
304 public FileContextMenu onEmptyEvent(Event event) {
305 FileContextMenu menu=null;
307 if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent()))
308 menu = new FileContextMenu(images, true, true);
309 else if(((DnDTreeItem)GSS.get().getTreeView().getCurrent()).getFolderResource() != null)
310 menu = new FileContextMenu(images, false, true);
313 int left = event.getClientX();
314 int top = event.getClientY();
315 menu.setPopupPosition(left, top);