2 * Copyright 2011-2013 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 com.google.gwt.resources.client.ClientBundle;
38 import com.google.gwt.resources.client.ImageResource;
39 import com.google.gwt.user.client.Command;
40 import com.google.gwt.user.client.Window;
41 import com.google.gwt.user.client.ui.AbstractImagePrototype;
42 import com.google.gwt.user.client.ui.MenuBar;
43 import com.google.gwt.user.client.ui.MenuItem;
44 import com.google.gwt.user.client.ui.PopupPanel;
45 import gr.grnet.pithos.web.client.commands.*;
46 import gr.grnet.pithos.web.client.foldertree.File;
47 import gr.grnet.pithos.web.client.foldertree.Folder;
49 import java.util.List;
52 * The 'File Context' menu implementation.
54 public class FileContextMenu extends PopupPanel {
57 * The widget's images.
59 private final Images images;
61 private MenuItem cutItem;
63 private MenuItem copyItem;
65 private MenuItem pasteItem;
67 private MenuItem updateItem;
69 private MenuItem sharingItem;
71 private MenuItem propItem;
73 private MenuItem trashItem;
75 private MenuItem deleteItem;
77 private MenuItem downloadItem;
79 private MenuItem saveAsItem;
82 * The image bundle for this widget's images that reuses images defined in
85 public interface Images extends ClientBundle {
87 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
88 ImageResource fileContextMenu();
90 @Source("gr/grnet/pithos/resources/doc_versions.png")
91 ImageResource versions();
93 @Source("gr/grnet/pithos/resources/groups22.png")
94 ImageResource sharing();
96 @Source("gr/grnet/pithos/resources/border_remove.png")
97 ImageResource unselectAll();
99 @Source("gr/grnet/pithos/resources/demo.png")
100 ImageResource viewImage();
102 @Source("gr/grnet/pithos/resources/folder_new.png")
103 ImageResource folderNew();
105 @Source("gr/grnet/pithos/resources/folder_outbox.png")
106 ImageResource fileUpdate();
108 @Source("gr/grnet/pithos/resources/view_text.png")
109 ImageResource viewText();
111 @Source("gr/grnet/pithos/resources/folder_inbox.png")
112 ImageResource download();
114 @Source("gr/grnet/pithos/resources/trash.png")
115 ImageResource emptyTrash();
117 @Source("gr/grnet/pithos/resources/refresh.png")
118 ImageResource refresh();
121 * Will bundle the file 'editcut.png' residing in the package
122 * 'gr.grnet.pithos.web.resources'.
124 * @return the image prototype
126 @Source("gr/grnet/pithos/resources/editcut.png")
130 * Will bundle the file 'editcopy.png' residing in the package
131 * 'gr.grnet.pithos.web.resources'.
133 * @return the image prototype
135 @Source("gr/grnet/pithos/resources/editcopy.png")
136 ImageResource copy();
139 * Will bundle the file 'editpaste.png' residing in the package
140 * 'gr.grnet.pithos.web.resources'.
142 * @return the image prototype
144 @Source("gr/grnet/pithos/resources/editpaste.png")
145 ImageResource paste();
148 * Will bundle the file 'editdelete.png' residing in the package
149 * 'gr.grnet.pithos.web.resources'.
151 * @return the image prototype
153 @Source("gr/grnet/pithos/resources/editdelete.png")
154 ImageResource delete();
157 * Will bundle the file 'translate.png' residing in the package
158 * 'gr.grnet.pithos.web.resources'.
160 * @return the image prototype
162 @Source("gr/grnet/pithos/resources/translate.png")
163 ImageResource selectAll();
165 @Source("gr/grnet/pithos/resources/internet.png")
166 ImageResource internet();
169 public static native String getDate()/*-{
170 return (new Date()).toUTCString();
174 * The widget's constructor.
176 * @param newImages the image bundle passed on by the parent object
178 public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, final List<File> selectedFiles) {
179 // The popup's constructor's argument is a boolean specifying that it
180 // auto-close itself when the user clicks outside of it.
183 MenuBar contextMenu = new MenuBar(true);
184 Boolean[] permissions = null;
185 boolean canWrite = true;
186 if (selectedFolder != null) {
187 permissions = selectedFolder.getPermissions().get(app.getUserID());
188 canWrite = selectedFolder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]);
191 for (File f : selectedFiles) {
192 permissions = f.getPermissions().get(app.getUserID());
193 canWrite &= (f.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]));
196 boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
197 boolean isMysharedSelected = selectedTree.equals(app.getMySharedTreeView());
199 Pithos.LOG("FileContextMenu(), selectedFolder=", selectedFolder);
200 Pithos.LOG("FileContextMenu(), isFolderTreeSelected=", isFolderTreeSelected);
201 Pithos.LOG("FileContextMenu(), isMysharedSelected=", isMysharedSelected);
203 if (selectedFolder != null) {
204 if (!selectedFolder.isInTrash()) {
205 if (canWrite && app.getClipboard().hasFiles() && !isMysharedSelected) {
206 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, selectedFolder));
207 contextMenu.addItem(pasteItem);
210 if (isFolderTreeSelected || isMysharedSelected) {
211 cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(app, this, selectedFiles));
212 contextMenu.addItem(cutItem);
215 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(app, this, selectedFiles));
216 contextMenu.addItem(copyItem);
218 if (isFolderTreeSelected || isMysharedSelected) {
219 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
220 contextMenu.addItem(trashItem);
224 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
225 contextMenu.addItem(restore);
227 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
228 contextMenu.addItem(deleteItem);
232 if (selectedFolder != null && !selectedFolder.isInTrash()) {
233 if ((isFolderTreeSelected || isMysharedSelected) && selectedFiles.size() == 1) {
234 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PROPERTIES)));
235 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Share</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PERMISSIONS)));
236 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Versions</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.VERSIONS)));
240 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() {
243 public void execute() {
244 for (File f : selectedFiles) {
245 Window.open(Pithos.getFileViewURL(f), "_blank", "");