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