2 * Copyright 2011-2012 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.EmptyContainerCommand;
44 import gr.grnet.pithos.web.client.commands.PasteCommand;
45 import gr.grnet.pithos.web.client.commands.PropertiesCommand;
46 import gr.grnet.pithos.web.client.commands.RemoveUserCommand;
47 import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
48 import gr.grnet.pithos.web.client.commands.ToTrashCommand;
49 import gr.grnet.pithos.web.client.foldertree.File;
50 import gr.grnet.pithos.web.client.foldertree.Folder;
51 import gr.grnet.pithos.web.client.grouptree.Group;
52 import gr.grnet.pithos.web.client.grouptree.GroupTreeView;
53 import gr.grnet.pithos.web.client.grouptree.User;
55 import java.util.List;
57 import com.google.gwt.user.client.Command;
58 import com.google.gwt.user.client.Window;
59 import com.google.gwt.user.client.ui.AbstractImagePrototype;
60 import com.google.gwt.user.client.ui.MenuBar;
61 import com.google.gwt.user.client.ui.MenuItem;
62 import com.google.gwt.user.client.ui.PopupPanel;
65 * The 'Folder Context' menu implementation.
67 public class ToolsMenu extends PopupPanel {
70 * The widget's images.
72 private final Images images;
75 * The image bundle for this widget's images that reuses images defined in
78 public interface Images extends GroupTreeView.Images {
81 private MenuItem pasteItem;
83 private boolean empty = true;
86 * The widget's constructor.
88 * @param newImages the image bundle passed on by the parent object
90 public ToolsMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder folder, final List<File> files) {
91 // The popup's constructor's argument is a boolean specifying that it
92 // auto-close itself when the user clicks outside of it.
95 MenuBar contextMenu = new MenuBar(true);
98 Boolean[] permissions = folder.getPermissions().get(app.getUserID());
99 boolean canWrite = folder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]);
100 boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
101 boolean isMysharedTreeSelected = app.isMySharedSelected();
103 if (!folder.isInTrash()) {
106 if (isFolderTreeSelected || isMysharedTreeSelected) {
108 if (files != null && !files.isEmpty()) {
109 cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut files</span>", true, new CutCommand(app, this, files));
111 else if (!folder.isContainer()) {
112 cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut folder</span>", true, new CutCommand(app, this, folder));
115 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 (isFolderTreeSelected && !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);
132 if (!isMysharedTreeSelected && !app.getClipboard().isEmpty()) {
133 Object item = app.getClipboard().getItem();
134 boolean showPaste = false;
135 if (item instanceof List) {
136 @SuppressWarnings("unchecked")
137 List<File> _files = (List<File>) item;
138 if (_files.get(0).getOwnerID().equals(folder.getOwnerID()))
142 Folder f = (Folder) item;
143 if (f.getOwnerID().equals(folder.getOwnerID()))
147 pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, folder));
148 contextMenu.addItem(pasteItem);
153 if (isFolderTreeSelected || isMysharedTreeSelected) {
154 MenuItem moveToTrash = null;
155 if (files != null && !files.isEmpty()) {
156 moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move files to Trash</span>", true, new ToTrashCommand(app, this, files));
158 else if (!folder.isContainer()) {
159 moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move folder to Trash</span>", true, new ToTrashCommand(app, this, folder));
161 if (moveToTrash != null) {
162 contextMenu.addItem(moveToTrash);
166 MenuItem delete = null;
167 if (files != null && !files.isEmpty()) {
168 delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete files</span>", true, new DeleteCommand(app, this, files, MessagePanel.images));
170 else if (!folder.isContainer())
171 delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete folder</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
172 if (delete != null) {
173 contextMenu.addItem(delete);
177 if (isFolderTreeSelected || isMysharedTreeSelected) {
178 if (files != null && files.size() == 1) {
179 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " File properties</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PROPERTIES)));
180 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.group()).getHTML() + " Sharing</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PERMISSIONS)));
181 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.internet()).getHTML() + " Publish</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PUBLISH)));
182 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Versions</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.VERSIONS)));
185 else if (!folder.isContainer()) {
186 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Folder properties</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES)));
187 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Folder sharing</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS)));
191 if (files != null && !files.isEmpty()) {
192 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() {
195 public void execute() {
197 Window.open(app.getApiPath() + f.getOwnerID() + f.getUri(), "_blank", "");
202 if (isFolderTreeSelected && folder.isContainer()) {
203 MenuItem emptyContainer = new MenuItem("<span>Empty Container</span>", true, new EmptyContainerCommand(app, this, folder));
204 contextMenu.addItem(emptyContainer);
210 if (!folder.isTrash()) {
211 MenuItem restore = null;
212 if (files != null && !files.isEmpty())
213 restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, files));
215 restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, folder));
216 contextMenu.addItem(restore);
218 MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
219 contextMenu.addItem(delete);
223 MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash</span>", true, new EmptyContainerCommand(app, this, folder));
224 contextMenu.addItem(emptyTrash);
230 Object o = app.getGroupTreeView().getSelected();
232 if (o instanceof User) {
233 MenuItem removeUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Remove User</span>", true, new RemoveUserCommand(app, this, (User) o));
234 contextMenu.addItem(removeUser);
237 else if (o instanceof Group) {
238 MenuItem addUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.user()).getHTML() + " Add User</span>", true, new AddUserCommand(app, this, (Group) o));
239 contextMenu.addItem(addUser);
241 MenuItem deleteGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete Group</span>", true, new DeleteGroupCommand(app, this, (Group) o));
242 contextMenu.addItem(deleteGroup);
247 MenuItem createGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.group()).getHTML() + " Create Group</span>", true, new CreateGroupCommand(app, this));
248 contextMenu.addItem(createGroup);
253 public boolean isEmpty() {