root / src / gr / grnet / pithos / web / client / FileContextMenu.java @ 3c058715
History | View | Annotate | Download (10.5 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | cae2a8db | Christos Stathis | * Copyright 2011-2012 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a57faaf0 | Christos Stathis | */
|
35 | a57faaf0 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a57faaf0 | Christos Stathis | |
37 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.CopyCommand; |
38 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.CutCommand; |
39 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.DeleteCommand; |
40 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.PasteCommand; |
41 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.PropertiesCommand; |
42 | 31477486 | Christos Stathis | import gr.grnet.pithos.web.client.commands.RestoreTrashCommand; |
43 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.ToTrashCommand; |
44 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.commands.UploadFileCommand; |
45 | d4374639 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
46 | 63366925 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
47 | a57faaf0 | Christos Stathis | |
48 | a57faaf0 | Christos Stathis | import java.util.List; |
49 | a57faaf0 | Christos Stathis | |
50 | d02b08f2 | Christos Stathis | import com.google.gwt.http.client.URL; |
51 | a57faaf0 | Christos Stathis | import com.google.gwt.resources.client.ClientBundle; |
52 | a57faaf0 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
53 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Command; |
54 | 05bb97f8 | Christos Stathis | import com.google.gwt.user.client.Window; |
55 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
56 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.MenuBar; |
57 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.MenuItem; |
58 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
59 | a57faaf0 | Christos Stathis | |
60 | a57faaf0 | Christos Stathis | /**
|
61 | a57faaf0 | Christos Stathis | * The 'File Context' menu implementation.
|
62 | a57faaf0 | Christos Stathis | */
|
63 | 63366925 | Christos Stathis | public class FileContextMenu extends PopupPanel { |
64 | a57faaf0 | Christos Stathis | |
65 | a57faaf0 | Christos Stathis | /**
|
66 | a57faaf0 | Christos Stathis | * The widget's images.
|
67 | a57faaf0 | Christos Stathis | */
|
68 | a57faaf0 | Christos Stathis | private final Images images; |
69 | a57faaf0 | Christos Stathis | |
70 | a57faaf0 | Christos Stathis | private MenuItem cutItem; |
71 | a57faaf0 | Christos Stathis | |
72 | a57faaf0 | Christos Stathis | private MenuItem copyItem; |
73 | a57faaf0 | Christos Stathis | |
74 | a57faaf0 | Christos Stathis | private MenuItem pasteItem; |
75 | a57faaf0 | Christos Stathis | |
76 | a57faaf0 | Christos Stathis | private MenuItem updateItem; |
77 | a57faaf0 | Christos Stathis | |
78 | a57faaf0 | Christos Stathis | private MenuItem sharingItem; |
79 | a57faaf0 | Christos Stathis | |
80 | a57faaf0 | Christos Stathis | private MenuItem propItem; |
81 | a57faaf0 | Christos Stathis | |
82 | a57faaf0 | Christos Stathis | private MenuItem trashItem; |
83 | a57faaf0 | Christos Stathis | |
84 | a57faaf0 | Christos Stathis | private MenuItem deleteItem; |
85 | a57faaf0 | Christos Stathis | |
86 | a57faaf0 | Christos Stathis | private MenuItem downloadItem; |
87 | a57faaf0 | Christos Stathis | |
88 | a57faaf0 | Christos Stathis | private MenuItem saveAsItem; |
89 | a57faaf0 | Christos Stathis | |
90 | a57faaf0 | Christos Stathis | /**
|
91 | a57faaf0 | Christos Stathis | * The image bundle for this widget's images that reuses images defined in
|
92 | a57faaf0 | Christos Stathis | * other menus.
|
93 | a57faaf0 | Christos Stathis | */
|
94 | f6445935 | Christos Stathis | public interface Images extends ClientBundle { |
95 | a57faaf0 | Christos Stathis | |
96 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/mimetypes/document.png") |
97 | a57faaf0 | Christos Stathis | ImageResource fileContextMenu(); |
98 | a57faaf0 | Christos Stathis | |
99 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/doc_versions.png") |
100 | a57faaf0 | Christos Stathis | ImageResource versions(); |
101 | a57faaf0 | Christos Stathis | |
102 | 9d8521d7 | Christos Stathis | @Source("gr/grnet/pithos/resources/groups22.png") |
103 | a57faaf0 | Christos Stathis | ImageResource sharing(); |
104 | a57faaf0 | Christos Stathis | |
105 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/border_remove.png") |
106 | a57faaf0 | Christos Stathis | ImageResource unselectAll(); |
107 | a57faaf0 | Christos Stathis | |
108 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/demo.png") |
109 | a57faaf0 | Christos Stathis | ImageResource viewImage(); |
110 | f6445935 | Christos Stathis | |
111 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/folder_new.png") |
112 | f6445935 | Christos Stathis | ImageResource folderNew(); |
113 | f6445935 | Christos Stathis | |
114 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/folder_outbox.png") |
115 | f6445935 | Christos Stathis | ImageResource fileUpdate(); |
116 | f6445935 | Christos Stathis | |
117 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/view_text.png") |
118 | f6445935 | Christos Stathis | ImageResource viewText(); |
119 | f6445935 | Christos Stathis | |
120 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/folder_inbox.png") |
121 | f6445935 | Christos Stathis | ImageResource download(); |
122 | f6445935 | Christos Stathis | |
123 | 9d8521d7 | Christos Stathis | @Source("gr/grnet/pithos/resources/trash.png") |
124 | f6445935 | Christos Stathis | ImageResource emptyTrash(); |
125 | f6445935 | Christos Stathis | |
126 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/refresh.png") |
127 | f6445935 | Christos Stathis | ImageResource refresh(); |
128 | f6445935 | Christos Stathis | |
129 | f6445935 | Christos Stathis | /**
|
130 | f6445935 | Christos Stathis | * Will bundle the file 'editcut.png' residing in the package
|
131 | f6445935 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
132 | f6445935 | Christos Stathis | *
|
133 | f6445935 | Christos Stathis | * @return the image prototype
|
134 | f6445935 | Christos Stathis | */
|
135 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/editcut.png") |
136 | f6445935 | Christos Stathis | ImageResource cut(); |
137 | f6445935 | Christos Stathis | |
138 | f6445935 | Christos Stathis | /**
|
139 | f6445935 | Christos Stathis | * Will bundle the file 'editcopy.png' residing in the package
|
140 | f6445935 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
141 | f6445935 | Christos Stathis | *
|
142 | f6445935 | Christos Stathis | * @return the image prototype
|
143 | f6445935 | Christos Stathis | */
|
144 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/editcopy.png") |
145 | f6445935 | Christos Stathis | ImageResource copy(); |
146 | f6445935 | Christos Stathis | |
147 | f6445935 | Christos Stathis | /**
|
148 | f6445935 | Christos Stathis | * Will bundle the file 'editpaste.png' residing in the package
|
149 | f6445935 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
150 | f6445935 | Christos Stathis | *
|
151 | f6445935 | Christos Stathis | * @return the image prototype
|
152 | f6445935 | Christos Stathis | */
|
153 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/editpaste.png") |
154 | f6445935 | Christos Stathis | ImageResource paste(); |
155 | f6445935 | Christos Stathis | |
156 | f6445935 | Christos Stathis | /**
|
157 | f6445935 | Christos Stathis | * Will bundle the file 'editdelete.png' residing in the package
|
158 | f6445935 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
159 | f6445935 | Christos Stathis | *
|
160 | f6445935 | Christos Stathis | * @return the image prototype
|
161 | f6445935 | Christos Stathis | */
|
162 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/editdelete.png") |
163 | f6445935 | Christos Stathis | ImageResource delete(); |
164 | f6445935 | Christos Stathis | |
165 | f6445935 | Christos Stathis | /**
|
166 | f6445935 | Christos Stathis | * Will bundle the file 'translate.png' residing in the package
|
167 | f6445935 | Christos Stathis | * 'gr.grnet.pithos.web.resources'.
|
168 | f6445935 | Christos Stathis | *
|
169 | f6445935 | Christos Stathis | * @return the image prototype
|
170 | f6445935 | Christos Stathis | */
|
171 | f6445935 | Christos Stathis | @Source("gr/grnet/pithos/resources/translate.png") |
172 | f6445935 | Christos Stathis | ImageResource selectAll(); |
173 | 71875b42 | Christos Stathis | |
174 | 71875b42 | Christos Stathis | @Source("gr/grnet/pithos/resources/internet.png") |
175 | 71875b42 | Christos Stathis | ImageResource internet(); |
176 | f6445935 | Christos Stathis | } |
177 | a57faaf0 | Christos Stathis | |
178 | a57faaf0 | Christos Stathis | public static native String getDate()/*-{ |
179 | a57faaf0 | Christos Stathis | return (new Date()).toUTCString();
|
180 | a57faaf0 | Christos Stathis | }-*/;
|
181 | a57faaf0 | Christos Stathis | |
182 | a57faaf0 | Christos Stathis | /**
|
183 | a57faaf0 | Christos Stathis | * The widget's constructor.
|
184 | a57faaf0 | Christos Stathis | *
|
185 | a57faaf0 | Christos Stathis | * @param newImages the image bundle passed on by the parent object
|
186 | a57faaf0 | Christos Stathis | */
|
187 | 05bb97f8 | Christos Stathis | public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, final List<File> selectedFiles) { |
188 | a57faaf0 | Christos Stathis | // The popup's constructor's argument is a boolean specifying that it
|
189 | a57faaf0 | Christos Stathis | // auto-close itself when the user clicks outside of it.
|
190 | a57faaf0 | Christos Stathis | super(true); |
191 | a57faaf0 | Christos Stathis | setAnimationEnabled(true);
|
192 | a57faaf0 | Christos Stathis | images = newImages; |
193 | 63366925 | Christos Stathis | MenuBar contextMenu = new MenuBar(true); |
194 | 63ee965c | Christos Stathis | Boolean[] permissions = null; |
195 | 63ee965c | Christos Stathis | boolean canWrite = true; |
196 | 63ee965c | Christos Stathis | if (selectedFolder != null) { |
197 | 63ee965c | Christos Stathis | permissions = selectedFolder.getPermissions().get(app.getUsername()); |
198 | 63ee965c | Christos Stathis | canWrite = selectedFolder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]); |
199 | 63ee965c | Christos Stathis | } |
200 | 63ee965c | Christos Stathis | else {
|
201 | 63ee965c | Christos Stathis | for (File f : selectedFiles) { |
202 | 63ee965c | Christos Stathis | permissions = f.getPermissions().get(app.getUsername()); |
203 | 63ee965c | Christos Stathis | canWrite &= (f.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1])); |
204 | 63ee965c | Christos Stathis | } |
205 | 63ee965c | Christos Stathis | } |
206 | 02d3a335 | Christos Stathis | boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
|
207 | 5d18aa82 | Christos Stathis | boolean isMysharedSelected = selectedTree.equals(app.getMySharedTreeView());
|
208 | 02d3a335 | Christos Stathis | if (selectedFolder != null) { |
209 | 02d3a335 | Christos Stathis | if (!selectedFolder.isInTrash()) {
|
210 | 5d18aa82 | Christos Stathis | if (canWrite && app.getClipboard().hasFiles() && !isMysharedSelected) {
|
211 | 43c372e8 | Christos Stathis | pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, selectedFolder)); |
212 | 43c372e8 | Christos Stathis | contextMenu.addItem(pasteItem); |
213 | 02d3a335 | Christos Stathis | } |
214 | 02d3a335 | Christos Stathis | |
215 | 5d18aa82 | Christos Stathis | if (canWrite && !isMysharedSelected) {
|
216 | 02d3a335 | Christos Stathis | MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(app, this, selectedFolder)); |
217 | 02d3a335 | Christos Stathis | contextMenu.addItem(upload); |
218 | 02d3a335 | Christos Stathis | } |
219 | 3586ad5e | Christos Stathis | if (isFolderTreeSelected || isMysharedSelected) {
|
220 | 02d3a335 | Christos Stathis | cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(app, this, selectedFiles)); |
221 | 02d3a335 | Christos Stathis | contextMenu.addItem(cutItem); |
222 | 02d3a335 | Christos Stathis | } |
223 | 02d3a335 | Christos Stathis | |
224 | 3586ad5e | Christos Stathis | copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(app, this, selectedFiles)); |
225 | 3586ad5e | Christos Stathis | contextMenu.addItem(copyItem); |
226 | 02d3a335 | Christos Stathis | |
227 | 3586ad5e | Christos Stathis | if (isFolderTreeSelected || isMysharedSelected) {
|
228 | 02d3a335 | Christos Stathis | trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles)); |
229 | 02d3a335 | Christos Stathis | contextMenu.addItem(trashItem); |
230 | 02d3a335 | Christos Stathis | } |
231 | 02d3a335 | Christos Stathis | } |
232 | 02d3a335 | Christos Stathis | else {
|
233 | 02d3a335 | Christos Stathis | MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles)); |
234 | 02d3a335 | Christos Stathis | contextMenu.addItem(restore); |
235 | 02d3a335 | Christos Stathis | } |
236 | 31477486 | Christos Stathis | } |
237 | 63366925 | Christos Stathis | |
238 | 3586ad5e | Christos Stathis | if (isFolderTreeSelected || isMysharedSelected) {
|
239 | 3ebb88f4 | Christos Stathis | deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images)); |
240 | 3ebb88f4 | Christos Stathis | contextMenu.addItem(deleteItem); |
241 | 3ebb88f4 | Christos Stathis | } |
242 | a57faaf0 | Christos Stathis | |
243 | 02d3a335 | Christos Stathis | if (selectedFolder != null && !selectedFolder.isInTrash()) { |
244 | 5d18aa82 | Christos Stathis | if ((isFolderTreeSelected || isMysharedSelected) && selectedFiles.size() == 1) { |
245 | 9326b841 | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PROPERTIES))); |
246 | 9326b841 | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PERMISSIONS))); |
247 | 71875b42 | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.internet()).getHTML() + " Publish</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PUBLISH))); |
248 | 3586ad5e | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Versions</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.VERSIONS))); |
249 | 9326b841 | Christos Stathis | } |
250 | 63366925 | Christos Stathis | |
251 | 31477486 | Christos Stathis | } |
252 | 05bb97f8 | Christos Stathis | contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() { |
253 | 05bb97f8 | Christos Stathis | |
254 | 05bb97f8 | Christos Stathis | @Override
|
255 | 05bb97f8 | Christos Stathis | public void execute() { |
256 | 05bb97f8 | Christos Stathis | for (File f : selectedFiles) |
257 | 983f9ee2 | Christos Stathis | Window.open(app.getApiPath() + f.getOwner() + f.getUri(), "_blank", ""); |
258 | 05bb97f8 | Christos Stathis | } |
259 | 05bb97f8 | Christos Stathis | })); |
260 | 390f5c04 | Christos Stathis | |
261 | a57faaf0 | Christos Stathis | add(contextMenu); |
262 | a57faaf0 | Christos Stathis | } |
263 | a57faaf0 | Christos Stathis | } |