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.AddUserCommand;
38 import gr.grnet.pithos.web.client.commands.CopyCommand;
39 import gr.grnet.pithos.web.client.commands.CreateGroupCommand;
40 import gr.grnet.pithos.web.client.commands.CutCommand;
41 import gr.grnet.pithos.web.client.commands.DeleteCommand;
42 import gr.grnet.pithos.web.client.commands.DeleteGroupCommand;
43 import gr.grnet.pithos.web.client.commands.EmptyTrashCommand;
44 import gr.grnet.pithos.web.client.commands.NewFolderCommand;
45 import gr.grnet.pithos.web.client.commands.PasteCommand;
46 import gr.grnet.pithos.web.client.commands.PropertiesCommand;
47 import gr.grnet.pithos.web.client.commands.RefreshCommand;
48 import gr.grnet.pithos.web.client.commands.RemoveUserCommand;
49 import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
50 import gr.grnet.pithos.web.client.commands.ToTrashCommand;
51 import gr.grnet.pithos.web.client.foldertree.File;
52 import gr.grnet.pithos.web.client.foldertree.Folder;
53 import gr.grnet.pithos.web.client.grouptree.Group;
54 import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
55 import gr.grnet.pithos.web.client.grouptree.User;
57 import java.util.List;
59 import com.google.gwt.user.client.Command;
60 import com.google.gwt.user.client.Window;
61 import com.google.gwt.user.client.ui.AbstractImagePrototype;
62 import com.google.gwt.user.client.ui.MenuBar;
63 import com.google.gwt.user.client.ui.MenuItem;
64 import com.google.gwt.user.client.ui.PopupPanel;
67 * The 'Folder Context' menu implementation.
69 public class ToolsMenu extends PopupPanel {
72 * The widget's images.
74 private final Images images;
77 * The image bundle for this widget's images that reuses images defined in
80 public interface Images extends GroupTreeView.Images {
83 private MenuItem pasteItem;
85 private boolean empty = false;;
88 * The widget's constructor.
90 * @param newImages the image bundle passed on by the parent object
92 public ToolsMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder folder, final List<File> files) {
93 // The popup's constructor's argument is a boolean specifying that it
94 // auto-close itself when the user clicks outside of it.
96 setAnimationEnabled(true);
98 MenuBar contextMenu = new MenuBar(true);
100 if (folder != null) {
101 Boolean[] permissions = folder.getPermissions().get(app.getUsername());
102 boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
103 boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
105 if (!folder.isInTrash()) {
108 if (isFolderTreeSelected) {
110 if (files != null && !files.isEmpty()) {
111 cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut files</span>", true, new CutCommand(app, this, files));
113 else if (!folder.isContainer()) {
114 cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut folder</span>", true, new CutCommand(app, this, folder));
117 contextMenu.addItem(cut);
121 MenuItem copy = null;
122 if (files != null && !files.isEmpty())
123 copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy files</span>", true, new CopyCommand(app, this, files));
124 else if (!folder.isContainer())
125 copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy folder</span>", true, new CopyCommand(app, this, folder));
127 contextMenu.addItem(copy);
130 if (!app.getClipboard().isEmpty()) {
131 Object item = app.getClipboard().getItem();
132 boolean showPaste = false;
133 if (item instanceof List) {
134 List<File> _files = (List<File>) item;
135 if (_files.get(0).getOwner().equals(folder.getOwner()))
139 Folder f = (Folder) item;
140 if (f.getOwner().equals(folder.getOwner()))
144 pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, folder));
145 contextMenu.addItem(pasteItem);
149 if (isFolderTreeSelected) {
150 MenuItem moveToTrash = null;
151 if (files != null && !files.isEmpty()) {
152 moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move files to Trash</span>", true, new ToTrashCommand(app, this, files));
154 else if (!folder.isContainer()) {
155 moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move folder to Trash</span>", true, new ToTrashCommand(app, this, folder));
157 if (moveToTrash != null)
158 contextMenu.addItem(moveToTrash);
160 MenuItem delete = null;
161 if (files != null && !files.isEmpty()) {
162 delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete files</span>", true, new DeleteCommand(app, this, files, MessagePanel.images));
164 else if (!folder.isContainer())
165 delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete folder</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
167 contextMenu.addItem(delete);
169 MenuItem properties = null;
170 if (files != null && files.size() == 1)
171 properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " File properties</span>", true, new PropertiesCommand(app, this, files, 0));
172 else if (!folder.isContainer())
173 properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Folder properties</span>", true, new PropertiesCommand(app, this, folder, 0));
174 if (properties != null)
175 contextMenu.addItem(properties);
177 if (files != null && !files.isEmpty()) {
178 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() {
181 public void execute() {
183 Window.open(app.getApiPath() + files.get(0).getOwner() + files.get(0).getUri() + "?X-Auth-Token=" + app.getToken(), "_blank", "");
190 if (!folder.isTrash()) {
191 MenuItem restore = null;
192 if (files != null && !files.isEmpty())
193 restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, files));
195 restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, folder));
196 contextMenu.addItem(restore);
198 MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
199 contextMenu.addItem(delete);
202 MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(app, this));
203 contextMenu.addItem(emptyTrash);
208 Object o = app.getGroupTreeView().getSelected();
210 if (o instanceof User) {
211 MenuItem removeUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Remove User</span>", true, new RemoveUserCommand(app, this, (User) o));
212 contextMenu.addItem(removeUser);
214 else if (o instanceof Group) {
215 MenuItem addUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.user()).getHTML() + " Add User</span>", true, new AddUserCommand(app, this, (Group) o));
216 contextMenu.addItem(addUser);
218 MenuItem deleteGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete Group</span>", true, new DeleteGroupCommand(app, this, (Group) o));
219 contextMenu.addItem(deleteGroup);
222 MenuItem createGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.group()).getHTML() + " Create Group</span>", true, new CreateGroupCommand(app, this));
223 contextMenu.addItem(createGroup);
232 public boolean isEmpty() {