2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
35 package gr.grnet.pithos.web.client;
37 import gr.grnet.pithos.web.client.commands.CopyCommand;
38 import gr.grnet.pithos.web.client.commands.CutCommand;
39 import gr.grnet.pithos.web.client.commands.DeleteCommand;
40 import gr.grnet.pithos.web.client.commands.PasteCommand;
41 import gr.grnet.pithos.web.client.commands.PropertiesCommand;
42 import gr.grnet.pithos.web.client.commands.RefreshCommand;
43 import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
44 import gr.grnet.pithos.web.client.commands.ToTrashCommand;
45 import gr.grnet.pithos.web.client.commands.UploadFileCommand;
46 import gr.grnet.pithos.web.client.foldertree.File;
47 import gr.grnet.pithos.web.client.foldertree.Folder;
48 import gr.grnet.pithos.web.client.rest.resource.FileResource;
49 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
50 import gr.grnet.pithos.web.client.rest.resource.RestResource;
51 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
52 import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
54 import java.util.List;
56 import com.google.gwt.event.dom.client.ClickEvent;
57 import com.google.gwt.event.dom.client.ClickHandler;
58 import com.google.gwt.event.dom.client.ContextMenuEvent;
59 import com.google.gwt.resources.client.ClientBundle;
60 import com.google.gwt.resources.client.ImageResource;
61 import com.google.gwt.user.client.Command;
62 import com.google.gwt.user.client.Event;
63 import com.google.gwt.user.client.ui.AbstractImagePrototype;
64 import com.google.gwt.user.client.ui.MenuBar;
65 import com.google.gwt.user.client.ui.MenuItem;
66 import com.google.gwt.user.client.ui.PopupPanel;
69 * The 'File Context' menu implementation.
71 public class FileContextMenu extends PopupPanel {
74 * The widget's images.
76 private final Images images;
78 private MenuItem cutItem;
80 private MenuItem copyItem;
82 private MenuItem pasteItem;
84 private MenuItem updateItem;
86 private MenuItem sharingItem;
88 private MenuItem propItem;
90 private MenuItem trashItem;
92 private MenuItem deleteItem;
94 private MenuItem downloadItem;
96 private MenuItem saveAsItem;
99 * The image bundle for this widget's images that reuses images defined in
102 public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
104 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
105 ImageResource fileContextMenu();
107 @Source("gr/grnet/pithos/resources/doc_versions.png")
108 ImageResource versions();
111 @Source("gr/grnet/pithos/resources/group.png")
112 ImageResource sharing();
115 @Source("gr/grnet/pithos/resources/border_remove.png")
116 ImageResource unselectAll();
118 @Source("gr/grnet/pithos/resources/demo.png")
119 ImageResource viewImage();
122 public static native String getDate()/*-{
123 return (new Date()).toUTCString();
127 * The widget's constructor.
129 * @param newImages the image bundle passed on by the parent object
131 public FileContextMenu(Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) {
132 // The popup's constructor's argument is a boolean specifying that it
133 // auto-close itself when the user clicks outside of it.
136 setAnimationEnabled(true);
138 MenuBar contextMenu = new MenuBar(true);
140 if (GSS.get().getClipboard().hasFiles()) {
141 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(GSS.get(), this, selectedFolder));
142 contextMenu.addItem(pasteItem);
145 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this, selectedFolder));
146 contextMenu.addItem(upload);
148 // MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
149 // contextMenu.addItem(refresh);
152 // MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
153 // contextMenu.addItem(restore);
155 // MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
156 // contextMenu.addItem(delete);
158 cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(GSS.get(), this, selectedFiles));
159 contextMenu.addItem(cutItem);
161 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(GSS.get(), this, selectedFiles));
162 contextMenu.addItem(copyItem);
164 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, selectedFiles));
165 contextMenu.addItem(trashItem);
167 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, selectedFiles, images));
168 contextMenu.addItem(deleteItem);
170 // sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
171 // contextMenu.addItem(sharingItem);
173 // propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
174 // contextMenu.addItem(propItem);
176 contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + GSS.get().getApiPath() + GSS.get().getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + GSS.get().getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));
178 MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, new Command() {
180 public void execute() {
182 GSS.get().getFileList().clearSelectedRows();
185 contextMenu.addItem(unSelect);