root / src / gr / grnet / pithos / web / client / FileContextMenu.java @ 28267d27
History | View | Annotate | Download (10.4 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2011-2012 GRNET S.A. All rights reserved.
|
3 |
*
|
4 |
* Redistribution and use in source and binary forms, with or
|
5 |
* without modification, are permitted provided that the following
|
6 |
* conditions are met:
|
7 |
*
|
8 |
* 1. Redistributions of source code must retain the above
|
9 |
* copyright notice, this list of conditions and the following
|
10 |
* disclaimer.
|
11 |
*
|
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.
|
16 |
*
|
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.
|
29 |
*
|
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.
|
34 |
*/
|
35 |
package gr.grnet.pithos.web.client; |
36 |
|
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; |
47 |
|
48 |
import java.util.List; |
49 |
|
50 |
import com.google.gwt.http.client.URL; |
51 |
import com.google.gwt.resources.client.ClientBundle; |
52 |
import com.google.gwt.resources.client.ImageResource; |
53 |
import com.google.gwt.user.client.Command; |
54 |
import com.google.gwt.user.client.Window; |
55 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
56 |
import com.google.gwt.user.client.ui.MenuBar; |
57 |
import com.google.gwt.user.client.ui.MenuItem; |
58 |
import com.google.gwt.user.client.ui.PopupPanel; |
59 |
|
60 |
/**
|
61 |
* The 'File Context' menu implementation.
|
62 |
*/
|
63 |
public class FileContextMenu extends PopupPanel { |
64 |
|
65 |
/**
|
66 |
* The widget's images.
|
67 |
*/
|
68 |
private final Images images; |
69 |
|
70 |
private MenuItem cutItem; |
71 |
|
72 |
private MenuItem copyItem; |
73 |
|
74 |
private MenuItem pasteItem; |
75 |
|
76 |
private MenuItem updateItem; |
77 |
|
78 |
private MenuItem sharingItem; |
79 |
|
80 |
private MenuItem propItem; |
81 |
|
82 |
private MenuItem trashItem; |
83 |
|
84 |
private MenuItem deleteItem; |
85 |
|
86 |
private MenuItem downloadItem; |
87 |
|
88 |
private MenuItem saveAsItem; |
89 |
|
90 |
/**
|
91 |
* The image bundle for this widget's images that reuses images defined in
|
92 |
* other menus.
|
93 |
*/
|
94 |
public interface Images extends ClientBundle { |
95 |
|
96 |
@Source("gr/grnet/pithos/resources/mimetypes/document.png") |
97 |
ImageResource fileContextMenu(); |
98 |
|
99 |
@Source("gr/grnet/pithos/resources/doc_versions.png") |
100 |
ImageResource versions(); |
101 |
|
102 |
@Source("gr/grnet/pithos/resources/groups22.png") |
103 |
ImageResource sharing(); |
104 |
|
105 |
@Source("gr/grnet/pithos/resources/border_remove.png") |
106 |
ImageResource unselectAll(); |
107 |
|
108 |
@Source("gr/grnet/pithos/resources/demo.png") |
109 |
ImageResource viewImage(); |
110 |
|
111 |
@Source("gr/grnet/pithos/resources/folder_new.png") |
112 |
ImageResource folderNew(); |
113 |
|
114 |
@Source("gr/grnet/pithos/resources/folder_outbox.png") |
115 |
ImageResource fileUpdate(); |
116 |
|
117 |
@Source("gr/grnet/pithos/resources/view_text.png") |
118 |
ImageResource viewText(); |
119 |
|
120 |
@Source("gr/grnet/pithos/resources/folder_inbox.png") |
121 |
ImageResource download(); |
122 |
|
123 |
@Source("gr/grnet/pithos/resources/trash.png") |
124 |
ImageResource emptyTrash(); |
125 |
|
126 |
@Source("gr/grnet/pithos/resources/refresh.png") |
127 |
ImageResource refresh(); |
128 |
|
129 |
/**
|
130 |
* Will bundle the file 'editcut.png' residing in the package
|
131 |
* 'gr.grnet.pithos.web.resources'.
|
132 |
*
|
133 |
* @return the image prototype
|
134 |
*/
|
135 |
@Source("gr/grnet/pithos/resources/editcut.png") |
136 |
ImageResource cut(); |
137 |
|
138 |
/**
|
139 |
* Will bundle the file 'editcopy.png' residing in the package
|
140 |
* 'gr.grnet.pithos.web.resources'.
|
141 |
*
|
142 |
* @return the image prototype
|
143 |
*/
|
144 |
@Source("gr/grnet/pithos/resources/editcopy.png") |
145 |
ImageResource copy(); |
146 |
|
147 |
/**
|
148 |
* Will bundle the file 'editpaste.png' residing in the package
|
149 |
* 'gr.grnet.pithos.web.resources'.
|
150 |
*
|
151 |
* @return the image prototype
|
152 |
*/
|
153 |
@Source("gr/grnet/pithos/resources/editpaste.png") |
154 |
ImageResource paste(); |
155 |
|
156 |
/**
|
157 |
* Will bundle the file 'editdelete.png' residing in the package
|
158 |
* 'gr.grnet.pithos.web.resources'.
|
159 |
*
|
160 |
* @return the image prototype
|
161 |
*/
|
162 |
@Source("gr/grnet/pithos/resources/editdelete.png") |
163 |
ImageResource delete(); |
164 |
|
165 |
/**
|
166 |
* Will bundle the file 'translate.png' residing in the package
|
167 |
* 'gr.grnet.pithos.web.resources'.
|
168 |
*
|
169 |
* @return the image prototype
|
170 |
*/
|
171 |
@Source("gr/grnet/pithos/resources/translate.png") |
172 |
ImageResource selectAll(); |
173 |
|
174 |
@Source("gr/grnet/pithos/resources/internet.png") |
175 |
ImageResource internet(); |
176 |
} |
177 |
|
178 |
public static native String getDate()/*-{ |
179 |
return (new Date()).toUTCString();
|
180 |
}-*/;
|
181 |
|
182 |
/**
|
183 |
* The widget's constructor.
|
184 |
*
|
185 |
* @param newImages the image bundle passed on by the parent object
|
186 |
*/
|
187 |
public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, final List<File> selectedFiles) { |
188 |
// The popup's constructor's argument is a boolean specifying that it
|
189 |
// auto-close itself when the user clicks outside of it.
|
190 |
super(true); |
191 |
images = newImages; |
192 |
MenuBar contextMenu = new MenuBar(true); |
193 |
Boolean[] permissions = null; |
194 |
boolean canWrite = true; |
195 |
if (selectedFolder != null) { |
196 |
permissions = selectedFolder.getPermissions().get(app.getUsername()); |
197 |
canWrite = selectedFolder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]); |
198 |
} |
199 |
else {
|
200 |
for (File f : selectedFiles) { |
201 |
permissions = f.getPermissions().get(app.getUsername()); |
202 |
canWrite &= (f.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1])); |
203 |
} |
204 |
} |
205 |
boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
|
206 |
boolean isMysharedSelected = selectedTree.equals(app.getMySharedTreeView());
|
207 |
if (selectedFolder != null) { |
208 |
if (!selectedFolder.isInTrash()) {
|
209 |
if (canWrite && app.getClipboard().hasFiles() && !isMysharedSelected) {
|
210 |
pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, selectedFolder)); |
211 |
contextMenu.addItem(pasteItem); |
212 |
} |
213 |
|
214 |
if (canWrite && !isMysharedSelected) {
|
215 |
MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(app, this, selectedFolder)); |
216 |
contextMenu.addItem(upload); |
217 |
} |
218 |
if (isFolderTreeSelected || isMysharedSelected) {
|
219 |
cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(app, this, selectedFiles)); |
220 |
contextMenu.addItem(cutItem); |
221 |
} |
222 |
|
223 |
copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(app, this, selectedFiles)); |
224 |
contextMenu.addItem(copyItem); |
225 |
|
226 |
if (isFolderTreeSelected || isMysharedSelected) {
|
227 |
trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles)); |
228 |
contextMenu.addItem(trashItem); |
229 |
} |
230 |
} |
231 |
else {
|
232 |
MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles)); |
233 |
contextMenu.addItem(restore); |
234 |
} |
235 |
} |
236 |
|
237 |
if (isFolderTreeSelected || isMysharedSelected) {
|
238 |
deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images)); |
239 |
contextMenu.addItem(deleteItem); |
240 |
} |
241 |
|
242 |
if (selectedFolder != null && !selectedFolder.isInTrash()) { |
243 |
if ((isFolderTreeSelected || isMysharedSelected) && selectedFiles.size() == 1) { |
244 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PROPERTIES))); |
245 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PERMISSIONS))); |
246 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.internet()).getHTML() + " Publish</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PUBLISH))); |
247 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Versions</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.VERSIONS))); |
248 |
} |
249 |
|
250 |
} |
251 |
contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() { |
252 |
|
253 |
@Override
|
254 |
public void execute() { |
255 |
for (File f : selectedFiles) |
256 |
Window.open(app.getApiPath() + f.getOwner() + f.getUri(), "_blank", ""); |
257 |
} |
258 |
})); |
259 |
|
260 |
add(contextMenu); |
261 |
} |
262 |
} |