root / src / gr / grnet / pithos / web / client / ToolsMenu.java @ 28e270f9
History | View | Annotate | Download (11.2 kB)
1 | a9e497d4 | Christos Stathis | /*
|
---|---|---|---|
2 | e6e9f6e6 | Christos KK Loverdos | * Copyright 2011-2013 GRNET S.A. All rights reserved.
|
3 | a9e497d4 | Christos Stathis | *
|
4 | a9e497d4 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | a9e497d4 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | a9e497d4 | Christos Stathis | * conditions are met:
|
7 | a9e497d4 | Christos Stathis | *
|
8 | a9e497d4 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | a9e497d4 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | a9e497d4 | Christos Stathis | * disclaimer.
|
11 | a9e497d4 | Christos Stathis | *
|
12 | a9e497d4 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | a9e497d4 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | a9e497d4 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | a9e497d4 | Christos Stathis | * provided with the distribution.
|
16 | a9e497d4 | Christos Stathis | *
|
17 | a9e497d4 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | a9e497d4 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | a9e497d4 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | a9e497d4 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | a9e497d4 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | a9e497d4 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | a9e497d4 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | a9e497d4 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | a9e497d4 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | a9e497d4 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | a9e497d4 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | a9e497d4 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | a9e497d4 | Christos Stathis | *
|
30 | a9e497d4 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | a9e497d4 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | a9e497d4 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | a9e497d4 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a9e497d4 | Christos Stathis | */
|
35 | a9e497d4 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a9e497d4 | Christos Stathis | |
37 | 8ddb4627 | Christos KK Loverdos | import gr.grnet.pithos.web.client.commands.*; |
38 | 8ddb4627 | Christos KK Loverdos | import gr.grnet.pithos.web.client.commands.PurgeContainerCommand; |
39 | a9e497d4 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
40 | a9e497d4 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
41 | b162dfaa | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.Group; |
42 | b162dfaa | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.GroupTreeView; |
43 | b162dfaa | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.User; |
44 | a9e497d4 | Christos Stathis | |
45 | a9e497d4 | Christos Stathis | import java.util.List; |
46 | a9e497d4 | Christos Stathis | |
47 | a9e497d4 | Christos Stathis | import com.google.gwt.user.client.Command; |
48 | 05bb97f8 | Christos Stathis | import com.google.gwt.user.client.Window; |
49 | a9e497d4 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
50 | a9e497d4 | Christos Stathis | import com.google.gwt.user.client.ui.MenuBar; |
51 | a9e497d4 | Christos Stathis | import com.google.gwt.user.client.ui.MenuItem; |
52 | a9e497d4 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
53 | a9e497d4 | Christos Stathis | |
54 | a9e497d4 | Christos Stathis | /**
|
55 | a9e497d4 | Christos Stathis | * The 'Folder Context' menu implementation.
|
56 | a9e497d4 | Christos Stathis | */
|
57 | a9e497d4 | Christos Stathis | public class ToolsMenu extends PopupPanel { |
58 | a9e497d4 | Christos Stathis | |
59 | a9e497d4 | Christos Stathis | /**
|
60 | a9e497d4 | Christos Stathis | * The widget's images.
|
61 | a9e497d4 | Christos Stathis | */
|
62 | a9e497d4 | Christos Stathis | private final Images images; |
63 | a9e497d4 | Christos Stathis | |
64 | a9e497d4 | Christos Stathis | /**
|
65 | a9e497d4 | Christos Stathis | * The image bundle for this widget's images that reuses images defined in
|
66 | a9e497d4 | Christos Stathis | * other menus.
|
67 | a9e497d4 | Christos Stathis | */
|
68 | b162dfaa | Christos Stathis | public interface Images extends GroupTreeView.Images { |
69 | a9e497d4 | Christos Stathis | } |
70 | a9e497d4 | Christos Stathis | |
71 | a9e497d4 | Christos Stathis | private MenuItem pasteItem; |
72 | a9e497d4 | Christos Stathis | |
73 | 7c02238e | Christos Stathis | private boolean empty = true; |
74 | b162dfaa | Christos Stathis | |
75 | a9e497d4 | Christos Stathis | /**
|
76 | a9e497d4 | Christos Stathis | * The widget's constructor.
|
77 | a9e497d4 | Christos Stathis | *
|
78 | a9e497d4 | Christos Stathis | * @param newImages the image bundle passed on by the parent object
|
79 | a9e497d4 | Christos Stathis | */
|
80 | 05bb97f8 | Christos Stathis | public ToolsMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder folder, final List<File> files) { |
81 | a9e497d4 | Christos Stathis | // The popup's constructor's argument is a boolean specifying that it
|
82 | a9e497d4 | Christos Stathis | // auto-close itself when the user clicks outside of it.
|
83 | a9e497d4 | Christos Stathis | super(true); |
84 | a9e497d4 | Christos Stathis | images = newImages; |
85 | a9e497d4 | Christos Stathis | MenuBar contextMenu = new MenuBar(true); |
86 | a9e497d4 | Christos Stathis | |
87 | a9e497d4 | Christos Stathis | if (folder != null) { |
88 | cc0120ab | Christos KK Loverdos | Boolean[] permissions = folder.getPermissions().get(app.getUserID()); |
89 | 4eaecbac | Christos KK Loverdos | boolean canWrite = folder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]); |
90 | a9e497d4 | Christos Stathis | boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
|
91 | 5d18aa82 | Christos Stathis | boolean isMysharedTreeSelected = app.isMySharedSelected();
|
92 | a9e497d4 | Christos Stathis | |
93 | a9e497d4 | Christos Stathis | if (!folder.isInTrash()) {
|
94 | a9e497d4 | Christos Stathis | if (canWrite) {
|
95 | a9e497d4 | Christos Stathis | |
96 | 3586ad5e | Christos Stathis | if (isFolderTreeSelected || isMysharedTreeSelected) {
|
97 | a9e497d4 | Christos Stathis | MenuItem cut = null; |
98 | a9e497d4 | Christos Stathis | if (files != null && !files.isEmpty()) { |
99 | a9e497d4 | Christos Stathis | cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut files</span>", true, new CutCommand(app, this, files)); |
100 | a9e497d4 | Christos Stathis | } |
101 | a9e497d4 | Christos Stathis | else if (!folder.isContainer()) { |
102 | a9e497d4 | Christos Stathis | cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut folder</span>", true, new CutCommand(app, this, folder)); |
103 | a9e497d4 | Christos Stathis | } |
104 | 7c02238e | Christos Stathis | if (cut != null) { |
105 | a9e497d4 | Christos Stathis | contextMenu.addItem(cut); |
106 | 7c02238e | Christos Stathis | empty = false;
|
107 | 7c02238e | Christos Stathis | } |
108 | a9e497d4 | Christos Stathis | } |
109 | a9e497d4 | Christos Stathis | } |
110 | a9e497d4 | Christos Stathis | |
111 | 3586ad5e | Christos Stathis | MenuItem copy = null; |
112 | 3586ad5e | Christos Stathis | if (files != null && !files.isEmpty()) |
113 | 3586ad5e | Christos Stathis | copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy files</span>", true, new CopyCommand(app, this, files)); |
114 | 3586ad5e | Christos Stathis | else if (isFolderTreeSelected && !folder.isContainer()) |
115 | 3586ad5e | Christos Stathis | copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy folder</span>", true, new CopyCommand(app, this, folder)); |
116 | 3586ad5e | Christos Stathis | if (copy != null) { |
117 | 3586ad5e | Christos Stathis | contextMenu.addItem(copy); |
118 | 3586ad5e | Christos Stathis | empty = false;
|
119 | 7c02238e | Christos Stathis | } |
120 | a9e497d4 | Christos Stathis | |
121 | a9e497d4 | Christos Stathis | if (canWrite) {
|
122 | 5d18aa82 | Christos Stathis | if (!isMysharedTreeSelected && !app.getClipboard().isEmpty()) {
|
123 | a9e497d4 | Christos Stathis | Object item = app.getClipboard().getItem();
|
124 | a9e497d4 | Christos Stathis | boolean showPaste = false; |
125 | a9e497d4 | Christos Stathis | if (item instanceof List) { |
126 | ebead1b5 | Christos Stathis | @SuppressWarnings("unchecked") |
127 | ebead1b5 | Christos Stathis | List<File> _files = (List<File>) item; |
128 | 4eaecbac | Christos KK Loverdos | if (_files.get(0).getOwnerID().equals(folder.getOwnerID())) |
129 | a9e497d4 | Christos Stathis | showPaste = true;
|
130 | a9e497d4 | Christos Stathis | } |
131 | a9e497d4 | Christos Stathis | else {
|
132 | a9e497d4 | Christos Stathis | Folder f = (Folder) item; |
133 | 4eaecbac | Christos KK Loverdos | if (f.getOwnerID().equals(folder.getOwnerID()))
|
134 | a9e497d4 | Christos Stathis | showPaste = true;
|
135 | a9e497d4 | Christos Stathis | } |
136 | a9e497d4 | Christos Stathis | if (showPaste) {
|
137 | a9e497d4 | Christos Stathis | pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, folder)); |
138 | a9e497d4 | Christos Stathis | contextMenu.addItem(pasteItem); |
139 | 7c02238e | Christos Stathis | empty = false;
|
140 | a9e497d4 | Christos Stathis | } |
141 | a9e497d4 | Christos Stathis | } |
142 | a9e497d4 | Christos Stathis | |
143 | 3586ad5e | Christos Stathis | if (isFolderTreeSelected || isMysharedTreeSelected) {
|
144 | a9e497d4 | Christos Stathis | MenuItem moveToTrash = null; |
145 | a9e497d4 | Christos Stathis | if (files != null && !files.isEmpty()) { |
146 | a9e497d4 | Christos Stathis | moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move files to Trash</span>", true, new ToTrashCommand(app, this, files)); |
147 | a9e497d4 | Christos Stathis | } |
148 | a9e497d4 | Christos Stathis | else if (!folder.isContainer()) { |
149 | a9e497d4 | Christos Stathis | moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move folder to Trash</span>", true, new ToTrashCommand(app, this, folder)); |
150 | a9e497d4 | Christos Stathis | } |
151 | 7c02238e | Christos Stathis | if (moveToTrash != null) { |
152 | a9e497d4 | Christos Stathis | contextMenu.addItem(moveToTrash); |
153 | 7c02238e | Christos Stathis | empty = false;
|
154 | 7c02238e | Christos Stathis | } |
155 | 5d18aa82 | Christos Stathis | } |
156 | 5d18aa82 | Christos Stathis | if (isFolderTreeSelected || isMysharedTreeSelected) {
|
157 | 9326b841 | Christos Stathis | if (files != null && files.size() == 1) { |
158 | 9326b841 | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " File properties</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PROPERTIES))); |
159 | 64d3b76b | Christos KK Loverdos | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.group()).getHTML() + " Share</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PERMISSIONS))); |
160 | 3586ad5e | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Versions</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.VERSIONS))); |
161 | 7c02238e | Christos Stathis | empty = false;
|
162 | 9326b841 | Christos Stathis | } |
163 | 6b7d024f | Christos Stathis | else if (!folder.isContainer()) { |
164 | 6b7d024f | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Folder properties</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES))); |
165 | 10ff638f | Christos KK Loverdos | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Share</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS))); |
166 | 7c02238e | Christos Stathis | empty = false;
|
167 | 6b7d024f | Christos Stathis | } |
168 | a9e497d4 | Christos Stathis | } |
169 | 006ec41a | Christos Stathis | if (files != null && !files.isEmpty()) { |
170 | 05bb97f8 | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() { |
171 | 05bb97f8 | Christos Stathis | |
172 | 05bb97f8 | Christos Stathis | @Override
|
173 | 05bb97f8 | Christos Stathis | public void execute() { |
174 | 05bb97f8 | Christos Stathis | for (File f: files) |
175 | 28e270f9 | Christos KK Loverdos | Window.open(Pithos.getStorageAPIURL() + f.getOwnerID() + f.getUri(), "_blank", ""); |
176 | 05bb97f8 | Christos Stathis | } |
177 | 05bb97f8 | Christos Stathis | })); |
178 | 7c02238e | Christos Stathis | empty = false;
|
179 | 05bb97f8 | Christos Stathis | } |
180 | 42214d4a | Christos Stathis | if (isFolderTreeSelected && folder.isContainer()) {
|
181 | 8ddb4627 | Christos KK Loverdos | MenuItem emptyContainer = new MenuItem( |
182 | 8ddb4627 | Christos KK Loverdos | "<span>" + Const.PurgeContainer(folder.getName()) + "</span>", |
183 | 8ddb4627 | Christos KK Loverdos | true,
|
184 | 8ddb4627 | Christos KK Loverdos | new PurgeContainerCommand(app, this, folder) |
185 | 8ddb4627 | Christos KK Loverdos | ); |
186 | 42214d4a | Christos Stathis | contextMenu.addItem(emptyContainer); |
187 | 42214d4a | Christos Stathis | empty = false;
|
188 | 42214d4a | Christos Stathis | } |
189 | a9e497d4 | Christos Stathis | } |
190 | a9e497d4 | Christos Stathis | } |
191 | a9e497d4 | Christos Stathis | else {
|
192 | a9e497d4 | Christos Stathis | if (!folder.isTrash()) {
|
193 | a9e497d4 | Christos Stathis | MenuItem restore = null; |
194 | a9e497d4 | Christos Stathis | if (files != null && !files.isEmpty()) |
195 | a9e497d4 | Christos Stathis | restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, files)); |
196 | a9e497d4 | Christos Stathis | else
|
197 | a9e497d4 | Christos Stathis | restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, folder)); |
198 | a9e497d4 | Christos Stathis | contextMenu.addItem(restore); |
199 | 7c02238e | Christos Stathis | |
200 | a9e497d4 | Christos Stathis | MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images)); |
201 | a9e497d4 | Christos Stathis | contextMenu.addItem(delete); |
202 | 7c02238e | Christos Stathis | empty = false;
|
203 | a9e497d4 | Christos Stathis | } |
204 | a9e497d4 | Christos Stathis | else {
|
205 | 8ddb4627 | Christos KK Loverdos | MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash</span>", true, new PurgeContainerCommand(app, this, folder)); |
206 | a9e497d4 | Christos Stathis | contextMenu.addItem(emptyTrash); |
207 | 7c02238e | Christos Stathis | empty = false;
|
208 | a9e497d4 | Christos Stathis | } |
209 | a9e497d4 | Christos Stathis | } |
210 | a9e497d4 | Christos Stathis | } |
211 | b162dfaa | Christos Stathis | else {
|
212 | b162dfaa | Christos Stathis | Object o = app.getGroupTreeView().getSelected();
|
213 | b162dfaa | Christos Stathis | if (o != null) { |
214 | b162dfaa | Christos Stathis | if (o instanceof User) { |
215 | b162dfaa | Christos Stathis | MenuItem removeUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Remove User</span>", true, new RemoveUserCommand(app, this, (User) o)); |
216 | b162dfaa | Christos Stathis | contextMenu.addItem(removeUser); |
217 | 7c02238e | Christos Stathis | empty = false;
|
218 | b162dfaa | Christos Stathis | } |
219 | b162dfaa | Christos Stathis | else if (o instanceof Group) { |
220 | b162dfaa | Christos Stathis | MenuItem addUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.user()).getHTML() + " Add User</span>", true, new AddUserCommand(app, this, (Group) o)); |
221 | b162dfaa | Christos Stathis | contextMenu.addItem(addUser); |
222 | b162dfaa | Christos Stathis | |
223 | b162dfaa | Christos Stathis | MenuItem deleteGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete Group</span>", true, new DeleteGroupCommand(app, this, (Group) o)); |
224 | b162dfaa | Christos Stathis | contextMenu.addItem(deleteGroup); |
225 | 7c02238e | Christos Stathis | empty = false;
|
226 | b162dfaa | Christos Stathis | } |
227 | b162dfaa | Christos Stathis | } |
228 | b162dfaa | Christos Stathis | } |
229 | c46c9e31 | Christos Stathis | MenuItem createGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.group()).getHTML() + " Create Group</span>", true, new CreateGroupCommand(app, this)); |
230 | c46c9e31 | Christos Stathis | contextMenu.addItem(createGroup); |
231 | c46c9e31 | Christos Stathis | empty = false;
|
232 | b162dfaa | Christos Stathis | add(contextMenu); |
233 | b162dfaa | Christos Stathis | } |
234 | b162dfaa | Christos Stathis | |
235 | b162dfaa | Christos Stathis | public boolean isEmpty() { |
236 | b162dfaa | Christos Stathis | return empty;
|
237 | a9e497d4 | Christos Stathis | } |
238 | a9e497d4 | Christos Stathis | } |