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