root / src / gr / ebs / gss / client / FileMenu.java @ 11a5a55d
History | View | Annotate | Download (9.2 kB)
1 | 023f6f1e | Panagiotis Astithas | /*
|
---|---|---|---|
2 | 023f6f1e | Panagiotis Astithas | * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
|
3 | 023f6f1e | Panagiotis Astithas | *
|
4 | 023f6f1e | Panagiotis Astithas | * This file is part of GSS.
|
5 | 023f6f1e | Panagiotis Astithas | *
|
6 | 023f6f1e | Panagiotis Astithas | * GSS is free software: you can redistribute it and/or modify
|
7 | 023f6f1e | Panagiotis Astithas | * it under the terms of the GNU General Public License as published by
|
8 | 023f6f1e | Panagiotis Astithas | * the Free Software Foundation, either version 3 of the License, or
|
9 | 023f6f1e | Panagiotis Astithas | * (at your option) any later version.
|
10 | 023f6f1e | Panagiotis Astithas | *
|
11 | 023f6f1e | Panagiotis Astithas | * GSS is distributed in the hope that it will be useful,
|
12 | 023f6f1e | Panagiotis Astithas | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 023f6f1e | Panagiotis Astithas | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 023f6f1e | Panagiotis Astithas | * GNU General Public License for more details.
|
15 | 023f6f1e | Panagiotis Astithas | *
|
16 | 023f6f1e | Panagiotis Astithas | * You should have received a copy of the GNU General Public License
|
17 | 023f6f1e | Panagiotis Astithas | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 023f6f1e | Panagiotis Astithas | */
|
19 | 023f6f1e | Panagiotis Astithas | package gr.ebs.gss.client; |
20 | 023f6f1e | Panagiotis Astithas | |
21 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.commands.EmptyTrashCommand; |
22 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.commands.NewFolderCommand; |
23 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.commands.PropertiesCommand; |
24 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.commands.RefreshCommand; |
25 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.commands.UploadFileCommand; |
26 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.RestCommand; |
27 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.resource.FileResource; |
28 | 023f6f1e | Panagiotis Astithas | import gr.ebs.gss.client.rest.resource.GroupUserResource; |
29 | 11a5a55d | koutsoub | import gr.ebs.gss.client.rest.resource.OtherUserResource; |
30 | 11a5a55d | koutsoub | import gr.ebs.gss.client.rest.resource.OthersResource; |
31 | 5b09ea6c | koutsoub | import gr.ebs.gss.client.rest.resource.RestResource; |
32 | 11a5a55d | koutsoub | import gr.ebs.gss.client.rest.resource.SharedResource; |
33 | 11a5a55d | koutsoub | import gr.ebs.gss.client.rest.resource.TrashFolderResource; |
34 | 11a5a55d | koutsoub | import gr.ebs.gss.client.rest.resource.TrashResource; |
35 | 023f6f1e | Panagiotis Astithas | |
36 | 023f6f1e | Panagiotis Astithas | import java.util.List; |
37 | 023f6f1e | Panagiotis Astithas | |
38 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.event.dom.client.ClickEvent; |
39 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.event.dom.client.ClickHandler; |
40 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.http.client.URL; |
41 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.resources.client.ClientBundle; |
42 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.resources.client.ImageResource; |
43 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.Command; |
44 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
45 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.MenuBar; |
46 | 114a597f | Natasa Kapravelou | import com.google.gwt.user.client.ui.MenuItem; |
47 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.PopupPanel; |
48 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.TreeItem; |
49 | 023f6f1e | Panagiotis Astithas | |
50 | 023f6f1e | Panagiotis Astithas | /**
|
51 | 023f6f1e | Panagiotis Astithas | * The 'File' menu implementation.
|
52 | 023f6f1e | Panagiotis Astithas | */
|
53 | 023f6f1e | Panagiotis Astithas | public class FileMenu extends PopupPanel implements ClickHandler { |
54 | 023f6f1e | Panagiotis Astithas | |
55 | 023f6f1e | Panagiotis Astithas | /**
|
56 | 023f6f1e | Panagiotis Astithas | * The widget's images.
|
57 | 023f6f1e | Panagiotis Astithas | */
|
58 | 023f6f1e | Panagiotis Astithas | private final Images images; |
59 | 023f6f1e | Panagiotis Astithas | |
60 | 023f6f1e | Panagiotis Astithas | /**
|
61 | 023f6f1e | Panagiotis Astithas | * An image bundle for this widgets images.
|
62 | 023f6f1e | Panagiotis Astithas | */
|
63 | 023f6f1e | Panagiotis Astithas | public interface Images extends ClientBundle,FilePropertiesDialog.Images { |
64 | 023f6f1e | Panagiotis Astithas | |
65 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/folder_new.png") |
66 | 023f6f1e | Panagiotis Astithas | ImageResource folderNew(); |
67 | 023f6f1e | Panagiotis Astithas | |
68 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/folder_outbox.png") |
69 | 023f6f1e | Panagiotis Astithas | ImageResource fileUpdate(); |
70 | 023f6f1e | Panagiotis Astithas | |
71 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/view_text.png") |
72 | 023f6f1e | Panagiotis Astithas | ImageResource viewText(); |
73 | 023f6f1e | Panagiotis Astithas | |
74 | 023f6f1e | Panagiotis Astithas | @Override
|
75 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/folder_inbox.png") |
76 | 023f6f1e | Panagiotis Astithas | ImageResource download(); |
77 | 023f6f1e | Panagiotis Astithas | |
78 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/trashcan_empty.png") |
79 | 023f6f1e | Panagiotis Astithas | ImageResource emptyTrash(); |
80 | 023f6f1e | Panagiotis Astithas | |
81 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/internet.png") |
82 | 023f6f1e | Panagiotis Astithas | ImageResource sharing(); |
83 | 023f6f1e | Panagiotis Astithas | |
84 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/refresh.png") |
85 | 023f6f1e | Panagiotis Astithas | ImageResource refresh(); |
86 | 023f6f1e | Panagiotis Astithas | } |
87 | 023f6f1e | Panagiotis Astithas | |
88 | 023f6f1e | Panagiotis Astithas | final MenuBar contextMenu = new MenuBar(true); |
89 | 023f6f1e | Panagiotis Astithas | |
90 | 023f6f1e | Panagiotis Astithas | /**
|
91 | 023f6f1e | Panagiotis Astithas | * The widget's constructor.
|
92 | 023f6f1e | Panagiotis Astithas | *
|
93 | 023f6f1e | Panagiotis Astithas | * @param _images the image bundle passed on by the parent object
|
94 | 023f6f1e | Panagiotis Astithas | */
|
95 | 023f6f1e | Panagiotis Astithas | public FileMenu(final Images _images) { |
96 | 023f6f1e | Panagiotis Astithas | // The popup's constructor's argument is a boolean specifying that it
|
97 | 023f6f1e | Panagiotis Astithas | // auto-close itself when the user clicks outside of it.
|
98 | 023f6f1e | Panagiotis Astithas | super(true); |
99 | 023f6f1e | Panagiotis Astithas | setAnimationEnabled(true);
|
100 | 023f6f1e | Panagiotis Astithas | images = _images; |
101 | 023f6f1e | Panagiotis Astithas | add(contextMenu); |
102 | 023f6f1e | Panagiotis Astithas | |
103 | 023f6f1e | Panagiotis Astithas | } |
104 | 023f6f1e | Panagiotis Astithas | |
105 | 023f6f1e | Panagiotis Astithas | @Override
|
106 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
107 | 023f6f1e | Panagiotis Astithas | final FileMenu menu = new FileMenu(images); |
108 | 023f6f1e | Panagiotis Astithas | final int left = event.getRelativeElement().getAbsoluteLeft(); |
109 | 023f6f1e | Panagiotis Astithas | final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); |
110 | 023f6f1e | Panagiotis Astithas | menu.setPopupPosition(left, top); |
111 | 023f6f1e | Panagiotis Astithas | menu.show(); |
112 | 023f6f1e | Panagiotis Astithas | |
113 | 023f6f1e | Panagiotis Astithas | } |
114 | 023f6f1e | Panagiotis Astithas | |
115 | 023f6f1e | Panagiotis Astithas | |
116 | 023f6f1e | Panagiotis Astithas | /**
|
117 | 023f6f1e | Panagiotis Astithas | * Do some validation before downloading a file.
|
118 | 023f6f1e | Panagiotis Astithas | */
|
119 | 023f6f1e | Panagiotis Astithas | void preDownloadCheck() {
|
120 | 023f6f1e | Panagiotis Astithas | Object selection = GSS.get().getCurrentSelection();
|
121 | 023f6f1e | Panagiotis Astithas | if (selection == null || !(selection instanceof FileResource)) { |
122 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("You have to select a file first");
|
123 | 023f6f1e | Panagiotis Astithas | return;
|
124 | 023f6f1e | Panagiotis Astithas | } |
125 | 023f6f1e | Panagiotis Astithas | } |
126 | 023f6f1e | Panagiotis Astithas | |
127 | 023f6f1e | Panagiotis Astithas | /**
|
128 | 023f6f1e | Panagiotis Astithas | * Create a download link for the respective menu item, if the currently
|
129 | 023f6f1e | Panagiotis Astithas | * selected object is a file.
|
130 | 023f6f1e | Panagiotis Astithas | *
|
131 | 023f6f1e | Panagiotis Astithas | * @param link a String array with two elements that is modified so that the
|
132 | 023f6f1e | Panagiotis Astithas | * first position contains the opening tag and the second one the
|
133 | 023f6f1e | Panagiotis Astithas | * closing tag
|
134 | 023f6f1e | Panagiotis Astithas | * @param forceDownload If true, link will be such that browser should ask for filename
|
135 | 023f6f1e | Panagiotis Astithas | * and save location
|
136 | 023f6f1e | Panagiotis Astithas | */
|
137 | 023f6f1e | Panagiotis Astithas | void createDownloadLink(String[] link, boolean forceDownload) { |
138 | 023f6f1e | Panagiotis Astithas | String downloadURL = getDownloadURL();
|
139 | 023f6f1e | Panagiotis Astithas | if (!downloadURL.isEmpty()) {
|
140 | 023f6f1e | Panagiotis Astithas | link[0] = "<a class='hidden-link' href='" + downloadURL |
141 | 023f6f1e | Panagiotis Astithas | + (forceDownload ? "&dl=1" : "") + "' target='_blank'>"; |
142 | 023f6f1e | Panagiotis Astithas | link[1] = "</a>"; |
143 | 023f6f1e | Panagiotis Astithas | } |
144 | 023f6f1e | Panagiotis Astithas | } |
145 | 023f6f1e | Panagiotis Astithas | |
146 | 023f6f1e | Panagiotis Astithas | public String getDownloadURL() { |
147 | 023f6f1e | Panagiotis Astithas | GSS app = GSS.get(); |
148 | 023f6f1e | Panagiotis Astithas | Object selection = app.getCurrentSelection();
|
149 | 023f6f1e | Panagiotis Astithas | if (selection != null && selection instanceof FileResource) { |
150 | 023f6f1e | Panagiotis Astithas | FileResource file = (FileResource) selection; |
151 | 023f6f1e | Panagiotis Astithas | return getDownloadURL(file);
|
152 | 023f6f1e | Panagiotis Astithas | } |
153 | 023f6f1e | Panagiotis Astithas | return ""; |
154 | 023f6f1e | Panagiotis Astithas | } |
155 | 023f6f1e | Panagiotis Astithas | |
156 | 023f6f1e | Panagiotis Astithas | public String getDownloadURL(FileResource file) { |
157 | 023f6f1e | Panagiotis Astithas | GSS app = GSS.get(); |
158 | 023f6f1e | Panagiotis Astithas | if (file != null) { |
159 | 023f6f1e | Panagiotis Astithas | String dateString = RestCommand.getDate();
|
160 | 023f6f1e | Panagiotis Astithas | String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length()); |
161 | 023f6f1e | Panagiotis Astithas | String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken())); |
162 | 023f6f1e | Panagiotis Astithas | return file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString); |
163 | 023f6f1e | Panagiotis Astithas | } |
164 | 023f6f1e | Panagiotis Astithas | return ""; |
165 | 023f6f1e | Panagiotis Astithas | } |
166 | 023f6f1e | Panagiotis Astithas | |
167 | 023f6f1e | Panagiotis Astithas | public MenuBar createMenu() { |
168 | 023f6f1e | Panagiotis Astithas | contextMenu.clearItems(); |
169 | 023f6f1e | Panagiotis Astithas | contextMenu.setAutoOpen(false);
|
170 | 023f6f1e | Panagiotis Astithas | final Command downloadCmd = new Command() { |
171 | 023f6f1e | Panagiotis Astithas | |
172 | 023f6f1e | Panagiotis Astithas | @Override
|
173 | 023f6f1e | Panagiotis Astithas | public void execute() { |
174 | 023f6f1e | Panagiotis Astithas | hide(); |
175 | 023f6f1e | Panagiotis Astithas | preDownloadCheck(); |
176 | 023f6f1e | Panagiotis Astithas | } |
177 | 023f6f1e | Panagiotis Astithas | }; |
178 | 11a5a55d | koutsoub | //
|
179 | 5b09ea6c | koutsoub | RestResource selectedItem = GSS.get().getTreeView().getSelection(); |
180 | 11a5a55d | koutsoub | boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource; |
181 | 11a5a55d | koutsoub | boolean propertiesVisible = !(selectedItem != null && (selectedItem instanceof TrashResource || selectedItem instanceof TrashFolderResource || selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource |
182 | 11a5a55d | koutsoub | //|| folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource
|
183 | 11a5a55d | koutsoub | || GSS.get().getCurrentSelection() instanceof List)); |
184 | 11a5a55d | koutsoub | boolean newFolderVisible = !(selectedItem != null && (selectedItem instanceof TrashResource || selectedItem instanceof TrashFolderResource || selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource)); |
185 | 11a5a55d | koutsoub | boolean uploadVisible = !(selectedItem != null && (selectedItem instanceof TrashResource || selectedItem instanceof TrashFolderResource || selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource)); |
186 | 114a597f | Natasa Kapravelou | if(newFolderVisible){
|
187 | 114a597f | Natasa Kapravelou | MenuItem newFolderItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
188 | 114a597f | Natasa Kapravelou | newFolderItem.getElement().setId("topMenu.file.newFolder");
|
189 | 114a597f | Natasa Kapravelou | contextMenu.addItem(newFolderItem); |
190 | 114a597f | Natasa Kapravelou | } |
191 | 114a597f | Natasa Kapravelou | if(uploadVisible){
|
192 | 114a597f | Natasa Kapravelou | MenuItem uploadItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
193 | 114a597f | Natasa Kapravelou | uploadItem.getElement().setId("topMenu.file.upload");
|
194 | 114a597f | Natasa Kapravelou | contextMenu.addItem(uploadItem); |
195 | 114a597f | Natasa Kapravelou | } |
196 | 023f6f1e | Panagiotis Astithas | if (downloadVisible) {
|
197 | 023f6f1e | Panagiotis Astithas | String[] link = {"", ""}; |
198 | 023f6f1e | Panagiotis Astithas | createDownloadLink(link, false);
|
199 | 114a597f | Natasa Kapravelou | |
200 | 114a597f | Natasa Kapravelou | MenuItem downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd); |
201 | 114a597f | Natasa Kapravelou | contextMenu.addItem(downloadItem); |
202 | 114a597f | Natasa Kapravelou | downloadItem.getElement().setId("topMenu.file.download");
|
203 | 114a597f | Natasa Kapravelou | |
204 | 023f6f1e | Panagiotis Astithas | createDownloadLink(link, true);
|
205 | 114a597f | Natasa Kapravelou | |
206 | 114a597f | Natasa Kapravelou | MenuItem saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd); |
207 | 114a597f | Natasa Kapravelou | saveAsItem.getElement().setId("topMenu.file.saveAs");
|
208 | 114a597f | Natasa Kapravelou | contextMenu.addItem(saveAsItem); |
209 | 023f6f1e | Panagiotis Astithas | } |
210 | 114a597f | Natasa Kapravelou | MenuItem emptyTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this)); |
211 | 114a597f | Natasa Kapravelou | emptyTrashItem.getElement().setId("topMenu.file.emptyTrash");
|
212 | 114a597f | Natasa Kapravelou | contextMenu.addItem(emptyTrashItem); |
213 | 114a597f | Natasa Kapravelou | |
214 | 114a597f | Natasa Kapravelou | MenuItem refreshItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
215 | 114a597f | Natasa Kapravelou | refreshItem.getElement().setId("topMenu.file.refresh");
|
216 | 114a597f | Natasa Kapravelou | contextMenu.addItem(refreshItem); |
217 | 114a597f | Natasa Kapravelou | |
218 | 114a597f | Natasa Kapravelou | MenuItem sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1)); |
219 | 114a597f | Natasa Kapravelou | sharingItem.getElement().setId("topMenu.file.sharing");
|
220 | 114a597f | Natasa Kapravelou | contextMenu.addItem(sharingItem) |
221 | 023f6f1e | Panagiotis Astithas | .setVisible(propertiesVisible); |
222 | 114a597f | Natasa Kapravelou | |
223 | 114a597f | Natasa Kapravelou | MenuItem propertiesItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0)); |
224 | 114a597f | Natasa Kapravelou | propertiesItem.getElement().setId("topMenu.file.properties");
|
225 | 114a597f | Natasa Kapravelou | contextMenu.addItem(propertiesItem) |
226 | 023f6f1e | Panagiotis Astithas | .setVisible(propertiesVisible); |
227 | 023f6f1e | Panagiotis Astithas | return contextMenu;
|
228 | 023f6f1e | Panagiotis Astithas | } |
229 | 023f6f1e | Panagiotis Astithas | |
230 | 023f6f1e | Panagiotis Astithas | } |