root / src / gr / ebs / gss / client / FileMenu.java @ 4cef6f04
History | View | Annotate | Download (7.6 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 | 023f6f1e | Panagiotis Astithas | |
30 | 023f6f1e | Panagiotis Astithas | import java.util.List; |
31 | 023f6f1e | Panagiotis Astithas | |
32 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.event.dom.client.ClickEvent; |
33 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.event.dom.client.ClickHandler; |
34 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.http.client.URL; |
35 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.resources.client.ClientBundle; |
36 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.resources.client.ImageResource; |
37 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.Command; |
38 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
39 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.MenuBar; |
40 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.PopupPanel; |
41 | 023f6f1e | Panagiotis Astithas | import com.google.gwt.user.client.ui.TreeItem; |
42 | 023f6f1e | Panagiotis Astithas | |
43 | 023f6f1e | Panagiotis Astithas | /**
|
44 | 023f6f1e | Panagiotis Astithas | * The 'File' menu implementation.
|
45 | 023f6f1e | Panagiotis Astithas | */
|
46 | 023f6f1e | Panagiotis Astithas | public class FileMenu extends PopupPanel implements ClickHandler { |
47 | 023f6f1e | Panagiotis Astithas | |
48 | 023f6f1e | Panagiotis Astithas | /**
|
49 | 023f6f1e | Panagiotis Astithas | * The widget's images.
|
50 | 023f6f1e | Panagiotis Astithas | */
|
51 | 023f6f1e | Panagiotis Astithas | private final Images images; |
52 | 023f6f1e | Panagiotis Astithas | |
53 | 023f6f1e | Panagiotis Astithas | /**
|
54 | 023f6f1e | Panagiotis Astithas | * An image bundle for this widgets images.
|
55 | 023f6f1e | Panagiotis Astithas | */
|
56 | 023f6f1e | Panagiotis Astithas | public interface Images extends ClientBundle,FilePropertiesDialog.Images { |
57 | 023f6f1e | Panagiotis Astithas | |
58 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/folder_new.png") |
59 | 023f6f1e | Panagiotis Astithas | ImageResource folderNew(); |
60 | 023f6f1e | Panagiotis Astithas | |
61 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/folder_outbox.png") |
62 | 023f6f1e | Panagiotis Astithas | ImageResource fileUpdate(); |
63 | 023f6f1e | Panagiotis Astithas | |
64 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/view_text.png") |
65 | 023f6f1e | Panagiotis Astithas | ImageResource viewText(); |
66 | 023f6f1e | Panagiotis Astithas | |
67 | 023f6f1e | Panagiotis Astithas | @Override
|
68 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/folder_inbox.png") |
69 | 023f6f1e | Panagiotis Astithas | ImageResource download(); |
70 | 023f6f1e | Panagiotis Astithas | |
71 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/trashcan_empty.png") |
72 | 023f6f1e | Panagiotis Astithas | ImageResource emptyTrash(); |
73 | 023f6f1e | Panagiotis Astithas | |
74 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/internet.png") |
75 | 023f6f1e | Panagiotis Astithas | ImageResource sharing(); |
76 | 023f6f1e | Panagiotis Astithas | |
77 | 023f6f1e | Panagiotis Astithas | @Source("gr/ebs/gss/resources/refresh.png") |
78 | 023f6f1e | Panagiotis Astithas | ImageResource refresh(); |
79 | 023f6f1e | Panagiotis Astithas | } |
80 | 023f6f1e | Panagiotis Astithas | |
81 | 023f6f1e | Panagiotis Astithas | final MenuBar contextMenu = new MenuBar(true); |
82 | 023f6f1e | Panagiotis Astithas | |
83 | 023f6f1e | Panagiotis Astithas | /**
|
84 | 023f6f1e | Panagiotis Astithas | * The widget's constructor.
|
85 | 023f6f1e | Panagiotis Astithas | *
|
86 | 023f6f1e | Panagiotis Astithas | * @param _images the image bundle passed on by the parent object
|
87 | 023f6f1e | Panagiotis Astithas | */
|
88 | 023f6f1e | Panagiotis Astithas | public FileMenu(final Images _images) { |
89 | 023f6f1e | Panagiotis Astithas | // The popup's constructor's argument is a boolean specifying that it
|
90 | 023f6f1e | Panagiotis Astithas | // auto-close itself when the user clicks outside of it.
|
91 | 023f6f1e | Panagiotis Astithas | super(true); |
92 | 023f6f1e | Panagiotis Astithas | setAnimationEnabled(true);
|
93 | 023f6f1e | Panagiotis Astithas | images = _images; |
94 | 023f6f1e | Panagiotis Astithas | add(contextMenu); |
95 | 023f6f1e | Panagiotis Astithas | |
96 | 023f6f1e | Panagiotis Astithas | } |
97 | 023f6f1e | Panagiotis Astithas | |
98 | 023f6f1e | Panagiotis Astithas | @Override
|
99 | 023f6f1e | Panagiotis Astithas | public void onClick(ClickEvent event) { |
100 | 023f6f1e | Panagiotis Astithas | final FileMenu menu = new FileMenu(images); |
101 | 023f6f1e | Panagiotis Astithas | final int left = event.getRelativeElement().getAbsoluteLeft(); |
102 | 023f6f1e | Panagiotis Astithas | final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); |
103 | 023f6f1e | Panagiotis Astithas | menu.setPopupPosition(left, top); |
104 | 023f6f1e | Panagiotis Astithas | menu.show(); |
105 | 023f6f1e | Panagiotis Astithas | |
106 | 023f6f1e | Panagiotis Astithas | } |
107 | 023f6f1e | Panagiotis Astithas | |
108 | 023f6f1e | Panagiotis Astithas | |
109 | 023f6f1e | Panagiotis Astithas | /**
|
110 | 023f6f1e | Panagiotis Astithas | * Do some validation before downloading a file.
|
111 | 023f6f1e | Panagiotis Astithas | */
|
112 | 023f6f1e | Panagiotis Astithas | void preDownloadCheck() {
|
113 | 023f6f1e | Panagiotis Astithas | Object selection = GSS.get().getCurrentSelection();
|
114 | 023f6f1e | Panagiotis Astithas | if (selection == null || !(selection instanceof FileResource)) { |
115 | 023f6f1e | Panagiotis Astithas | GSS.get().displayError("You have to select a file first");
|
116 | 023f6f1e | Panagiotis Astithas | return;
|
117 | 023f6f1e | Panagiotis Astithas | } |
118 | 023f6f1e | Panagiotis Astithas | } |
119 | 023f6f1e | Panagiotis Astithas | |
120 | 023f6f1e | Panagiotis Astithas | /**
|
121 | 023f6f1e | Panagiotis Astithas | * Create a download link for the respective menu item, if the currently
|
122 | 023f6f1e | Panagiotis Astithas | * selected object is a file.
|
123 | 023f6f1e | Panagiotis Astithas | *
|
124 | 023f6f1e | Panagiotis Astithas | * @param link a String array with two elements that is modified so that the
|
125 | 023f6f1e | Panagiotis Astithas | * first position contains the opening tag and the second one the
|
126 | 023f6f1e | Panagiotis Astithas | * closing tag
|
127 | 023f6f1e | Panagiotis Astithas | * @param forceDownload If true, link will be such that browser should ask for filename
|
128 | 023f6f1e | Panagiotis Astithas | * and save location
|
129 | 023f6f1e | Panagiotis Astithas | */
|
130 | 023f6f1e | Panagiotis Astithas | void createDownloadLink(String[] link, boolean forceDownload) { |
131 | 023f6f1e | Panagiotis Astithas | String downloadURL = getDownloadURL();
|
132 | 023f6f1e | Panagiotis Astithas | if (!downloadURL.isEmpty()) {
|
133 | 023f6f1e | Panagiotis Astithas | link[0] = "<a class='hidden-link' href='" + downloadURL |
134 | 023f6f1e | Panagiotis Astithas | + (forceDownload ? "&dl=1" : "") + "' target='_blank'>"; |
135 | 023f6f1e | Panagiotis Astithas | link[1] = "</a>"; |
136 | 023f6f1e | Panagiotis Astithas | } |
137 | 023f6f1e | Panagiotis Astithas | } |
138 | 023f6f1e | Panagiotis Astithas | |
139 | 023f6f1e | Panagiotis Astithas | public String getDownloadURL() { |
140 | 023f6f1e | Panagiotis Astithas | GSS app = GSS.get(); |
141 | 023f6f1e | Panagiotis Astithas | Object selection = app.getCurrentSelection();
|
142 | 023f6f1e | Panagiotis Astithas | if (selection != null && selection instanceof FileResource) { |
143 | 023f6f1e | Panagiotis Astithas | FileResource file = (FileResource) selection; |
144 | 023f6f1e | Panagiotis Astithas | return getDownloadURL(file);
|
145 | 023f6f1e | Panagiotis Astithas | } |
146 | 023f6f1e | Panagiotis Astithas | return ""; |
147 | 023f6f1e | Panagiotis Astithas | } |
148 | 023f6f1e | Panagiotis Astithas | |
149 | 023f6f1e | Panagiotis Astithas | public String getDownloadURL(FileResource file) { |
150 | 023f6f1e | Panagiotis Astithas | GSS app = GSS.get(); |
151 | 023f6f1e | Panagiotis Astithas | if (file != null) { |
152 | 023f6f1e | Panagiotis Astithas | String dateString = RestCommand.getDate();
|
153 | 023f6f1e | Panagiotis Astithas | String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length()); |
154 | 023f6f1e | Panagiotis Astithas | String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken())); |
155 | 023f6f1e | Panagiotis Astithas | return file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString); |
156 | 023f6f1e | Panagiotis Astithas | } |
157 | 023f6f1e | Panagiotis Astithas | return ""; |
158 | 023f6f1e | Panagiotis Astithas | } |
159 | 023f6f1e | Panagiotis Astithas | |
160 | 023f6f1e | Panagiotis Astithas | public MenuBar createMenu() { |
161 | 023f6f1e | Panagiotis Astithas | contextMenu.clearItems(); |
162 | 023f6f1e | Panagiotis Astithas | contextMenu.setAutoOpen(false);
|
163 | 023f6f1e | Panagiotis Astithas | final Command downloadCmd = new Command() { |
164 | 023f6f1e | Panagiotis Astithas | |
165 | 023f6f1e | Panagiotis Astithas | @Override
|
166 | 023f6f1e | Panagiotis Astithas | public void execute() { |
167 | 023f6f1e | Panagiotis Astithas | hide(); |
168 | 023f6f1e | Panagiotis Astithas | preDownloadCheck(); |
169 | 023f6f1e | Panagiotis Astithas | } |
170 | 023f6f1e | Panagiotis Astithas | }; |
171 | 023f6f1e | Panagiotis Astithas | Folders folders = GSS.get().getFolders(); |
172 | 023f6f1e | Panagiotis Astithas | TreeItem selectedItem = folders.getCurrent(); |
173 | 023f6f1e | Panagiotis Astithas | boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource; |
174 | 023f6f1e | Panagiotis Astithas | boolean propertiesVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource || GSS.get().getCurrentSelection() instanceof List)); |
175 | 023f6f1e | Panagiotis Astithas | boolean newFolderVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isTrashItem(selectedItem) || folders.isMyShares(selectedItem)|| folders.isOthersShared(selectedItem))); |
176 | 023f6f1e | Panagiotis Astithas | boolean uploadVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isTrashItem(selectedItem)|| folders.isMyShares(selectedItem)|| folders.isOthersShared(selectedItem))); |
177 | 023f6f1e | Panagiotis Astithas | if(newFolderVisible)
|
178 | 023f6f1e | Panagiotis Astithas | contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images)); |
179 | 023f6f1e | Panagiotis Astithas | if(uploadVisible)
|
180 | 023f6f1e | Panagiotis Astithas | contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this)); |
181 | 023f6f1e | Panagiotis Astithas | if (downloadVisible) {
|
182 | 023f6f1e | Panagiotis Astithas | String[] link = {"", ""}; |
183 | 023f6f1e | Panagiotis Astithas | createDownloadLink(link, false);
|
184 | 023f6f1e | Panagiotis Astithas | contextMenu.addItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd); |
185 | 023f6f1e | Panagiotis Astithas | createDownloadLink(link, true);
|
186 | 023f6f1e | Panagiotis Astithas | contextMenu.addItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd); |
187 | 023f6f1e | Panagiotis Astithas | } |
188 | 023f6f1e | Panagiotis Astithas | contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this)); |
189 | 023f6f1e | Panagiotis Astithas | contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images)); |
190 | 023f6f1e | Panagiotis Astithas | contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1)) |
191 | 023f6f1e | Panagiotis Astithas | .setVisible(propertiesVisible); |
192 | 023f6f1e | Panagiotis Astithas | contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0)) |
193 | 023f6f1e | Panagiotis Astithas | .setVisible(propertiesVisible); |
194 | 023f6f1e | Panagiotis Astithas | return contextMenu;
|
195 | 023f6f1e | Panagiotis Astithas | } |
196 | 023f6f1e | Panagiotis Astithas | |
197 | 023f6f1e | Panagiotis Astithas | } |