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