root / src / gr / grnet / pithos / web / client / FileContextMenu.java @ 8092e326
History | View | Annotate | Download (8.2 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2011 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.RefreshCommand; |
43 |
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand; |
44 |
import gr.grnet.pithos.web.client.commands.ToTrashCommand; |
45 |
import gr.grnet.pithos.web.client.commands.UploadFileCommand; |
46 |
import gr.grnet.pithos.web.client.foldertree.File; |
47 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
48 |
import gr.grnet.pithos.web.client.rest.resource.FileResource; |
49 |
import gr.grnet.pithos.web.client.rest.resource.FolderResource; |
50 |
import gr.grnet.pithos.web.client.rest.resource.RestResource; |
51 |
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; |
52 |
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource; |
53 |
|
54 |
import java.util.List; |
55 |
|
56 |
import com.google.gwt.event.dom.client.ClickEvent; |
57 |
import com.google.gwt.event.dom.client.ClickHandler; |
58 |
import com.google.gwt.event.dom.client.ContextMenuEvent; |
59 |
import com.google.gwt.resources.client.ClientBundle; |
60 |
import com.google.gwt.resources.client.ImageResource; |
61 |
import com.google.gwt.user.client.Command; |
62 |
import com.google.gwt.user.client.Event; |
63 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
64 |
import com.google.gwt.user.client.ui.MenuBar; |
65 |
import com.google.gwt.user.client.ui.MenuItem; |
66 |
import com.google.gwt.user.client.ui.PopupPanel; |
67 |
|
68 |
/**
|
69 |
* The 'File Context' menu implementation.
|
70 |
*/
|
71 |
public class FileContextMenu extends PopupPanel { |
72 |
|
73 |
/**
|
74 |
* The widget's images.
|
75 |
*/
|
76 |
private final Images images; |
77 |
|
78 |
private MenuItem cutItem; |
79 |
|
80 |
private MenuItem copyItem; |
81 |
|
82 |
private MenuItem pasteItem; |
83 |
|
84 |
private MenuItem updateItem; |
85 |
|
86 |
private MenuItem sharingItem; |
87 |
|
88 |
private MenuItem propItem; |
89 |
|
90 |
private MenuItem trashItem; |
91 |
|
92 |
private MenuItem deleteItem; |
93 |
|
94 |
private MenuItem downloadItem; |
95 |
|
96 |
private MenuItem saveAsItem; |
97 |
|
98 |
/**
|
99 |
* The image bundle for this widget's images that reuses images defined in
|
100 |
* other menus.
|
101 |
*/
|
102 |
public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images { |
103 |
|
104 |
@Source("gr/grnet/pithos/resources/mimetypes/document.png") |
105 |
ImageResource fileContextMenu(); |
106 |
|
107 |
@Source("gr/grnet/pithos/resources/doc_versions.png") |
108 |
ImageResource versions(); |
109 |
|
110 |
@Override
|
111 |
@Source("gr/grnet/pithos/resources/group.png") |
112 |
ImageResource sharing(); |
113 |
|
114 |
@Override
|
115 |
@Source("gr/grnet/pithos/resources/border_remove.png") |
116 |
ImageResource unselectAll(); |
117 |
|
118 |
@Source("gr/grnet/pithos/resources/demo.png") |
119 |
ImageResource viewImage(); |
120 |
} |
121 |
|
122 |
public static native String getDate()/*-{ |
123 |
return (new Date()).toUTCString();
|
124 |
}-*/;
|
125 |
|
126 |
/**
|
127 |
* The widget's constructor.
|
128 |
*
|
129 |
* @param newImages the image bundle passed on by the parent object
|
130 |
*/
|
131 |
public FileContextMenu(Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) { |
132 |
// The popup's constructor's argument is a boolean specifying that it
|
133 |
// auto-close itself when the user clicks outside of it.
|
134 |
super(true); |
135 |
GSS gss = GSS.get(); |
136 |
setAnimationEnabled(true);
|
137 |
images = newImages; |
138 |
MenuBar contextMenu = new MenuBar(true); |
139 |
|
140 |
if (GSS.get().getClipboard().hasFiles()) {
|
141 |
pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(GSS.get(), this, selectedFolder)); |
142 |
contextMenu.addItem(pasteItem); |
143 |
} |
144 |
|
145 |
MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this, selectedFolder)); |
146 |
contextMenu.addItem(upload); |
147 |
|
148 |
// MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
|
149 |
// contextMenu.addItem(refresh);
|
150 |
|
151 |
// if (isTrash) {
|
152 |
// MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
|
153 |
// contextMenu.addItem(restore);
|
154 |
//
|
155 |
// MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
|
156 |
// contextMenu.addItem(delete);
|
157 |
// } else {
|
158 |
cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(GSS.get(), this, selectedFiles)); |
159 |
contextMenu.addItem(cutItem); |
160 |
|
161 |
copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(GSS.get(), this, selectedFiles)); |
162 |
contextMenu.addItem(copyItem); |
163 |
|
164 |
trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, selectedFiles)); |
165 |
contextMenu.addItem(trashItem); |
166 |
|
167 |
deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, selectedFiles, images)); |
168 |
contextMenu.addItem(deleteItem); |
169 |
|
170 |
// sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
|
171 |
// contextMenu.addItem(sharingItem);
|
172 |
|
173 |
// propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
|
174 |
// contextMenu.addItem(propItem);
|
175 |
|
176 |
downloadItem = new MenuItem("<span><a class='hidden-link' href='" + GSS.get().getApiPath() + GSS.get().getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + GSS.get().getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, new Command() { |
177 |
@Override
|
178 |
public void execute() { |
179 |
} |
180 |
}); |
181 |
contextMenu.addItem(downloadItem); |
182 |
|
183 |
// final Command unselectAllCommand = new Command() {
|
184 |
//
|
185 |
// @Override
|
186 |
// public void execute() {
|
187 |
// hide();
|
188 |
// if(GSS.get().isFileListShowing())
|
189 |
// GSS.get().getFileList().clearSelectedRows();
|
190 |
// }
|
191 |
// };
|
192 |
// MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand);
|
193 |
// contextMenu.addItem(unSelect);
|
194 |
|
195 |
// }
|
196 |
add(contextMenu); |
197 |
} |
198 |
} |