root / src / gr / grnet / pithos / web / client / Pithos.java @ 0f797b1b
History | View | Annotate | Download (41.8 kB)
1 | a57faaf0 | Christos Stathis | /*
|
---|---|---|---|
2 | 63366925 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 63366925 | Christos Stathis | *
|
4 | 63366925 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 63366925 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 63366925 | Christos Stathis | * conditions are met:
|
7 | 63366925 | Christos Stathis | *
|
8 | 63366925 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 63366925 | Christos Stathis | * disclaimer.
|
11 | 63366925 | Christos Stathis | *
|
12 | 63366925 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 63366925 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 63366925 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 63366925 | Christos Stathis | * provided with the distribution.
|
16 | 63366925 | Christos Stathis | *
|
17 | 63366925 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 63366925 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 63366925 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 63366925 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 63366925 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 63366925 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 63366925 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 63366925 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 63366925 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 63366925 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 63366925 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 63366925 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 63366925 | Christos Stathis | *
|
30 | 63366925 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 63366925 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 63366925 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 63366925 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | a57faaf0 | Christos Stathis | */
|
35 | a57faaf0 | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | a57faaf0 | Christos Stathis | |
37 | bbdd34ef | Christos Stathis | import gr.grnet.pithos.web.client.commands.UploadFileCommand; |
38 | 6084aa02 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.AccountResource; |
39 | 875a0179 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.File; |
40 | 7c818c14 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Folder; |
41 | 6084aa02 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.FolderTreeView; |
42 | 7c818c14 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel; |
43 | 602ebeb4 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
44 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.Group; |
45 | ee9fbc37 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.GroupTreeView; |
46 | ee9fbc37 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel; |
47 | 105b4e49 | Christos Stathis | import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView; |
48 | 105b4e49 | Christos Stathis | import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel; |
49 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView; |
50 | 6d8e0f58 | Christos Stathis | import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel; |
51 | 602ebeb4 | Christos Stathis | import gr.grnet.pithos.web.client.rest.DeleteRequest; |
52 | 6084aa02 | Christos Stathis | import gr.grnet.pithos.web.client.rest.GetRequest; |
53 | 64f42c0b | Christos Stathis | import gr.grnet.pithos.web.client.rest.HeadRequest; |
54 | d6be39da | Christos Stathis | import gr.grnet.pithos.web.client.rest.PutRequest; |
55 | a57faaf0 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
56 | a6592a15 | Christos Stathis | import gr.grnet.pithos.web.client.tagtree.Tag; |
57 | a6592a15 | Christos Stathis | import gr.grnet.pithos.web.client.tagtree.TagTreeView; |
58 | a6592a15 | Christos Stathis | import gr.grnet.pithos.web.client.tagtree.TagTreeViewModel; |
59 | 7811b9d1 | Christos Stathis | |
60 | a57faaf0 | Christos Stathis | import java.util.ArrayList; |
61 | 8ddf07ab | Christos Stathis | import java.util.Date; |
62 | a57faaf0 | Christos Stathis | import java.util.HashMap; |
63 | 7c818c14 | Christos Stathis | import java.util.Iterator; |
64 | a57faaf0 | Christos Stathis | import java.util.List; |
65 | 7811b9d1 | Christos Stathis | import java.util.Set; |
66 | a57faaf0 | Christos Stathis | |
67 | a57faaf0 | Christos Stathis | import com.google.gwt.core.client.EntryPoint; |
68 | a57faaf0 | Christos Stathis | import com.google.gwt.core.client.GWT; |
69 | 7811b9d1 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
70 | 7811b9d1 | Christos Stathis | import com.google.gwt.core.client.Scheduler.ScheduledCommand; |
71 | 7811b9d1 | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
72 | 7811b9d1 | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
73 | a57faaf0 | Christos Stathis | import com.google.gwt.event.logical.shared.ResizeEvent; |
74 | a57faaf0 | Christos Stathis | import com.google.gwt.event.logical.shared.ResizeHandler; |
75 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.Request; |
76 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.RequestBuilder; |
77 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.RequestCallback; |
78 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.RequestException; |
79 | 7811b9d1 | Christos Stathis | import com.google.gwt.http.client.Response; |
80 | f5023f13 | Christos Stathis | import com.google.gwt.http.client.URL; |
81 | 29b2177c | Christos Stathis | import com.google.gwt.i18n.client.NumberFormat; |
82 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONArray; |
83 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONObject; |
84 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONParser; |
85 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONString; |
86 | 7811b9d1 | Christos Stathis | import com.google.gwt.json.client.JSONValue; |
87 | a57faaf0 | Christos Stathis | import com.google.gwt.resources.client.ImageResource; |
88 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.Command; |
89 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Cookies; |
90 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Event; |
91 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.History; |
92 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.Window; |
93 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.AbstractImagePrototype; |
94 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.Button; |
95 | 0549e173 | Christos Stathis | import com.google.gwt.user.client.ui.Composite; |
96 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.HTML; |
97 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
98 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.HasVerticalAlignment; |
99 | 7811b9d1 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalPanel; |
100 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.HorizontalSplitPanel; |
101 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.RootPanel; |
102 | a57faaf0 | Christos Stathis | import com.google.gwt.user.client.ui.VerticalPanel; |
103 | 7811b9d1 | Christos Stathis | import com.google.gwt.view.client.SelectionChangeEvent; |
104 | 7811b9d1 | Christos Stathis | import com.google.gwt.view.client.SelectionChangeEvent.Handler; |
105 | 7811b9d1 | Christos Stathis | import com.google.gwt.view.client.SingleSelectionModel; |
106 | 6084aa02 | Christos Stathis | |
107 | a57faaf0 | Christos Stathis | /**
|
108 | a57faaf0 | Christos Stathis | * Entry point classes define <code>onModuleLoad()</code>.
|
109 | a57faaf0 | Christos Stathis | */
|
110 | 749068ba | Christos Stathis | public class Pithos implements EntryPoint, ResizeHandler { |
111 | a57faaf0 | Christos Stathis | |
112 | 105b4e49 | Christos Stathis | public static final String HOME_CONTAINER = "pithos"; |
113 | 7b28ae07 | Christos Stathis | |
114 | 7b28ae07 | Christos Stathis | public static final String TRASH_CONTAINER = "trash"; |
115 | 105b4e49 | Christos Stathis | |
116 | a57faaf0 | Christos Stathis | /**
|
117 | a57faaf0 | Christos Stathis | * Instantiate an application-level image bundle. This object will provide
|
118 | a57faaf0 | Christos Stathis | * programmatic access to all the images needed by widgets.
|
119 | a57faaf0 | Christos Stathis | */
|
120 | a9e497d4 | Christos Stathis | static Images images = (Images) GWT.create(Images.class);
|
121 | a57faaf0 | Christos Stathis | |
122 | 6084aa02 | Christos Stathis | public String getUsername() { |
123 | 6084aa02 | Christos Stathis | return username;
|
124 | 6084aa02 | Christos Stathis | } |
125 | a57faaf0 | Christos Stathis | |
126 | 8e61880b | Christos Stathis | public void setAccount(AccountResource acct) { |
127 | 8e61880b | Christos Stathis | account = acct; |
128 | 8e61880b | Christos Stathis | } |
129 | 8e61880b | Christos Stathis | |
130 | 8e61880b | Christos Stathis | public AccountResource getAccount() {
|
131 | 8e61880b | Christos Stathis | return account;
|
132 | 8e61880b | Christos Stathis | } |
133 | 8e61880b | Christos Stathis | |
134 | 16e8478a | Christos Stathis | public void updateFolder(Folder f, boolean showfiles, Command callback) { |
135 | 16e8478a | Christos Stathis | folderTreeView.updateFolder(f, showfiles, callback); |
136 | b651e67f | Christos Stathis | } |
137 | b651e67f | Christos Stathis | |
138 | 4baffab1 | Christos Stathis | public void updateGroupNode(Group group) { |
139 | 4baffab1 | Christos Stathis | groupTreeView.updateGroupNode(group); |
140 | 4baffab1 | Christos Stathis | } |
141 | 4baffab1 | Christos Stathis | |
142 | 105b4e49 | Christos Stathis | public void updateSharedFolder(Folder f, boolean showfiles) { |
143 | 105b4e49 | Christos Stathis | mysharedTreeView.updateFolder(f, showfiles); |
144 | 105b4e49 | Christos Stathis | } |
145 | 105b4e49 | Christos Stathis | |
146 | 6d8e0f58 | Christos Stathis | public void updateOtherSharedFolder(Folder f, boolean showfiles) { |
147 | 6d8e0f58 | Christos Stathis | otherSharedTreeView.updateFolder(f, showfiles); |
148 | 6d8e0f58 | Christos Stathis | } |
149 | 6d8e0f58 | Christos Stathis | |
150 | ef5b664d | Christos Stathis | public List<Tag> getAllTags() { |
151 | ef5b664d | Christos Stathis | List<Tag> tagList = new ArrayList<Tag>(); |
152 | ef5b664d | Christos Stathis | for (Folder f : account.getContainers()) {
|
153 | ef5b664d | Christos Stathis | for (String t : f.getTags()) { |
154 | ef5b664d | Christos Stathis | tagList.add(new Tag(t));
|
155 | ef5b664d | Christos Stathis | } |
156 | ef5b664d | Christos Stathis | } |
157 | ef5b664d | Christos Stathis | return tagList;
|
158 | 0d1e8310 | Christos Stathis | } |
159 | 0d1e8310 | Christos Stathis | |
160 | 105b4e49 | Christos Stathis | public MysharedTreeView getMySharedTreeView() {
|
161 | 105b4e49 | Christos Stathis | return mysharedTreeView;
|
162 | 105b4e49 | Christos Stathis | } |
163 | 105b4e49 | Christos Stathis | |
164 | 6084aa02 | Christos Stathis | /**
|
165 | a57faaf0 | Christos Stathis | * An aggregate image bundle that pulls together all the images for this
|
166 | a57faaf0 | Christos Stathis | * application into a single bundle.
|
167 | a57faaf0 | Christos Stathis | */
|
168 | a9e497d4 | Christos Stathis | public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images { |
169 | a57faaf0 | Christos Stathis | |
170 | a57faaf0 | Christos Stathis | @Source("gr/grnet/pithos/resources/document.png") |
171 | a57faaf0 | Christos Stathis | ImageResource folders(); |
172 | a57faaf0 | Christos Stathis | |
173 | a9e497d4 | Christos Stathis | @Source("gr/grnet/pithos/resources/advancedsettings.png") |
174 | a9e497d4 | Christos Stathis | ImageResource tools(); |
175 | a57faaf0 | Christos Stathis | } |
176 | a57faaf0 | Christos Stathis | |
177 | a57faaf0 | Christos Stathis | /**
|
178 | a57faaf0 | Christos Stathis | * The Application Clipboard implementation;
|
179 | a57faaf0 | Christos Stathis | */
|
180 | a57faaf0 | Christos Stathis | private Clipboard clipboard = new Clipboard(); |
181 | a57faaf0 | Christos Stathis | |
182 | a57faaf0 | Christos Stathis | /**
|
183 | a57faaf0 | Christos Stathis | * The top panel that contains the menu bar.
|
184 | a57faaf0 | Christos Stathis | */
|
185 | a57faaf0 | Christos Stathis | private TopPanel topPanel;
|
186 | a57faaf0 | Christos Stathis | |
187 | a57faaf0 | Christos Stathis | /**
|
188 | a57faaf0 | Christos Stathis | * The panel that contains the various system messages.
|
189 | a57faaf0 | Christos Stathis | */
|
190 | 749068ba | Christos Stathis | private MessagePanel messagePanel = new MessagePanel(Pithos.images); |
191 | a57faaf0 | Christos Stathis | |
192 | a57faaf0 | Christos Stathis | /**
|
193 | a57faaf0 | Christos Stathis | * The bottom panel that contains the status bar.
|
194 | a57faaf0 | Christos Stathis | */
|
195 | 8e61880b | Christos Stathis | private StatusPanel statusPanel = null; |
196 | a57faaf0 | Christos Stathis | |
197 | a57faaf0 | Christos Stathis | /**
|
198 | a57faaf0 | Christos Stathis | * The file list widget.
|
199 | a57faaf0 | Christos Stathis | */
|
200 | a57faaf0 | Christos Stathis | private FileList fileList;
|
201 | a57faaf0 | Christos Stathis | |
202 | a57faaf0 | Christos Stathis | /**
|
203 | a57faaf0 | Christos Stathis | * The tab panel that occupies the right side of the screen.
|
204 | a57faaf0 | Christos Stathis | */
|
205 | bbdd34ef | Christos Stathis | private VerticalPanel inner = new VerticalPanel(); |
206 | a57faaf0 | Christos Stathis | |
207 | 63366925 | Christos Stathis | |
208 | a57faaf0 | Christos Stathis | /**
|
209 | a57faaf0 | Christos Stathis | * The split panel that will contain the left and right panels.
|
210 | a57faaf0 | Christos Stathis | */
|
211 | a57faaf0 | Christos Stathis | private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); |
212 | a57faaf0 | Christos Stathis | |
213 | a57faaf0 | Christos Stathis | /**
|
214 | a57faaf0 | Christos Stathis | * The currently selected item in the application, for use by the Edit menu
|
215 | a57faaf0 | Christos Stathis | * commands. Potential types are Folder, File, User and Group.
|
216 | a57faaf0 | Christos Stathis | */
|
217 | a57faaf0 | Christos Stathis | private Object currentSelection; |
218 | a57faaf0 | Christos Stathis | |
219 | a57faaf0 | Christos Stathis | public HashMap<String, String> userFullNameMap = new HashMap<String, String>(); |
220 | a57faaf0 | Christos Stathis | |
221 | 6084aa02 | Christos Stathis | private String username = null; |
222 | 6084aa02 | Christos Stathis | |
223 | 6084aa02 | Christos Stathis | /**
|
224 | 6084aa02 | Christos Stathis | * The authentication token of the current user.
|
225 | 6084aa02 | Christos Stathis | */
|
226 | 6084aa02 | Christos Stathis | private String token; |
227 | 6084aa02 | Christos Stathis | |
228 | 7c54d867 | Christos Stathis | VerticalPanel trees; |
229 | 7c54d867 | Christos Stathis | |
230 | f1b24b82 | Christos Stathis | SingleSelectionModel<Folder> folderTreeSelectionModel;
|
231 | f1b24b82 | Christos Stathis | FolderTreeViewModel folderTreeViewModel; |
232 | f1b24b82 | Christos Stathis | FolderTreeView folderTreeView; |
233 | 6084aa02 | Christos Stathis | |
234 | f1b24b82 | Christos Stathis | SingleSelectionModel<Folder> mysharedTreeSelectionModel;
|
235 | 7c54d867 | Christos Stathis | MysharedTreeViewModel mysharedTreeViewModel; |
236 | 7c54d867 | Christos Stathis | MysharedTreeView mysharedTreeView = null;;
|
237 | 105b4e49 | Christos Stathis | |
238 | 7811b9d1 | Christos Stathis | protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel; |
239 | 7c54d867 | Christos Stathis | OtherSharedTreeViewModel otherSharedTreeViewModel; |
240 | 7c54d867 | Christos Stathis | OtherSharedTreeView otherSharedTreeView = null;
|
241 | a6592a15 | Christos Stathis | |
242 | abd8738f | Christos Stathis | GroupTreeViewModel groupTreeViewModel; |
243 | ee9fbc37 | Christos Stathis | private GroupTreeView groupTreeView;
|
244 | ee9fbc37 | Christos Stathis | |
245 | f1b24b82 | Christos Stathis | private TreeView selectedTree;
|
246 | 7811b9d1 | Christos Stathis | protected AccountResource account;
|
247 | 16e8478a | Christos Stathis | |
248 | abd8738f | Christos Stathis | Folder trash; |
249 | 0549e173 | Christos Stathis | |
250 | 0549e173 | Christos Stathis | List<Composite> treeViews = new ArrayList<Composite>(); |
251 | 8e61880b | Christos Stathis | |
252 | 7c54d867 | Christos Stathis | @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>(); |
253 | 3ebb88f4 | Christos Stathis | |
254 | 3ebb88f4 | Christos Stathis | Button upload;
|
255 | bf664298 | Christos Stathis | |
256 | bf664298 | Christos Stathis | private HTML usedBytes; |
257 | bf664298 | Christos Stathis | |
258 | bf664298 | Christos Stathis | private HTML totalBytes; |
259 | bf664298 | Christos Stathis | |
260 | bf664298 | Christos Stathis | private HTML usedPercent; |
261 | a19f758c | Christos Stathis | |
262 | a19f758c | Christos Stathis | private HTML numOfFiles; |
263 | b162dfaa | Christos Stathis | |
264 | b162dfaa | Christos Stathis | private Button toolsButton; |
265 | 105b4e49 | Christos Stathis | |
266 | a57faaf0 | Christos Stathis | @Override
|
267 | a57faaf0 | Christos Stathis | public void onModuleLoad() { |
268 | 6084aa02 | Christos Stathis | if (parseUserCredentials())
|
269 | 6084aa02 | Christos Stathis | initialize(); |
270 | 6084aa02 | Christos Stathis | } |
271 | a57faaf0 | Christos Stathis | |
272 | 6084aa02 | Christos Stathis | private void initialize() { |
273 | a7b6e464 | Christos Stathis | boolean bareContent = Window.Location.getParameter("noframe") != null; |
274 | a7b6e464 | Christos Stathis | String contentWidth = bareContent ? "100%" : "75%"; |
275 | bbdd34ef | Christos Stathis | |
276 | a7b6e464 | Christos Stathis | VerticalPanel outer = new VerticalPanel();
|
277 | a7b6e464 | Christos Stathis | outer.setWidth("100%");
|
278 | a7b6e464 | Christos Stathis | if (!bareContent) {
|
279 | a7b6e464 | Christos Stathis | outer.addStyleName("pithos-outer");
|
280 | a7b6e464 | Christos Stathis | } |
281 | a7b6e464 | Christos Stathis | |
282 | a7b6e464 | Christos Stathis | if (!bareContent) {
|
283 | a7b6e464 | Christos Stathis | topPanel = new TopPanel(this, Pithos.images); |
284 | a7b6e464 | Christos Stathis | topPanel.setWidth("100%");
|
285 | a7b6e464 | Christos Stathis | outer.add(topPanel); |
286 | a7b6e464 | Christos Stathis | outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER); |
287 | a7b6e464 | Christos Stathis | } |
288 | a76065b6 | Christos Stathis | |
289 | a7b6e464 | Christos Stathis | HorizontalPanel header = new HorizontalPanel();
|
290 | a7b6e464 | Christos Stathis | header.addStyleName("pithos-header");
|
291 | 2d91458a | Christos Stathis | header.setWidth(contentWidth); |
292 | 0549e173 | Christos Stathis | if (bareContent)
|
293 | 0549e173 | Christos Stathis | header.addStyleName("pithos-header-noframe");
|
294 | a7b6e464 | Christos Stathis | upload = new Button("Upload File", new ClickHandler() { |
295 | a7b6e464 | Christos Stathis | @Override
|
296 | a7b6e464 | Christos Stathis | public void onClick(@SuppressWarnings("unused") ClickEvent event) { |
297 | a7b6e464 | Christos Stathis | new UploadFileCommand(Pithos.this, null, getSelection()).execute(); |
298 | a7b6e464 | Christos Stathis | } |
299 | a7b6e464 | Christos Stathis | }); |
300 | a7b6e464 | Christos Stathis | upload.addStyleName("pithos-uploadButton");
|
301 | 140f0f6d | Christos Stathis | header.add(upload); |
302 | 140f0f6d | Christos Stathis | header.setCellHorizontalAlignment(upload, HasHorizontalAlignment.ALIGN_LEFT); |
303 | 140f0f6d | Christos Stathis | header.setCellVerticalAlignment(upload, HasVerticalAlignment.ALIGN_MIDDLE); |
304 | 140f0f6d | Christos Stathis | header.setCellWidth(upload, "146px");
|
305 | 6084aa02 | Christos Stathis | |
306 | 140f0f6d | Christos Stathis | messagePanel.setVisible(false);
|
307 | 140f0f6d | Christos Stathis | header.add(messagePanel); |
308 | 140f0f6d | Christos Stathis | header.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); |
309 | 140f0f6d | Christos Stathis | header.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE); |
310 | 140f0f6d | Christos Stathis | |
311 | 140f0f6d | Christos Stathis | |
312 | b162dfaa | Christos Stathis | toolsButton = new Button(AbstractImagePrototype.create(images.tools()).getHTML()); |
313 | a9e497d4 | Christos Stathis | toolsButton.addClickHandler(new ClickHandler() {
|
314 | a9e497d4 | Christos Stathis | |
315 | a9e497d4 | Christos Stathis | @Override
|
316 | a9e497d4 | Christos Stathis | public void onClick(ClickEvent event) { |
317 | a9e497d4 | Christos Stathis | ToolsMenu menu = new ToolsMenu(Pithos.this, images, getSelectedTree(), getSelectedTree().getSelection(), getFileList().getSelectedFiles());
|
318 | b162dfaa | Christos Stathis | if (!menu.isEmpty()) {
|
319 | b162dfaa | Christos Stathis | menu.setPopupPosition(event.getClientX(), event.getClientY()); |
320 | b162dfaa | Christos Stathis | menu.show(); |
321 | b162dfaa | Christos Stathis | } |
322 | a9e497d4 | Christos Stathis | } |
323 | a9e497d4 | Christos Stathis | }); |
324 | 140f0f6d | Christos Stathis | header.add(toolsButton); |
325 | 140f0f6d | Christos Stathis | header.setCellHorizontalAlignment(toolsButton, HasHorizontalAlignment.ALIGN_RIGHT); |
326 | 140f0f6d | Christos Stathis | header.setCellVerticalAlignment(toolsButton, HasVerticalAlignment.ALIGN_MIDDLE); |
327 | 140f0f6d | Christos Stathis | header.setCellWidth(toolsButton, "30px");
|
328 | a9e497d4 | Christos Stathis | |
329 | a19f758c | Christos Stathis | HorizontalPanel folderStatistics = new HorizontalPanel();
|
330 | bbdd34ef | Christos Stathis | folderStatistics.addStyleName("pithos-folderStatistics");
|
331 | a19f758c | Christos Stathis | numOfFiles = new HTML(); |
332 | a19f758c | Christos Stathis | folderStatistics.add(numOfFiles); |
333 | a7b6e464 | Christos Stathis | folderStatistics.setCellVerticalAlignment(numOfFiles, HasVerticalAlignment.ALIGN_MIDDLE); |
334 | a19f758c | Christos Stathis | HTML numOfFilesLabel = new HTML(" Files"); |
335 | a19f758c | Christos Stathis | folderStatistics.add(numOfFilesLabel); |
336 | a7b6e464 | Christos Stathis | folderStatistics.setCellVerticalAlignment(numOfFilesLabel, HasVerticalAlignment.ALIGN_MIDDLE); |
337 | 140f0f6d | Christos Stathis | header.add(folderStatistics); |
338 | 140f0f6d | Christos Stathis | header.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT); |
339 | 140f0f6d | Christos Stathis | header.setCellVerticalAlignment(folderStatistics, HasVerticalAlignment.ALIGN_MIDDLE); |
340 | 140f0f6d | Christos Stathis | header.setCellWidth(folderStatistics, "60px");
|
341 | a7b6e464 | Christos Stathis | outer.add(header); |
342 | a7b6e464 | Christos Stathis | outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER); |
343 | a7b6e464 | Christos Stathis | // Inner contains the various lists.nner
|
344 | a7b6e464 | Christos Stathis | inner.sinkEvents(Event.ONCONTEXTMENU);
|
345 | a7b6e464 | Christos Stathis | inner.setWidth("100%");
|
346 | 6084aa02 | Christos Stathis | |
347 | 875a0179 | Christos Stathis | folderTreeSelectionModel = new SingleSelectionModel<Folder>(); |
348 | 875a0179 | Christos Stathis | folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
349 | 875a0179 | Christos Stathis | @Override
|
350 | 7811b9d1 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
351 | a845b044 | Christos Stathis | if (folderTreeSelectionModel.getSelectedObject() != null) { |
352 | f1b24b82 | Christos Stathis | deselectOthers(folderTreeView, folderTreeSelectionModel); |
353 | 3ebb88f4 | Christos Stathis | applyPermissions(folderTreeSelectionModel.getSelectedObject()); |
354 | a845b044 | Christos Stathis | Folder f = folderTreeSelectionModel.getSelectedObject(); |
355 | cf49bbc9 | Christos Stathis | showFiles(f); |
356 | a845b044 | Christos Stathis | } |
357 | 875a0179 | Christos Stathis | } |
358 | 875a0179 | Christos Stathis | }); |
359 | 105b4e49 | Christos Stathis | selectionModels.add(folderTreeSelectionModel); |
360 | 875a0179 | Christos Stathis | |
361 | a7c43f26 | Christos Stathis | folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel); |
362 | 875a0179 | Christos Stathis | folderTreeView = new FolderTreeView(folderTreeViewModel);
|
363 | 0549e173 | Christos Stathis | treeViews.add(folderTreeView); |
364 | 0549e173 | Christos Stathis | |
365 | a7c43f26 | Christos Stathis | fileList = new FileList(this, images, folderTreeView); |
366 | bbdd34ef | Christos Stathis | inner.add(fileList); |
367 | 875a0179 | Christos Stathis | |
368 | 4baffab1 | Christos Stathis | groupTreeViewModel = new GroupTreeViewModel(this); |
369 | ee9fbc37 | Christos Stathis | groupTreeView = new GroupTreeView(groupTreeViewModel);
|
370 | 0549e173 | Christos Stathis | treeViews.add(groupTreeView); |
371 | 0549e173 | Christos Stathis | |
372 | 7c54d867 | Christos Stathis | trees = new VerticalPanel();
|
373 | a76065b6 | Christos Stathis | trees.setWidth("100%");
|
374 | bbdd34ef | Christos Stathis | |
375 | bbdd34ef | Christos Stathis | |
376 | bbdd34ef | Christos Stathis | HorizontalPanel treeHeader = new HorizontalPanel();
|
377 | bbdd34ef | Christos Stathis | treeHeader.addStyleName("pithos-treeHeader");
|
378 | a76065b6 | Christos Stathis | treeHeader.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); |
379 | a7b6e464 | Christos Stathis | treeHeader.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); |
380 | bf664298 | Christos Stathis | HorizontalPanel statistics = new HorizontalPanel();
|
381 | a7b6e464 | Christos Stathis | statistics.addStyleName("pithos-statistics");
|
382 | 0f797b1b | Christos Stathis | statistics.add(new HTML("Used: ")); |
383 | bf664298 | Christos Stathis | usedBytes = new HTML(); |
384 | bf664298 | Christos Stathis | statistics.add(usedBytes); |
385 | bf664298 | Christos Stathis | statistics.add(new HTML(" of ")); |
386 | bf664298 | Christos Stathis | totalBytes = new HTML(); |
387 | bf664298 | Christos Stathis | statistics.add(totalBytes); |
388 | bf664298 | Christos Stathis | statistics.add(new HTML(" (")); |
389 | bf664298 | Christos Stathis | usedPercent = new HTML(); |
390 | bf664298 | Christos Stathis | statistics.add(usedPercent); |
391 | 29b2177c | Christos Stathis | statistics.add(new HTML(")")); |
392 | bf664298 | Christos Stathis | treeHeader.add(statistics); |
393 | 29b2177c | Christos Stathis | treeHeader.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_LEFT); |
394 | bbdd34ef | Christos Stathis | trees.add(treeHeader); |
395 | bbdd34ef | Christos Stathis | |
396 | a6592a15 | Christos Stathis | trees.add(folderTreeView); |
397 | ee9fbc37 | Christos Stathis | trees.add(groupTreeView); |
398 | 6084aa02 | Christos Stathis | // Add the left and right panels to the split panel.
|
399 | a6592a15 | Christos Stathis | splitPanel.setLeftWidget(trees); |
400 | 6084aa02 | Christos Stathis | splitPanel.setRightWidget(inner); |
401 | a76065b6 | Christos Stathis | splitPanel.setSplitPosition("35%");
|
402 | 6084aa02 | Christos Stathis | splitPanel.setSize("100%", "100%"); |
403 | 6084aa02 | Christos Stathis | splitPanel.addStyleName("pithos-splitPanel");
|
404 | a7b6e464 | Christos Stathis | splitPanel.setWidth(contentWidth); |
405 | 6084aa02 | Christos Stathis | outer.add(splitPanel); |
406 | a76065b6 | Christos Stathis | outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER); |
407 | bbdd34ef | Christos Stathis | |
408 | a7b6e464 | Christos Stathis | if (!bareContent) {
|
409 | a7b6e464 | Christos Stathis | statusPanel = new StatusPanel();
|
410 | a7b6e464 | Christos Stathis | statusPanel.setWidth("100%");
|
411 | a7b6e464 | Christos Stathis | outer.add(statusPanel); |
412 | a7b6e464 | Christos Stathis | outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER); |
413 | a7b6e464 | Christos Stathis | } |
414 | 0549e173 | Christos Stathis | else
|
415 | 0549e173 | Christos Stathis | splitPanel.addStyleName("pithos-splitPanel-noframe");
|
416 | 6084aa02 | Christos Stathis | |
417 | 6084aa02 | Christos Stathis | // Hook the window resize event, so that we can adjust the UI.
|
418 | 6084aa02 | Christos Stathis | Window.addResizeHandler(this); |
419 | 6084aa02 | Christos Stathis | // Clear out the window's built-in margin, because we want to take
|
420 | 6084aa02 | Christos Stathis | // advantage of the entire client area.
|
421 | 6084aa02 | Christos Stathis | Window.setMargin("0px"); |
422 | 6084aa02 | Christos Stathis | // Finally, add the outer panel to the RootPanel, so that it will be
|
423 | 6084aa02 | Christos Stathis | // displayed.
|
424 | 6084aa02 | Christos Stathis | RootPanel.get().add(outer); |
425 | 6084aa02 | Christos Stathis | // Call the window resized handler to get the initial sizes setup. Doing
|
426 | 6084aa02 | Christos Stathis | // this in a deferred command causes it to occur after all widgets'
|
427 | 6084aa02 | Christos Stathis | // sizes have been computed by the browser.
|
428 | 7c818c14 | Christos Stathis | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
429 | 6084aa02 | Christos Stathis | |
430 | 6084aa02 | Christos Stathis | @Override
|
431 | 6084aa02 | Christos Stathis | public void execute() { |
432 | 6084aa02 | Christos Stathis | onWindowResized(Window.getClientHeight());
|
433 | 6084aa02 | Christos Stathis | } |
434 | 6084aa02 | Christos Stathis | }); |
435 | 7c818c14 | Christos Stathis | |
436 | 7c818c14 | Christos Stathis | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
437 | 7c818c14 | Christos Stathis | @Override
|
438 | 7c818c14 | Christos Stathis | public void execute() { |
439 | 64f42c0b | Christos Stathis | fetchAccount(new Command() {
|
440 | 64f42c0b | Christos Stathis | |
441 | 64f42c0b | Christos Stathis | @Override
|
442 | 64f42c0b | Christos Stathis | public void execute() { |
443 | 64f42c0b | Christos Stathis | if (!account.hasHomeContainer())
|
444 | 64f42c0b | Christos Stathis | createHomeContainer(account, this);
|
445 | 64f42c0b | Christos Stathis | else if (!account.hasTrashContainer()) |
446 | 64f42c0b | Christos Stathis | createTrashContainer(this);
|
447 | 64f42c0b | Christos Stathis | else {
|
448 | 64f42c0b | Christos Stathis | for (Folder f : account.getContainers())
|
449 | 64f42c0b | Christos Stathis | if (f.getName().equals(Pithos.TRASH_CONTAINER)) {
|
450 | 64f42c0b | Christos Stathis | trash = f; |
451 | 64f42c0b | Christos Stathis | break;
|
452 | 64f42c0b | Christos Stathis | } |
453 | 5fab761b | Christos Stathis | folderTreeViewModel.initialize(account, new Command() {
|
454 | 5fab761b | Christos Stathis | |
455 | 5fab761b | Christos Stathis | @Override
|
456 | 5fab761b | Christos Stathis | public void execute() { |
457 | 5fab761b | Christos Stathis | createMySharedTree(); |
458 | 5fab761b | Christos Stathis | } |
459 | 5fab761b | Christos Stathis | }); |
460 | 64f42c0b | Christos Stathis | groupTreeViewModel.initialize(); |
461 | 64f42c0b | Christos Stathis | showStatistics(); |
462 | 64f42c0b | Christos Stathis | } |
463 | 64f42c0b | Christos Stathis | } |
464 | 64f42c0b | Christos Stathis | }); |
465 | 7c818c14 | Christos Stathis | } |
466 | 7c818c14 | Christos Stathis | }); |
467 | 140f0f6d | Christos Stathis | |
468 | 140f0f6d | Christos Stathis | // Scheduler.get().scheduleDeferred(new Command() {
|
469 | 140f0f6d | Christos Stathis | //
|
470 | 140f0f6d | Christos Stathis | // @Override
|
471 | 140f0f6d | Christos Stathis | // public void execute() {
|
472 | 140f0f6d | Christos Stathis | // displayError("lalala");
|
473 | 140f0f6d | Christos Stathis | //
|
474 | 140f0f6d | Christos Stathis | // }
|
475 | 140f0f6d | Christos Stathis | // });
|
476 | 6084aa02 | Christos Stathis | } |
477 | a57faaf0 | Christos Stathis | |
478 | 3ebb88f4 | Christos Stathis | public void applyPermissions(Folder f) { |
479 | 3ebb88f4 | Christos Stathis | if (f != null) { |
480 | 3ebb88f4 | Christos Stathis | if (f.isInTrash())
|
481 | 3ebb88f4 | Christos Stathis | upload.setEnabled(false);
|
482 | 3ebb88f4 | Christos Stathis | else {
|
483 | 3ebb88f4 | Christos Stathis | Boolean[] perms = f.getPermissions().get(username); |
484 | 3ebb88f4 | Christos Stathis | if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) { |
485 | 3ebb88f4 | Christos Stathis | upload.setEnabled(true);
|
486 | 3ebb88f4 | Christos Stathis | } |
487 | 3ebb88f4 | Christos Stathis | else
|
488 | 3ebb88f4 | Christos Stathis | upload.setEnabled(false);
|
489 | 3ebb88f4 | Christos Stathis | } |
490 | 3ebb88f4 | Christos Stathis | } |
491 | 3ebb88f4 | Christos Stathis | else
|
492 | 3ebb88f4 | Christos Stathis | upload.setEnabled(false);
|
493 | 3ebb88f4 | Christos Stathis | } |
494 | 3ebb88f4 | Christos Stathis | |
495 | 3ebb88f4 | Christos Stathis | @SuppressWarnings({ "rawtypes", "unchecked" }) |
496 | f1b24b82 | Christos Stathis | public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) { |
497 | f1b24b82 | Christos Stathis | selectedTree = _selectedTree; |
498 | 0549e173 | Christos Stathis | |
499 | 0549e173 | Christos Stathis | for (Composite c : treeViews) |
500 | 0549e173 | Christos Stathis | if (c.equals(selectedTree))
|
501 | 0549e173 | Christos Stathis | c.addStyleName("cellTreeWidget-selectedTree");
|
502 | 0549e173 | Christos Stathis | else
|
503 | 0549e173 | Christos Stathis | c.removeStyleName("cellTreeWidget-selectedTree");
|
504 | 0549e173 | Christos Stathis | |
505 | 105b4e49 | Christos Stathis | for (SingleSelectionModel s : selectionModels) |
506 | 105b4e49 | Christos Stathis | if (!s.equals(model))
|
507 | 105b4e49 | Christos Stathis | s.setSelected(s.getSelectedObject(), false);
|
508 | 105b4e49 | Christos Stathis | } |
509 | 105b4e49 | Christos Stathis | |
510 | bdda6b2f | Christos Stathis | public void showFiles(Folder f) { |
511 | 07a1b5fe | Christos Stathis | Set<File> files = f.getFiles(); |
512 | a845b044 | Christos Stathis | showFiles(files); |
513 | a845b044 | Christos Stathis | } |
514 | a845b044 | Christos Stathis | |
515 | a845b044 | Christos Stathis | public void showFiles(Set<File> files) { |
516 | a845b044 | Christos Stathis | //Iterator<File> iter = files.iterator();
|
517 | a845b044 | Christos Stathis | //fetchFile(iter, files);
|
518 | a845b044 | Christos Stathis | fileList.setFiles(new ArrayList<File>(files)); |
519 | 07a1b5fe | Christos Stathis | } |
520 | 07a1b5fe | Christos Stathis | |
521 | 7811b9d1 | Christos Stathis | protected void fetchFile(final Iterator<File> iter, final Set<File> files) { |
522 | 07a1b5fe | Christos Stathis | if (iter.hasNext()) {
|
523 | 07a1b5fe | Christos Stathis | File file = iter.next();
|
524 | b51c628b | Christos Stathis | String path = file.getUri() + "?format=json"; |
525 | b51c628b | Christos Stathis | GetRequest<File> getFile = new GetRequest<File>(File.class, getApiPath(), username, path, file) { |
526 | 07a1b5fe | Christos Stathis | @Override
|
527 | 7811b9d1 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") File _result) { |
528 | 07a1b5fe | Christos Stathis | fetchFile(iter, files); |
529 | 07a1b5fe | Christos Stathis | } |
530 | 07a1b5fe | Christos Stathis | |
531 | 07a1b5fe | Christos Stathis | @Override
|
532 | 07a1b5fe | Christos Stathis | public void onError(Throwable t) { |
533 | 07a1b5fe | Christos Stathis | GWT.log("Error getting file", t);
|
534 | 07a1b5fe | Christos Stathis | if (t instanceof RestException) |
535 | a7c43f26 | Christos Stathis | displayError("Error getting file: " + ((RestException) t).getHttpStatusText());
|
536 | 07a1b5fe | Christos Stathis | else
|
537 | a7c43f26 | Christos Stathis | displayError("System error fetching file: " + t.getMessage());
|
538 | 07a1b5fe | Christos Stathis | } |
539 | 9539e23d | Christos Stathis | |
540 | 9539e23d | Christos Stathis | @Override
|
541 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
542 | 9539e23d | Christos Stathis | sessionExpired(); |
543 | 9539e23d | Christos Stathis | } |
544 | 07a1b5fe | Christos Stathis | }; |
545 | 07a1b5fe | Christos Stathis | getFile.setHeader("X-Auth-Token", "0000"); |
546 | 07a1b5fe | Christos Stathis | Scheduler.get().scheduleDeferred(getFile); |
547 | 07a1b5fe | Christos Stathis | } |
548 | 07a1b5fe | Christos Stathis | else
|
549 | 07a1b5fe | Christos Stathis | fileList.setFiles(new ArrayList<File>(files)); |
550 | 875a0179 | Christos Stathis | } |
551 | 875a0179 | Christos Stathis | |
552 | 875a0179 | Christos Stathis | /**
|
553 | a57faaf0 | Christos Stathis | * Parse and store the user credentials to the appropriate fields.
|
554 | a57faaf0 | Christos Stathis | */
|
555 | 6084aa02 | Christos Stathis | private boolean parseUserCredentials() { |
556 | 36dc8e18 | Christos Stathis | username = Window.Location.getParameter("user"); |
557 | 36dc8e18 | Christos Stathis | token = Window.Location.getParameter("token"); |
558 | 36dc8e18 | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
559 | 36dc8e18 | Christos Stathis | if (username == null || username.length() == 0 || token == null || token.length() == 0) { |
560 | 36dc8e18 | Christos Stathis | String cookie = conf.authCookie();
|
561 | 36dc8e18 | Christos Stathis | String auth = Cookies.getCookie(cookie);
|
562 | 36dc8e18 | Christos Stathis | if (auth == null) { |
563 | 6084aa02 | Christos Stathis | authenticateUser(); |
564 | 6084aa02 | Christos Stathis | return false; |
565 | 6084aa02 | Christos Stathis | } |
566 | 7811b9d1 | Christos Stathis | String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); |
567 | 7811b9d1 | Christos Stathis | if (authSplit.length != 2) { |
568 | 7811b9d1 | Christos Stathis | authenticateUser(); |
569 | 7811b9d1 | Christos Stathis | return false; |
570 | 7811b9d1 | Christos Stathis | } |
571 | 7811b9d1 | Christos Stathis | username = authSplit[0];
|
572 | 7811b9d1 | Christos Stathis | token = authSplit[1];
|
573 | 7811b9d1 | Christos Stathis | return true; |
574 | 36dc8e18 | Christos Stathis | } |
575 | 8ddf07ab | Christos Stathis | |
576 | 8ddf07ab | Christos Stathis | Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token, null, "", "/", false); |
577 | 7811b9d1 | Christos Stathis | return true; |
578 | 36dc8e18 | Christos Stathis | } |
579 | a57faaf0 | Christos Stathis | |
580 | 6084aa02 | Christos Stathis | /**
|
581 | a57faaf0 | Christos Stathis | * Redirect the user to the login page for authentication.
|
582 | a57faaf0 | Christos Stathis | */
|
583 | a57faaf0 | Christos Stathis | protected void authenticateUser() { |
584 | 6084aa02 | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
585 | c5cf124e | Christos Stathis | Window.Location.assign(conf.loginUrl() + "?next=" + Window.Location.getHref()); |
586 | a57faaf0 | Christos Stathis | } |
587 | a57faaf0 | Christos Stathis | |
588 | 64f42c0b | Christos Stathis | protected void fetchAccount(final Command callback) { |
589 | b51c628b | Christos Stathis | String path = "?format=json"; |
590 | 7c818c14 | Christos Stathis | |
591 | b51c628b | Christos Stathis | GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
|
592 | 7c818c14 | Christos Stathis | @Override
|
593 | 7811b9d1 | Christos Stathis | public void onSuccess(AccountResource _result) { |
594 | 7811b9d1 | Christos Stathis | account = _result; |
595 | 64f42c0b | Christos Stathis | if (callback != null) |
596 | 64f42c0b | Christos Stathis | callback.execute(); |
597 | 7c818c14 | Christos Stathis | } |
598 | 7c818c14 | Christos Stathis | |
599 | 7c818c14 | Christos Stathis | @Override
|
600 | 7c818c14 | Christos Stathis | public void onError(Throwable t) { |
601 | 7c818c14 | Christos Stathis | GWT.log("Error getting account", t);
|
602 | 7c818c14 | Christos Stathis | if (t instanceof RestException) |
603 | a7c43f26 | Christos Stathis | displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
604 | 7c818c14 | Christos Stathis | else
|
605 | a7c43f26 | Christos Stathis | displayError("System error fetching user data: " + t.getMessage());
|
606 | 7c818c14 | Christos Stathis | } |
607 | 9539e23d | Christos Stathis | |
608 | 9539e23d | Christos Stathis | @Override
|
609 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
610 | 9539e23d | Christos Stathis | sessionExpired(); |
611 | 9539e23d | Christos Stathis | } |
612 | 7c818c14 | Christos Stathis | }; |
613 | 875a0179 | Christos Stathis | getAccount.setHeader("X-Auth-Token", token);
|
614 | 7c818c14 | Christos Stathis | Scheduler.get().scheduleDeferred(getAccount); |
615 | 7c818c14 | Christos Stathis | } |
616 | 7c818c14 | Christos Stathis | |
617 | 64f42c0b | Christos Stathis | public void updateStatistics() { |
618 | 64f42c0b | Christos Stathis | HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) { |
619 | 64f42c0b | Christos Stathis | |
620 | 64f42c0b | Christos Stathis | @Override
|
621 | abd8738f | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") AccountResource _result) { |
622 | 64f42c0b | Christos Stathis | showStatistics(); |
623 | 64f42c0b | Christos Stathis | } |
624 | 64f42c0b | Christos Stathis | |
625 | 64f42c0b | Christos Stathis | @Override
|
626 | 64f42c0b | Christos Stathis | public void onError(Throwable t) { |
627 | 64f42c0b | Christos Stathis | GWT.log("Error getting account", t);
|
628 | 64f42c0b | Christos Stathis | if (t instanceof RestException) |
629 | 64f42c0b | Christos Stathis | displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
630 | 64f42c0b | Christos Stathis | else
|
631 | 64f42c0b | Christos Stathis | displayError("System error fetching user data: " + t.getMessage());
|
632 | 64f42c0b | Christos Stathis | } |
633 | 9539e23d | Christos Stathis | |
634 | 9539e23d | Christos Stathis | @Override
|
635 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
636 | 9539e23d | Christos Stathis | sessionExpired(); |
637 | 9539e23d | Christos Stathis | } |
638 | 64f42c0b | Christos Stathis | }; |
639 | 64f42c0b | Christos Stathis | headAccount.setHeader("X-Auth-Token", token);
|
640 | 64f42c0b | Christos Stathis | Scheduler.get().scheduleDeferred(headAccount); |
641 | 64f42c0b | Christos Stathis | } |
642 | 64f42c0b | Christos Stathis | |
643 | 64f42c0b | Christos Stathis | protected void showStatistics() { |
644 | bf664298 | Christos Stathis | usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
|
645 | bf664298 | Christos Stathis | totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
|
646 | 29b2177c | Christos Stathis | NumberFormat nf = NumberFormat.getPercentFormat(); |
647 | 29b2177c | Christos Stathis | usedPercent.setHTML(nf.format(account.getUsedPercentage())); |
648 | bf664298 | Christos Stathis | } |
649 | bf664298 | Christos Stathis | |
650 | abd8738f | Christos Stathis | protected void createHomeContainer(final AccountResource _account, final Command callback) { |
651 | 7b28ae07 | Christos Stathis | String path = "/" + Pithos.HOME_CONTAINER; |
652 | b51c628b | Christos Stathis | PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
|
653 | b8822fe7 | Christos Stathis | @Override
|
654 | 7811b9d1 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
655 | abd8738f | Christos Stathis | if (!_account.hasTrashContainer())
|
656 | 64f42c0b | Christos Stathis | createTrashContainer(callback); |
657 | 7b28ae07 | Christos Stathis | else
|
658 | 64f42c0b | Christos Stathis | fetchAccount(callback); |
659 | b8822fe7 | Christos Stathis | } |
660 | b8822fe7 | Christos Stathis | |
661 | b8822fe7 | Christos Stathis | @Override
|
662 | b8822fe7 | Christos Stathis | public void onError(Throwable t) { |
663 | b8822fe7 | Christos Stathis | GWT.log("Error creating pithos", t);
|
664 | b8822fe7 | Christos Stathis | if (t instanceof RestException) |
665 | a7c43f26 | Christos Stathis | displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
|
666 | b8822fe7 | Christos Stathis | else
|
667 | a7c43f26 | Christos Stathis | displayError("System error Error creating pithos: " + t.getMessage());
|
668 | b8822fe7 | Christos Stathis | } |
669 | 9539e23d | Christos Stathis | |
670 | 9539e23d | Christos Stathis | @Override
|
671 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
672 | 9539e23d | Christos Stathis | sessionExpired(); |
673 | 9539e23d | Christos Stathis | } |
674 | b8822fe7 | Christos Stathis | }; |
675 | b8822fe7 | Christos Stathis | createPithos.setHeader("X-Auth-Token", getToken());
|
676 | b8822fe7 | Christos Stathis | Scheduler.get().scheduleDeferred(createPithos); |
677 | b8822fe7 | Christos Stathis | } |
678 | b8822fe7 | Christos Stathis | |
679 | 64f42c0b | Christos Stathis | protected void createTrashContainer(final Command callback) { |
680 | 7b28ae07 | Christos Stathis | String path = "/" + Pithos.TRASH_CONTAINER; |
681 | 7b28ae07 | Christos Stathis | PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
|
682 | 7b28ae07 | Christos Stathis | @Override
|
683 | 7b28ae07 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
684 | 64f42c0b | Christos Stathis | fetchAccount(callback); |
685 | 7b28ae07 | Christos Stathis | } |
686 | 7b28ae07 | Christos Stathis | |
687 | 7b28ae07 | Christos Stathis | @Override
|
688 | 7b28ae07 | Christos Stathis | public void onError(Throwable t) { |
689 | 7b28ae07 | Christos Stathis | GWT.log("Error creating pithos", t);
|
690 | 7b28ae07 | Christos Stathis | if (t instanceof RestException) |
691 | 7b28ae07 | Christos Stathis | displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
|
692 | 7b28ae07 | Christos Stathis | else
|
693 | 7b28ae07 | Christos Stathis | displayError("System error Error creating pithos: " + t.getMessage());
|
694 | 7b28ae07 | Christos Stathis | } |
695 | 9539e23d | Christos Stathis | |
696 | 9539e23d | Christos Stathis | @Override
|
697 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
698 | 9539e23d | Christos Stathis | sessionExpired(); |
699 | 9539e23d | Christos Stathis | } |
700 | 7b28ae07 | Christos Stathis | }; |
701 | 7b28ae07 | Christos Stathis | createPithos.setHeader("X-Auth-Token", getToken());
|
702 | 7b28ae07 | Christos Stathis | Scheduler.get().scheduleDeferred(createPithos); |
703 | 7b28ae07 | Christos Stathis | } |
704 | 7b28ae07 | Christos Stathis | |
705 | 7b28ae07 | Christos Stathis | /**
|
706 | a57faaf0 | Christos Stathis | * Creates an HTML fragment that places an image & caption together, for use
|
707 | a57faaf0 | Christos Stathis | * in a group header.
|
708 | a57faaf0 | Christos Stathis | *
|
709 | a57faaf0 | Christos Stathis | * @param imageProto an image prototype for an image
|
710 | a57faaf0 | Christos Stathis | * @param caption the group caption
|
711 | a57faaf0 | Christos Stathis | * @return the header HTML fragment
|
712 | a57faaf0 | Christos Stathis | */
|
713 | a57faaf0 | Christos Stathis | private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) { |
714 | a57faaf0 | Christos Stathis | String captionHTML = "<table class='caption' cellpadding='0' " |
715 | a57faaf0 | Christos Stathis | + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() |
716 | a57faaf0 | Christos Stathis | + "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'> " |
717 | a57faaf0 | Christos Stathis | + caption + "</b></td></tr></table>";
|
718 | a57faaf0 | Christos Stathis | return captionHTML;
|
719 | a57faaf0 | Christos Stathis | } |
720 | a57faaf0 | Christos Stathis | |
721 | d7be6c23 | Christos Stathis | protected void onWindowResized(int height) { |
722 | d7be6c23 | Christos Stathis | // Adjust the split panel to take up the available room in the window.
|
723 | 0549e173 | Christos Stathis | int newHeight = height - splitPanel.getAbsoluteTop();
|
724 | d7be6c23 | Christos Stathis | if (newHeight < 1) |
725 | d7be6c23 | Christos Stathis | newHeight = 1;
|
726 | d7be6c23 | Christos Stathis | splitPanel.setHeight("" + newHeight);
|
727 | d7be6c23 | Christos Stathis | inner.setHeight("" + newHeight);
|
728 | d7be6c23 | Christos Stathis | } |
729 | a57faaf0 | Christos Stathis | |
730 | a57faaf0 | Christos Stathis | @Override
|
731 | a57faaf0 | Christos Stathis | public void onResize(ResizeEvent event) { |
732 | a57faaf0 | Christos Stathis | int height = event.getHeight();
|
733 | d7be6c23 | Christos Stathis | onWindowResized(height); |
734 | a57faaf0 | Christos Stathis | } |
735 | a57faaf0 | Christos Stathis | |
736 | a57faaf0 | Christos Stathis | /**
|
737 | a57faaf0 | Christos Stathis | * Display an error message.
|
738 | a57faaf0 | Christos Stathis | *
|
739 | a57faaf0 | Christos Stathis | * @param msg the message to display
|
740 | a57faaf0 | Christos Stathis | */
|
741 | a57faaf0 | Christos Stathis | public void displayError(String msg) { |
742 | a57faaf0 | Christos Stathis | messagePanel.displayError(msg); |
743 | a57faaf0 | Christos Stathis | } |
744 | a57faaf0 | Christos Stathis | |
745 | a57faaf0 | Christos Stathis | /**
|
746 | a57faaf0 | Christos Stathis | * Display a warning message.
|
747 | a57faaf0 | Christos Stathis | *
|
748 | a57faaf0 | Christos Stathis | * @param msg the message to display
|
749 | a57faaf0 | Christos Stathis | */
|
750 | a57faaf0 | Christos Stathis | public void displayWarning(String msg) { |
751 | a57faaf0 | Christos Stathis | messagePanel.displayWarning(msg); |
752 | a57faaf0 | Christos Stathis | } |
753 | a57faaf0 | Christos Stathis | |
754 | a57faaf0 | Christos Stathis | /**
|
755 | a57faaf0 | Christos Stathis | * Display an informational message.
|
756 | a57faaf0 | Christos Stathis | *
|
757 | a57faaf0 | Christos Stathis | * @param msg the message to display
|
758 | a57faaf0 | Christos Stathis | */
|
759 | a57faaf0 | Christos Stathis | public void displayInformation(String msg) { |
760 | a57faaf0 | Christos Stathis | messagePanel.displayInformation(msg); |
761 | a57faaf0 | Christos Stathis | } |
762 | a57faaf0 | Christos Stathis | |
763 | a57faaf0 | Christos Stathis | /**
|
764 | a57faaf0 | Christos Stathis | * Retrieve the fileList.
|
765 | a57faaf0 | Christos Stathis | *
|
766 | a57faaf0 | Christos Stathis | * @return the fileList
|
767 | a57faaf0 | Christos Stathis | */
|
768 | a57faaf0 | Christos Stathis | public FileList getFileList() {
|
769 | a57faaf0 | Christos Stathis | return fileList;
|
770 | a57faaf0 | Christos Stathis | } |
771 | a57faaf0 | Christos Stathis | |
772 | a57faaf0 | Christos Stathis | /**
|
773 | a57faaf0 | Christos Stathis | * Retrieve the topPanel.
|
774 | a57faaf0 | Christos Stathis | *
|
775 | a57faaf0 | Christos Stathis | * @return the topPanel
|
776 | a57faaf0 | Christos Stathis | */
|
777 | a57faaf0 | Christos Stathis | TopPanel getTopPanel() { |
778 | a57faaf0 | Christos Stathis | return topPanel;
|
779 | a57faaf0 | Christos Stathis | } |
780 | a57faaf0 | Christos Stathis | |
781 | a57faaf0 | Christos Stathis | /**
|
782 | a57faaf0 | Christos Stathis | * Retrieve the clipboard.
|
783 | a57faaf0 | Christos Stathis | *
|
784 | a57faaf0 | Christos Stathis | * @return the clipboard
|
785 | a57faaf0 | Christos Stathis | */
|
786 | a57faaf0 | Christos Stathis | public Clipboard getClipboard() { |
787 | a57faaf0 | Christos Stathis | return clipboard;
|
788 | a57faaf0 | Christos Stathis | } |
789 | a57faaf0 | Christos Stathis | |
790 | a57faaf0 | Christos Stathis | public StatusPanel getStatusPanel() {
|
791 | a57faaf0 | Christos Stathis | return statusPanel;
|
792 | a57faaf0 | Christos Stathis | } |
793 | a57faaf0 | Christos Stathis | |
794 | a57faaf0 | Christos Stathis | public String getToken() { |
795 | a57faaf0 | Christos Stathis | return token;
|
796 | a57faaf0 | Christos Stathis | } |
797 | a57faaf0 | Christos Stathis | |
798 | a57faaf0 | Christos Stathis | public static native void preventIESelection() /*-{ |
799 | a57faaf0 | Christos Stathis | $doc.body.onselectstart = function () { return false; };
|
800 | a57faaf0 | Christos Stathis | }-*/;
|
801 | a57faaf0 | Christos Stathis | |
802 | a57faaf0 | Christos Stathis | public static native void enableIESelection() /*-{ |
803 | a57faaf0 | Christos Stathis | if ($doc.body.onselectstart != null)
|
804 | a57faaf0 | Christos Stathis | $doc.body.onselectstart = null;
|
805 | a57faaf0 | Christos Stathis | }-*/;
|
806 | a57faaf0 | Christos Stathis | |
807 | a57faaf0 | Christos Stathis | /**
|
808 | a57faaf0 | Christos Stathis | * @return the absolute path of the API root URL
|
809 | a57faaf0 | Christos Stathis | */
|
810 | a57faaf0 | Christos Stathis | public String getApiPath() { |
811 | a57faaf0 | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
812 | 6084aa02 | Christos Stathis | return conf.apiPath();
|
813 | a57faaf0 | Christos Stathis | } |
814 | a57faaf0 | Christos Stathis | |
815 | a57faaf0 | Christos Stathis | /**
|
816 | a57faaf0 | Christos Stathis | * History support for folder navigation
|
817 | a57faaf0 | Christos Stathis | * adds a new browser history entry
|
818 | a57faaf0 | Christos Stathis | *
|
819 | a57faaf0 | Christos Stathis | * @param key
|
820 | a57faaf0 | Christos Stathis | */
|
821 | a57faaf0 | Christos Stathis | public void updateHistory(String key){ |
822 | a57faaf0 | Christos Stathis | // Replace any whitespace of the initial string to "+"
|
823 | a57faaf0 | Christos Stathis | // String result = key.replaceAll("\\s","+");
|
824 | a57faaf0 | Christos Stathis | // Add a new browser history entry.
|
825 | a57faaf0 | Christos Stathis | // History.newItem(result);
|
826 | a57faaf0 | Christos Stathis | History.newItem(key); |
827 | a57faaf0 | Christos Stathis | } |
828 | a57faaf0 | Christos Stathis | |
829 | 602ebeb4 | Christos Stathis | public void deleteFolder(final Folder folder) { |
830 | f5023f13 | Christos Stathis | String path = getApiPath() + folder.getOwner() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(folder.getPrefix()) + "&t=" + System.currentTimeMillis(); |
831 | 602ebeb4 | Christos Stathis | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
832 | 602ebeb4 | Christos Stathis | builder.setHeader("X-Auth-Token", getToken());
|
833 | 602ebeb4 | Christos Stathis | try {
|
834 | 602ebeb4 | Christos Stathis | builder.sendRequest("", new RequestCallback() { |
835 | 602ebeb4 | Christos Stathis | @Override
|
836 | 7811b9d1 | Christos Stathis | public void onResponseReceived(@SuppressWarnings("unused") Request request, Response response) { |
837 | 602ebeb4 | Christos Stathis | if (response.getStatusCode() == Response.SC_OK) {
|
838 | 602ebeb4 | Christos Stathis | JSONValue json = JSONParser.parseStrict(response.getText()); |
839 | 602ebeb4 | Christos Stathis | JSONArray array = json.isArray(); |
840 | 602ebeb4 | Christos Stathis | int i = 0; |
841 | 602ebeb4 | Christos Stathis | if (array != null) { |
842 | 602ebeb4 | Christos Stathis | deleteObject(folder, i, array); |
843 | 602ebeb4 | Christos Stathis | } |
844 | 602ebeb4 | Christos Stathis | } |
845 | 602ebeb4 | Christos Stathis | } |
846 | 602ebeb4 | Christos Stathis | |
847 | 602ebeb4 | Christos Stathis | @Override
|
848 | 7811b9d1 | Christos Stathis | public void onError(@SuppressWarnings("unused") Request request, Throwable exception) { |
849 | a7c43f26 | Christos Stathis | displayError("System error unable to delete folder: " + exception.getMessage());
|
850 | 602ebeb4 | Christos Stathis | } |
851 | 602ebeb4 | Christos Stathis | }); |
852 | 602ebeb4 | Christos Stathis | } |
853 | 602ebeb4 | Christos Stathis | catch (RequestException e) {
|
854 | 602ebeb4 | Christos Stathis | } |
855 | 602ebeb4 | Christos Stathis | } |
856 | 602ebeb4 | Christos Stathis | |
857 | 64f42c0b | Christos Stathis | void deleteObject(final Folder folder, final int i, final JSONArray array) { |
858 | 602ebeb4 | Christos Stathis | if (i < array.size()) {
|
859 | 602ebeb4 | Christos Stathis | JSONObject o = array.get(i).isObject(); |
860 | 602ebeb4 | Christos Stathis | if (o != null && !o.containsKey("subdir")) { |
861 | 602ebeb4 | Christos Stathis | JSONString name = o.get("name").isString();
|
862 | b51c628b | Christos Stathis | String path = "/" + folder.getContainer() + "/" + name.stringValue(); |
863 | 63ee965c | Christos Stathis | DeleteRequest delete = new DeleteRequest(getApiPath(), folder.getOwner(), path) {
|
864 | 602ebeb4 | Christos Stathis | @Override
|
865 | 7811b9d1 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
866 | 602ebeb4 | Christos Stathis | deleteObject(folder, i + 1, array);
|
867 | 602ebeb4 | Christos Stathis | } |
868 | 602ebeb4 | Christos Stathis | |
869 | 602ebeb4 | Christos Stathis | @Override
|
870 | 602ebeb4 | Christos Stathis | public void onError(Throwable t) { |
871 | 602ebeb4 | Christos Stathis | GWT.log("", t);
|
872 | a7c43f26 | Christos Stathis | displayError("System error unable to delete folder: " + t.getMessage());
|
873 | 602ebeb4 | Christos Stathis | } |
874 | 9539e23d | Christos Stathis | |
875 | 9539e23d | Christos Stathis | @Override
|
876 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
877 | 9539e23d | Christos Stathis | sessionExpired(); |
878 | 9539e23d | Christos Stathis | } |
879 | 602ebeb4 | Christos Stathis | }; |
880 | 602ebeb4 | Christos Stathis | delete.setHeader("X-Auth-Token", getToken());
|
881 | 602ebeb4 | Christos Stathis | Scheduler.get().scheduleDeferred(delete); |
882 | 602ebeb4 | Christos Stathis | } |
883 | 7811b9d1 | Christos Stathis | else if (o != null) { |
884 | 602ebeb4 | Christos Stathis | String subdir = o.get("subdir").isString().stringValue(); |
885 | 602ebeb4 | Christos Stathis | subdir = subdir.substring(0, subdir.length() - 1); |
886 | f5023f13 | Christos Stathis | String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis(); |
887 | 602ebeb4 | Christos Stathis | RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
888 | 602ebeb4 | Christos Stathis | builder.setHeader("X-Auth-Token", getToken());
|
889 | 602ebeb4 | Christos Stathis | try {
|
890 | 602ebeb4 | Christos Stathis | builder.sendRequest("", new RequestCallback() { |
891 | 602ebeb4 | Christos Stathis | @Override
|
892 | 7811b9d1 | Christos Stathis | public void onResponseReceived(@SuppressWarnings("unused") Request request, Response response) { |
893 | 602ebeb4 | Christos Stathis | if (response.getStatusCode() == Response.SC_OK) {
|
894 | 602ebeb4 | Christos Stathis | JSONValue json = JSONParser.parseStrict(response.getText()); |
895 | 602ebeb4 | Christos Stathis | JSONArray array2 = json.isArray(); |
896 | 602ebeb4 | Christos Stathis | if (array2 != null) { |
897 | 602ebeb4 | Christos Stathis | int l = array.size();
|
898 | 602ebeb4 | Christos Stathis | for (int j=0; j<array2.size(); j++) { |
899 | 602ebeb4 | Christos Stathis | array.set(l++, array2.get(j)); |
900 | 602ebeb4 | Christos Stathis | } |
901 | 602ebeb4 | Christos Stathis | } |
902 | 602ebeb4 | Christos Stathis | deleteObject(folder, i + 1, array);
|
903 | 602ebeb4 | Christos Stathis | } |
904 | 602ebeb4 | Christos Stathis | } |
905 | 602ebeb4 | Christos Stathis | |
906 | 602ebeb4 | Christos Stathis | @Override
|
907 | 7811b9d1 | Christos Stathis | public void onError(@SuppressWarnings("unused") Request request, Throwable exception) { |
908 | a7c43f26 | Christos Stathis | displayError("System error unable to delete folder: " + exception.getMessage());
|
909 | 602ebeb4 | Christos Stathis | } |
910 | 602ebeb4 | Christos Stathis | }); |
911 | 602ebeb4 | Christos Stathis | } |
912 | 602ebeb4 | Christos Stathis | catch (RequestException e) {
|
913 | 602ebeb4 | Christos Stathis | } |
914 | 602ebeb4 | Christos Stathis | } |
915 | 602ebeb4 | Christos Stathis | } |
916 | 602ebeb4 | Christos Stathis | else {
|
917 | b51c628b | Christos Stathis | String path = folder.getUri();
|
918 | b51c628b | Christos Stathis | DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), path) {
|
919 | 602ebeb4 | Christos Stathis | @Override
|
920 | 7811b9d1 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
921 | 64f42c0b | Christos Stathis | updateFolder(folder.getParent(), true, new Command() { |
922 | 64f42c0b | Christos Stathis | |
923 | 64f42c0b | Christos Stathis | @Override
|
924 | 64f42c0b | Christos Stathis | public void execute() { |
925 | 64f42c0b | Christos Stathis | updateStatistics(); |
926 | 64f42c0b | Christos Stathis | } |
927 | 64f42c0b | Christos Stathis | }); |
928 | 602ebeb4 | Christos Stathis | } |
929 | 602ebeb4 | Christos Stathis | |
930 | 602ebeb4 | Christos Stathis | @Override
|
931 | 602ebeb4 | Christos Stathis | public void onError(Throwable t) { |
932 | 602ebeb4 | Christos Stathis | GWT.log("", t);
|
933 | 602ebeb4 | Christos Stathis | if (t instanceof RestException) { |
934 | 7b28ae07 | Christos Stathis | if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND)
|
935 | 7b28ae07 | Christos Stathis | displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
|
936 | 7b28ae07 | Christos Stathis | else
|
937 | 7b28ae07 | Christos Stathis | onSuccess(null);
|
938 | 602ebeb4 | Christos Stathis | } |
939 | 602ebeb4 | Christos Stathis | else
|
940 | a7c43f26 | Christos Stathis | displayError("System error unable to delete folder: " + t.getMessage());
|
941 | 602ebeb4 | Christos Stathis | } |
942 | 9539e23d | Christos Stathis | |
943 | 9539e23d | Christos Stathis | @Override
|
944 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
945 | 9539e23d | Christos Stathis | sessionExpired(); |
946 | 9539e23d | Christos Stathis | } |
947 | 602ebeb4 | Christos Stathis | }; |
948 | 602ebeb4 | Christos Stathis | deleteFolder.setHeader("X-Auth-Token", getToken());
|
949 | 602ebeb4 | Christos Stathis | Scheduler.get().scheduleDeferred(deleteFolder); |
950 | 602ebeb4 | Christos Stathis | } |
951 | 602ebeb4 | Christos Stathis | } |
952 | fad48f0d | Christos Stathis | |
953 | fad48f0d | Christos Stathis | public FolderTreeView getFolderTreeView() {
|
954 | fad48f0d | Christos Stathis | return folderTreeView;
|
955 | fad48f0d | Christos Stathis | } |
956 | d6be39da | Christos Stathis | |
957 | 63ee965c | Christos Stathis | public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) { |
958 | d6be39da | Christos Stathis | if (iter.hasNext()) {
|
959 | d6be39da | Christos Stathis | File file = iter.next();
|
960 | b51c628b | Christos Stathis | String path = targetUri + "/" + file.getName(); |
961 | 63ee965c | Christos Stathis | PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
|
962 | d6be39da | Christos Stathis | @Override
|
963 | 7811b9d1 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
964 | 63ee965c | Christos Stathis | copyFiles(iter, targetUsername, targetUri, callback); |
965 | d6be39da | Christos Stathis | } |
966 | d6be39da | Christos Stathis | |
967 | d6be39da | Christos Stathis | @Override
|
968 | d6be39da | Christos Stathis | public void onError(Throwable t) { |
969 | d6be39da | Christos Stathis | GWT.log("", t);
|
970 | d6be39da | Christos Stathis | if (t instanceof RestException) { |
971 | a7c43f26 | Christos Stathis | displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
|
972 | d6be39da | Christos Stathis | } |
973 | d6be39da | Christos Stathis | else
|
974 | a7c43f26 | Christos Stathis | displayError("System error unable to copy file: "+t.getMessage());
|
975 | d6be39da | Christos Stathis | } |
976 | 9539e23d | Christos Stathis | |
977 | 9539e23d | Christos Stathis | @Override
|
978 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
979 | 9539e23d | Christos Stathis | sessionExpired(); |
980 | 9539e23d | Christos Stathis | } |
981 | d6be39da | Christos Stathis | }; |
982 | d6be39da | Christos Stathis | copyFile.setHeader("X-Auth-Token", getToken());
|
983 | d6be39da | Christos Stathis | copyFile.setHeader("X-Copy-From", file.getUri());
|
984 | 43c372e8 | Christos Stathis | if (!file.getOwner().equals(targetUsername))
|
985 | 43c372e8 | Christos Stathis | copyFile.setHeader("X-Source-Account", file.getOwner());
|
986 | d6be39da | Christos Stathis | Scheduler.get().scheduleDeferred(copyFile); |
987 | d6be39da | Christos Stathis | } |
988 | d6be39da | Christos Stathis | else if (callback != null) { |
989 | d6be39da | Christos Stathis | callback.execute(); |
990 | d6be39da | Christos Stathis | } |
991 | d6be39da | Christos Stathis | } |
992 | d6be39da | Christos Stathis | |
993 | 63ee965c | Christos Stathis | public void copySubfolders(final Iterator<Folder> iter, final String targetUsername, final String targetUri, final Command callback) { |
994 | d6be39da | Christos Stathis | if (iter.hasNext()) {
|
995 | d6be39da | Christos Stathis | final Folder f = iter.next();
|
996 | acbb73ac | Christos Stathis | copyFolder(f, targetUsername, targetUri, new Command() {
|
997 | acbb73ac | Christos Stathis | |
998 | acbb73ac | Christos Stathis | @Override
|
999 | acbb73ac | Christos Stathis | public void execute() { |
1000 | acbb73ac | Christos Stathis | copySubfolders(iter, targetUsername, targetUri, callback); |
1001 | acbb73ac | Christos Stathis | } |
1002 | acbb73ac | Christos Stathis | }); |
1003 | d6be39da | Christos Stathis | } |
1004 | d6be39da | Christos Stathis | else if (callback != null) { |
1005 | d6be39da | Christos Stathis | callback.execute(); |
1006 | d6be39da | Christos Stathis | } |
1007 | d6be39da | Christos Stathis | } |
1008 | d6be39da | Christos Stathis | |
1009 | 63ee965c | Christos Stathis | public void copyFolder(final Folder f, final String targetUsername, final String targetUri, final Command callback) { |
1010 | b51c628b | Christos Stathis | String path = targetUri + "/" + f.getName(); |
1011 | 63ee965c | Christos Stathis | PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) {
|
1012 | d6be39da | Christos Stathis | @Override
|
1013 | 7811b9d1 | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
1014 | f5023f13 | Christos Stathis | GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) { |
1015 | acbb73ac | Christos Stathis | |
1016 | acbb73ac | Christos Stathis | @Override
|
1017 | abd8738f | Christos Stathis | public void onSuccess(final Folder _f) { |
1018 | abd8738f | Christos Stathis | Iterator<File> iter = _f.getFiles().iterator(); |
1019 | abd8738f | Christos Stathis | copyFiles(iter, targetUsername, targetUri + "/" + _f.getName(), new Command() { |
1020 | acbb73ac | Christos Stathis | @Override
|
1021 | acbb73ac | Christos Stathis | public void execute() { |
1022 | abd8738f | Christos Stathis | Iterator<Folder> iterf = _f.getSubfolders().iterator();
|
1023 | abd8738f | Christos Stathis | copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback);
|
1024 | acbb73ac | Christos Stathis | } |
1025 | acbb73ac | Christos Stathis | }); |
1026 | acbb73ac | Christos Stathis | } |
1027 | acbb73ac | Christos Stathis | |
1028 | acbb73ac | Christos Stathis | @Override
|
1029 | acbb73ac | Christos Stathis | public void onError(Throwable t) { |
1030 | acbb73ac | Christos Stathis | GWT.log("", t);
|
1031 | acbb73ac | Christos Stathis | if (t instanceof RestException) { |
1032 | acbb73ac | Christos Stathis | displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
|
1033 | acbb73ac | Christos Stathis | } |
1034 | acbb73ac | Christos Stathis | else
|
1035 | acbb73ac | Christos Stathis | displayError("System error getting folder: " + t.getMessage());
|
1036 | acbb73ac | Christos Stathis | } |
1037 | 9539e23d | Christos Stathis | |
1038 | 9539e23d | Christos Stathis | @Override
|
1039 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
1040 | 9539e23d | Christos Stathis | sessionExpired(); |
1041 | 9539e23d | Christos Stathis | } |
1042 | acbb73ac | Christos Stathis | }; |
1043 | acbb73ac | Christos Stathis | getFolder.setHeader("X-Auth-Token", getToken());
|
1044 | acbb73ac | Christos Stathis | Scheduler.get().scheduleDeferred(getFolder); |
1045 | d6be39da | Christos Stathis | } |
1046 | d6be39da | Christos Stathis | |
1047 | d6be39da | Christos Stathis | @Override
|
1048 | d6be39da | Christos Stathis | public void onError(Throwable t) { |
1049 | d6be39da | Christos Stathis | GWT.log("", t);
|
1050 | d6be39da | Christos Stathis | if (t instanceof RestException) { |
1051 | acbb73ac | Christos Stathis | displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText());
|
1052 | d6be39da | Christos Stathis | } |
1053 | d6be39da | Christos Stathis | else
|
1054 | acbb73ac | Christos Stathis | displayError("System error creating folder: " + t.getMessage());
|
1055 | d6be39da | Christos Stathis | } |
1056 | 9539e23d | Christos Stathis | |
1057 | 9539e23d | Christos Stathis | @Override
|
1058 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
1059 | 9539e23d | Christos Stathis | sessionExpired(); |
1060 | 9539e23d | Christos Stathis | } |
1061 | d6be39da | Christos Stathis | }; |
1062 | d6be39da | Christos Stathis | createFolder.setHeader("X-Auth-Token", getToken());
|
1063 | d6be39da | Christos Stathis | createFolder.setHeader("Accept", "*/*"); |
1064 | d6be39da | Christos Stathis | createFolder.setHeader("Content-Length", "0"); |
1065 | d6be39da | Christos Stathis | createFolder.setHeader("Content-Type", "application/folder"); |
1066 | d6be39da | Christos Stathis | Scheduler.get().scheduleDeferred(createFolder); |
1067 | d6be39da | Christos Stathis | } |
1068 | 105b4e49 | Christos Stathis | |
1069 | 7811b9d1 | Christos Stathis | public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) { |
1070 | 105b4e49 | Christos Stathis | selectionModels.add(model); |
1071 | 105b4e49 | Christos Stathis | } |
1072 | 6d8e0f58 | Christos Stathis | |
1073 | 6d8e0f58 | Christos Stathis | public OtherSharedTreeView getOtherSharedTreeView() {
|
1074 | 6d8e0f58 | Christos Stathis | return otherSharedTreeView;
|
1075 | 6d8e0f58 | Christos Stathis | } |
1076 | 16e8478a | Christos Stathis | |
1077 | 16e8478a | Christos Stathis | public void updateTrash(boolean showFiles, Command callback) { |
1078 | 16e8478a | Christos Stathis | updateFolder(trash, showFiles, callback); |
1079 | 16e8478a | Christos Stathis | } |
1080 | 4baffab1 | Christos Stathis | |
1081 | 4baffab1 | Christos Stathis | public void updateGroupsNode() { |
1082 | 4baffab1 | Christos Stathis | groupTreeView.updateGroupNode(null);
|
1083 | 4baffab1 | Christos Stathis | } |
1084 | 4baffab1 | Christos Stathis | |
1085 | 4baffab1 | Christos Stathis | public void addGroup(String groupname) { |
1086 | 4baffab1 | Christos Stathis | Group newGroup = new Group(groupname); |
1087 | 4baffab1 | Christos Stathis | account.addGroup(newGroup); |
1088 | 4baffab1 | Christos Stathis | groupTreeView.updateGroupNode(null);
|
1089 | 4baffab1 | Christos Stathis | } |
1090 | 61f8605d | Christos Stathis | |
1091 | 61f8605d | Christos Stathis | public void removeGroup(Group group) { |
1092 | 61f8605d | Christos Stathis | account.removeGroup(group); |
1093 | 61f8605d | Christos Stathis | updateGroupsNode(); |
1094 | 61f8605d | Christos Stathis | } |
1095 | f1b24b82 | Christos Stathis | |
1096 | f1b24b82 | Christos Stathis | public TreeView getSelectedTree() {
|
1097 | f1b24b82 | Christos Stathis | return selectedTree;
|
1098 | f1b24b82 | Christos Stathis | } |
1099 | f1b24b82 | Christos Stathis | |
1100 | f1b24b82 | Christos Stathis | public Folder getSelection() {
|
1101 | f1b24b82 | Christos Stathis | return selectedTree.getSelection();
|
1102 | f1b24b82 | Christos Stathis | } |
1103 | a19f758c | Christos Stathis | |
1104 | a19f758c | Christos Stathis | public void showFolderStatistics(int folderFileCount) { |
1105 | a19f758c | Christos Stathis | numOfFiles.setHTML(String.valueOf(folderFileCount));
|
1106 | a19f758c | Christos Stathis | } |
1107 | b162dfaa | Christos Stathis | |
1108 | b162dfaa | Christos Stathis | public GroupTreeView getGroupTreeView() {
|
1109 | b162dfaa | Christos Stathis | return groupTreeView;
|
1110 | b162dfaa | Christos Stathis | } |
1111 | 9539e23d | Christos Stathis | |
1112 | 9539e23d | Christos Stathis | public void sessionExpired() { |
1113 | 9539e23d | Christos Stathis | new SessionExpiredDialog(this).center(); |
1114 | 9539e23d | Christos Stathis | } |
1115 | 340bf0d6 | Christos Stathis | |
1116 | 340bf0d6 | Christos Stathis | public void updateRootFolder(Command callback) { |
1117 | 340bf0d6 | Christos Stathis | updateFolder(account.getPithos(), false, callback);
|
1118 | 340bf0d6 | Christos Stathis | } |
1119 | 7c54d867 | Christos Stathis | |
1120 | 7c54d867 | Christos Stathis | void createMySharedTree() {
|
1121 | 7c54d867 | Christos Stathis | mysharedTreeSelectionModel = new SingleSelectionModel<Folder>(); |
1122 | 7c54d867 | Christos Stathis | mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
1123 | 7c54d867 | Christos Stathis | @Override
|
1124 | 7c54d867 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
1125 | 7c54d867 | Christos Stathis | if (mysharedTreeSelectionModel.getSelectedObject() != null) { |
1126 | 7c54d867 | Christos Stathis | deselectOthers(mysharedTreeView, mysharedTreeSelectionModel); |
1127 | 7c54d867 | Christos Stathis | upload.setEnabled(false);
|
1128 | 7c54d867 | Christos Stathis | updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
|
1129 | 7c54d867 | Christos Stathis | } |
1130 | d7be6c23 | Christos Stathis | } |
1131 | 7c54d867 | Christos Stathis | }); |
1132 | 7c54d867 | Christos Stathis | selectionModels.add(mysharedTreeSelectionModel); |
1133 | 7c54d867 | Christos Stathis | mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel);
|
1134 | 7c54d867 | Christos Stathis | mysharedTreeViewModel.initialize(new Command() {
|
1135 | 7c54d867 | Christos Stathis | |
1136 | 7c54d867 | Christos Stathis | @Override
|
1137 | 7c54d867 | Christos Stathis | public void execute() { |
1138 | 7c54d867 | Christos Stathis | mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
|
1139 | 0549e173 | Christos Stathis | trees.insert(mysharedTreeView, 2);
|
1140 | 0549e173 | Christos Stathis | treeViews.add(mysharedTreeView); |
1141 | 7c54d867 | Christos Stathis | createOtherSharedTree(); |
1142 | 7c54d867 | Christos Stathis | } |
1143 | 7c54d867 | Christos Stathis | }); |
1144 | 7c54d867 | Christos Stathis | } |
1145 | 7c54d867 | Christos Stathis | |
1146 | 7c54d867 | Christos Stathis | void createOtherSharedTree() {
|
1147 | 7c54d867 | Christos Stathis | otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>(); |
1148 | 7c54d867 | Christos Stathis | otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
1149 | 7c54d867 | Christos Stathis | @Override
|
1150 | 7c54d867 | Christos Stathis | public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) { |
1151 | 7c54d867 | Christos Stathis | if (otherSharedTreeSelectionModel.getSelectedObject() != null) { |
1152 | 7c54d867 | Christos Stathis | deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel); |
1153 | 0549e173 | Christos Stathis | otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree");
|
1154 | 7c54d867 | Christos Stathis | applyPermissions(otherSharedTreeSelectionModel.getSelectedObject()); |
1155 | 7c54d867 | Christos Stathis | updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
|
1156 | 7c54d867 | Christos Stathis | } |
1157 | d7be6c23 | Christos Stathis | } |
1158 | 7c54d867 | Christos Stathis | }); |
1159 | 7c54d867 | Christos Stathis | selectionModels.add(otherSharedTreeSelectionModel); |
1160 | 7c54d867 | Christos Stathis | otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel);
|
1161 | 7c54d867 | Christos Stathis | otherSharedTreeViewModel.initialize(new Command() {
|
1162 | 7c54d867 | Christos Stathis | |
1163 | 7c54d867 | Christos Stathis | @Override
|
1164 | 7c54d867 | Christos Stathis | public void execute() { |
1165 | 7c54d867 | Christos Stathis | otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
|
1166 | 0549e173 | Christos Stathis | trees.insert(otherSharedTreeView, 3);
|
1167 | 0549e173 | Christos Stathis | treeViews.add(otherSharedTreeView); |
1168 | 7c54d867 | Christos Stathis | } |
1169 | 7c54d867 | Christos Stathis | }); |
1170 | 7c54d867 | Christos Stathis | } |
1171 | 4ac4833e | Christos Stathis | |
1172 | 4ac4833e | Christos Stathis | public void logoff() { |
1173 | 4ac4833e | Christos Stathis | Configuration conf = (Configuration) GWT.create(Configuration.class); |
1174 | 4ac4833e | Christos Stathis | Cookies.removeCookie(conf.authCookie()); |
1175 | f7353d58 | Christos Stathis | Cookies.removeCookie(conf.authTokenCookie(), "/");
|
1176 | f7353d58 | Christos Stathis | for (String s: Cookies.getCookieNames()) |
1177 | f7353d58 | Christos Stathis | if (s.startsWith(conf.shibSessionCookiePrefix()))
|
1178 | f7353d58 | Christos Stathis | Cookies.removeCookie(s, "/");
|
1179 | f7353d58 | Christos Stathis | Window.Location.assign(Window.Location.getPath()); |
1180 | 4ac4833e | Christos Stathis | } |
1181 | a57faaf0 | Christos Stathis | } |