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.RestoreTrashCommand;
43 import gr.grnet.pithos.web.client.commands.ToTrashCommand;
44 import gr.grnet.pithos.web.client.commands.UploadFileCommand;
45 import gr.grnet.pithos.web.client.foldertree.File;
46 import gr.grnet.pithos.web.client.foldertree.Folder;
48 import java.util.List;
50 import com.google.gwt.resources.client.ClientBundle;
51 import com.google.gwt.resources.client.ImageResource;
52 import com.google.gwt.user.client.Command;
53 import com.google.gwt.user.client.ui.AbstractImagePrototype;
54 import com.google.gwt.user.client.ui.MenuBar;
55 import com.google.gwt.user.client.ui.MenuItem;
56 import com.google.gwt.user.client.ui.PopupPanel;
59 * The 'File Context' menu implementation.
61 public class FileContextMenu extends PopupPanel {
64 * The widget's images.
66 private final Images images;
68 private MenuItem cutItem;
70 private MenuItem copyItem;
72 private MenuItem pasteItem;
74 private MenuItem updateItem;
76 private MenuItem sharingItem;
78 private MenuItem propItem;
80 private MenuItem trashItem;
82 private MenuItem deleteItem;
84 private MenuItem downloadItem;
86 private MenuItem saveAsItem;
89 * The image bundle for this widget's images that reuses images defined in
92 public interface Images extends ClientBundle {
94 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
95 ImageResource fileContextMenu();
97 @Source("gr/grnet/pithos/resources/doc_versions.png")
98 ImageResource versions();
100 @Source("gr/grnet/pithos/resources/groups22.png")
101 ImageResource sharing();
103 @Source("gr/grnet/pithos/resources/border_remove.png")
104 ImageResource unselectAll();
106 @Source("gr/grnet/pithos/resources/demo.png")
107 ImageResource viewImage();
109 @Source("gr/grnet/pithos/resources/folder_new.png")
110 ImageResource folderNew();
112 @Source("gr/grnet/pithos/resources/folder_outbox.png")
113 ImageResource fileUpdate();
115 @Source("gr/grnet/pithos/resources/view_text.png")
116 ImageResource viewText();
118 @Source("gr/grnet/pithos/resources/folder_inbox.png")
119 ImageResource download();
121 @Source("gr/grnet/pithos/resources/trash.png")
122 ImageResource emptyTrash();
124 @Source("gr/grnet/pithos/resources/refresh.png")
125 ImageResource refresh();
128 * Will bundle the file 'editcut.png' residing in the package
129 * 'gr.grnet.pithos.web.resources'.
131 * @return the image prototype
133 @Source("gr/grnet/pithos/resources/editcut.png")
137 * Will bundle the file 'editcopy.png' residing in the package
138 * 'gr.grnet.pithos.web.resources'.
140 * @return the image prototype
142 @Source("gr/grnet/pithos/resources/editcopy.png")
143 ImageResource copy();
146 * Will bundle the file 'editpaste.png' residing in the package
147 * 'gr.grnet.pithos.web.resources'.
149 * @return the image prototype
151 @Source("gr/grnet/pithos/resources/editpaste.png")
152 ImageResource paste();
155 * Will bundle the file 'editdelete.png' residing in the package
156 * 'gr.grnet.pithos.web.resources'.
158 * @return the image prototype
160 @Source("gr/grnet/pithos/resources/editdelete.png")
161 ImageResource delete();
164 * Will bundle the file 'translate.png' residing in the package
165 * 'gr.grnet.pithos.web.resources'.
167 * @return the image prototype
169 @Source("gr/grnet/pithos/resources/translate.png")
170 ImageResource selectAll();
173 public static native String getDate()/*-{
174 return (new Date()).toUTCString();
178 * The widget's constructor.
180 * @param newImages the image bundle passed on by the parent object
182 public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, List<File> selectedFiles) {
183 // The popup's constructor's argument is a boolean specifying that it
184 // auto-close itself when the user clicks outside of it.
186 setAnimationEnabled(true);
188 MenuBar contextMenu = new MenuBar(true);
189 Boolean[] permissions = null;
190 boolean canWrite = true;
191 if (selectedFolder != null) {
192 permissions = selectedFolder.getPermissions().get(app.getUsername());
193 canWrite = selectedFolder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
196 for (File f : selectedFiles) {
197 permissions = f.getPermissions().get(app.getUsername());
198 canWrite &= (f.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]));
201 boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
202 if (selectedFolder != null) {
203 if (!selectedFolder.isInTrash()) {
204 if (canWrite && app.getClipboard().hasFiles()) {
205 List<File> files = (List<File>) app.getClipboard().getItem();
206 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, selectedFolder));
207 contextMenu.addItem(pasteItem);
211 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
212 contextMenu.addItem(upload);
214 if (isFolderTreeSelected) {
215 cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(app, this, selectedFiles));
216 contextMenu.addItem(cutItem);
220 if (isFolderTreeSelected) {
221 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
222 contextMenu.addItem(trashItem);
226 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
227 contextMenu.addItem(restore);
230 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(app, this, selectedFiles));
231 contextMenu.addItem(copyItem);
233 if (isFolderTreeSelected) {
234 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
235 contextMenu.addItem(deleteItem);
238 if (selectedFolder != null && !selectedFolder.isInTrash()) {
239 if (isFolderTreeSelected && selectedFiles.size() == 1)
240 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0)));
243 if (selectedFiles.size() == 1)
244 contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + app.getApiPath() + selectedFiles.get(0).getOwner() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + app.getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));