root / src / gr / ebs / gss / client / FileContextMenu.java @ 023f6f1e
History | View | Annotate | Download (12.5 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
6 |
* GSS is free software: you can redistribute it and/or modify
|
7 |
* it under the terms of the GNU General Public License as published by
|
8 |
* the Free Software Foundation, either version 3 of the License, or
|
9 |
* (at your option) any later version.
|
10 |
*
|
11 |
* GSS is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.client; |
20 |
|
21 |
import gr.ebs.gss.client.commands.CopyCommand; |
22 |
import gr.ebs.gss.client.commands.CutCommand; |
23 |
import gr.ebs.gss.client.commands.DeleteCommand; |
24 |
import gr.ebs.gss.client.commands.PasteCommand; |
25 |
import gr.ebs.gss.client.commands.PropertiesCommand; |
26 |
import gr.ebs.gss.client.commands.RefreshCommand; |
27 |
import gr.ebs.gss.client.commands.RestoreTrashCommand; |
28 |
import gr.ebs.gss.client.commands.ToTrashCommand; |
29 |
import gr.ebs.gss.client.commands.UploadFileCommand; |
30 |
import gr.ebs.gss.client.dnd.DnDTreeItem; |
31 |
import gr.ebs.gss.client.rest.resource.FileResource; |
32 |
import gr.ebs.gss.client.rest.resource.FolderResource; |
33 |
|
34 |
import java.util.List; |
35 |
|
36 |
import com.google.gwt.event.dom.client.ClickEvent; |
37 |
import com.google.gwt.event.dom.client.ClickHandler; |
38 |
import com.google.gwt.event.dom.client.ContextMenuEvent; |
39 |
import com.google.gwt.resources.client.ClientBundle; |
40 |
import com.google.gwt.resources.client.ImageResource; |
41 |
import com.google.gwt.user.client.Command; |
42 |
import com.google.gwt.user.client.Event; |
43 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
44 |
import com.google.gwt.user.client.ui.MenuBar; |
45 |
import com.google.gwt.user.client.ui.MenuItem; |
46 |
import com.google.gwt.user.client.ui.PopupPanel; |
47 |
import com.google.gwt.user.client.ui.TreeItem; |
48 |
|
49 |
/**
|
50 |
* The 'File Context' menu implementation.
|
51 |
*/
|
52 |
public class FileContextMenu extends PopupPanel implements ClickHandler { |
53 |
|
54 |
/**
|
55 |
* The widget's images.
|
56 |
*/
|
57 |
private final Images images; |
58 |
|
59 |
private MenuItem cutItem; |
60 |
|
61 |
private MenuItem copyItem; |
62 |
|
63 |
private MenuItem pasteItem; |
64 |
|
65 |
private MenuItem updateItem; |
66 |
|
67 |
private MenuItem sharingItem; |
68 |
|
69 |
private MenuItem propItem; |
70 |
|
71 |
private MenuItem trashItem; |
72 |
|
73 |
private MenuItem deleteItem; |
74 |
|
75 |
private MenuItem downloadItem; |
76 |
|
77 |
private MenuItem saveAsItem; |
78 |
|
79 |
/**
|
80 |
* The image bundle for this widget's images that reuses images defined in
|
81 |
* other menus.
|
82 |
*/
|
83 |
public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images { |
84 |
|
85 |
@Source("gr/ebs/gss/resources/mimetypes/document.png") |
86 |
ImageResource fileContextMenu(); |
87 |
|
88 |
@Source("gr/ebs/gss/resources/doc_versions.png") |
89 |
ImageResource versions(); |
90 |
|
91 |
@Override
|
92 |
@Source("gr/ebs/gss/resources/group.png") |
93 |
ImageResource sharing(); |
94 |
|
95 |
@Override
|
96 |
@Source("gr/ebs/gss/resources/border_remove.png") |
97 |
ImageResource unselectAll(); |
98 |
|
99 |
@Source("gr/ebs/gss/resources/demo.png") |
100 |
ImageResource viewImage(); |
101 |
} |
102 |
|
103 |
public static native String getDate()/*-{ |
104 |
return (new Date()).toUTCString();
|
105 |
}-*/;
|
106 |
|
107 |
/**
|
108 |
* The widget's constructor.
|
109 |
*
|
110 |
* @param newImages the image bundle passed on by the parent object
|
111 |
*/
|
112 |
public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) { |
113 |
// The popup's constructor's argument is a boolean specifying that it
|
114 |
// auto-close itself when the user clicks outside of it.
|
115 |
super(true); |
116 |
GSS gss = GSS.get(); |
117 |
setAnimationEnabled(true);
|
118 |
images = newImages; |
119 |
|
120 |
// The command that does some validation before downloading a file.
|
121 |
Command downloadCmd = new Command() {
|
122 |
|
123 |
@Override
|
124 |
public void execute() { |
125 |
hide(); |
126 |
GSS.get().getTopPanel().getFileMenu().preDownloadCheck(); |
127 |
} |
128 |
}; |
129 |
|
130 |
pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this)); |
131 |
|
132 |
MenuBar contextMenu = new MenuBar(true); |
133 |
if (isEmpty) {
|
134 |
contextMenu.addItem(pasteItem); |
135 |
if (GSS.get().getFolders().getCurrent() != null) |
136 |
if (GSS.get().getFolders().isFileItem(GSS.get().getFolders().getCurrent()))
|
137 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
138 |
else if (GSS.get().getFolders().isMySharedItem(GSS.get().getFolders().getCurrent()) || GSS .get() |
139 |
.getFolders() |
140 |
.isOthersSharedItem(GSS .get() |
141 |
.getFolders() |
142 |
.getCurrent())) |
143 |
if(GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource) |
144 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
145 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
146 |
} else if (isTrash) { |
147 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this)); |
148 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
149 |
} else {
|
150 |
final Command unselectAllCommand = new Command() { |
151 |
|
152 |
@Override
|
153 |
public void execute() { |
154 |
hide(); |
155 |
if(GSS.get().isFileListShowing())
|
156 |
GSS.get().getFileList().clearSelectedRows(); |
157 |
else if(GSS.get().isSearchResultsShowing()) |
158 |
GSS.get().getSearchResults().clearSelectedRows(); |
159 |
} |
160 |
}; |
161 |
cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this)); |
162 |
copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this)); |
163 |
|
164 |
updateItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
165 |
|
166 |
trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this)); |
167 |
deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images)); |
168 |
|
169 |
sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1)); |
170 |
propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0)); |
171 |
|
172 |
TreeItem currentFolder = gss.getFolders().getCurrent(); |
173 |
if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource) |
174 |
contextMenu.addItem(updateItem); |
175 |
String[] link = {"", ""}; |
176 |
gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
|
177 |
downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd); |
178 |
contextMenu.addItem(downloadItem); |
179 |
gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
|
180 |
saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd); |
181 |
contextMenu.addItem(saveAsItem); |
182 |
contextMenu.addItem(cutItem); |
183 |
contextMenu.addItem(copyItem); |
184 |
if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource) |
185 |
contextMenu.addItem(pasteItem); |
186 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand); |
187 |
contextMenu.addItem(trashItem); |
188 |
contextMenu.addItem(deleteItem); |
189 |
contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
190 |
contextMenu.addItem(sharingItem); |
191 |
contextMenu.addItem(propItem); |
192 |
} |
193 |
add(contextMenu); |
194 |
if (gss.getClipboard().hasFileItem())
|
195 |
pasteItem.setVisible(true);
|
196 |
else
|
197 |
pasteItem.setVisible(false);
|
198 |
} |
199 |
|
200 |
void onMultipleSelection() {
|
201 |
updateItem.setVisible(false);
|
202 |
downloadItem.setVisible(false);
|
203 |
saveAsItem.setVisible(false);
|
204 |
sharingItem.setVisible(false);
|
205 |
} |
206 |
@Override
|
207 |
public void onClick(ClickEvent event) { |
208 |
if (GSS.get().getCurrentSelection() != null) |
209 |
if (GSS.get().getCurrentSelection() instanceof FileResource) { |
210 |
FileResource res = (FileResource) GSS.get().getCurrentSelection(); |
211 |
FileContextMenu menu; |
212 |
if (res.isDeleted())
|
213 |
menu = new FileContextMenu(images, true, false); |
214 |
else
|
215 |
menu = new FileContextMenu(images, false, false); |
216 |
int left = event.getRelativeElement().getAbsoluteLeft();
|
217 |
int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
|
218 |
menu.setPopupPosition(left, top); |
219 |
menu.show(); |
220 |
} else if (GSS.get().getCurrentSelection() instanceof List) { |
221 |
FileContextMenu menu; |
222 |
if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
|
223 |
menu = new FileContextMenu(images, true, false); |
224 |
else {
|
225 |
menu = new FileContextMenu(images, false, false); |
226 |
menu.onMultipleSelection(); |
227 |
} |
228 |
int left = event.getRelativeElement().getAbsoluteLeft();
|
229 |
int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
|
230 |
menu.setPopupPosition(left, top); |
231 |
menu.show(); |
232 |
} |
233 |
} |
234 |
|
235 |
public void onEvent(Event event) { |
236 |
if (GSS.get().getCurrentSelection() != null) |
237 |
if (GSS.get().getCurrentSelection() instanceof FileResource) { |
238 |
FileResource res = (FileResource) GSS.get().getCurrentSelection(); |
239 |
FileContextMenu menu; |
240 |
if (res.isDeleted())
|
241 |
menu = new FileContextMenu(images, true, false); |
242 |
else
|
243 |
menu = new FileContextMenu(images, false, false); |
244 |
int left = event.getClientX();
|
245 |
int top = event.getClientY();
|
246 |
menu.setPopupPosition(left, top); |
247 |
menu.show(); |
248 |
} else if (GSS.get().getCurrentSelection() instanceof List) { |
249 |
FileContextMenu menu; |
250 |
if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
|
251 |
menu = new FileContextMenu(images, true, false); |
252 |
else {
|
253 |
menu = new FileContextMenu(images, false, false); |
254 |
menu.onMultipleSelection(); |
255 |
} |
256 |
int left = event.getClientX();
|
257 |
int top = event.getClientY();
|
258 |
menu.setPopupPosition(left, top); |
259 |
menu.show(); |
260 |
} |
261 |
} |
262 |
|
263 |
public void onContextEvent(ContextMenuEvent event) { |
264 |
if (GSS.get().getCurrentSelection() != null) |
265 |
if (GSS.get().getCurrentSelection() instanceof FileResource) { |
266 |
FileResource res = (FileResource) GSS.get().getCurrentSelection(); |
267 |
FileContextMenu menu; |
268 |
if (res.isDeleted())
|
269 |
menu = new FileContextMenu(images, true, false); |
270 |
else
|
271 |
menu = new FileContextMenu(images, false, false); |
272 |
int left = event.getNativeEvent().getClientX();
|
273 |
int top = event.getNativeEvent().getClientY();
|
274 |
menu.setPopupPosition(left, top); |
275 |
menu.show(); |
276 |
|
277 |
} else if (GSS.get().getCurrentSelection() instanceof List) { |
278 |
FileContextMenu menu; |
279 |
if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
|
280 |
menu = new FileContextMenu(images, true, false); |
281 |
else {
|
282 |
menu = new FileContextMenu(images, false, false); |
283 |
menu.onMultipleSelection(); |
284 |
} |
285 |
int left = event.getNativeEvent().getClientX();
|
286 |
int top = event.getNativeEvent().getClientY();
|
287 |
menu.setPopupPosition(left, top); |
288 |
menu.show(); |
289 |
} |
290 |
} |
291 |
|
292 |
public void onContextEmptyEvent(ContextMenuEvent event) { |
293 |
FileContextMenu menu; |
294 |
if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
|
295 |
menu = new FileContextMenu(images, true, true); |
296 |
else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null) |
297 |
menu = new FileContextMenu(images, false, true); |
298 |
else return; |
299 |
int left = event.getNativeEvent().getClientX();
|
300 |
int top = event.getNativeEvent().getClientY();
|
301 |
menu.setPopupPosition(left, top); |
302 |
menu.show(); |
303 |
} |
304 |
|
305 |
public void onEmptyEvent(Event event) { |
306 |
FileContextMenu menu; |
307 |
if (GSS.get().getFolders().isTrashItem(GSS.get().getFolders().getCurrent()))
|
308 |
menu = new FileContextMenu(images, true, true); |
309 |
else if(((DnDTreeItem)GSS.get().getFolders().getCurrent()).getFolderResource() != null) |
310 |
menu = new FileContextMenu(images, false, true); |
311 |
else return; |
312 |
int left = event.getClientX();
|
313 |
int top = event.getClientY();
|
314 |
menu.setPopupPosition(left, top); |
315 |
menu.show(); |
316 |
} |
317 |
|
318 |
|
319 |
} |