root / src / gr / grnet / pithos / web / client / Pithos.java @ ba6ffffb
History | View | Annotate | Download (43.9 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 |
// Add the left and right panels to the split panel.
|
366 |
splitPanel.setLeftWidget(trees); |
367 |
splitPanel.setRightWidget(inner); |
368 |
splitPanel.setSplitPosition("219px");
|
369 |
splitPanel.setSize("100%", "100%"); |
370 |
splitPanel.addStyleName("pithos-splitPanel");
|
371 |
splitPanel.setWidth(contentWidth); |
372 |
outer.add(splitPanel); |
373 |
outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER); |
374 |
|
375 |
if (!bareContent) {
|
376 |
statusPanel = new StatusPanel();
|
377 |
statusPanel.setWidth("100%");
|
378 |
outer.add(statusPanel); |
379 |
outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER); |
380 |
} |
381 |
else
|
382 |
splitPanel.addStyleName("pithos-splitPanel-noframe");
|
383 |
|
384 |
// Hook the window resize event, so that we can adjust the UI.
|
385 |
Window.addResizeHandler(this); |
386 |
// Clear out the window's built-in margin, because we want to take
|
387 |
// advantage of the entire client area.
|
388 |
Window.setMargin("0px"); |
389 |
// Finally, add the outer panel to the RootPanel, so that it will be
|
390 |
// displayed.
|
391 |
RootPanel.get().add(outer); |
392 |
// Call the window resized handler to get the initial sizes setup. Doing
|
393 |
// this in a deferred command causes it to occur after all widgets'
|
394 |
// sizes have been computed by the browser.
|
395 |
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
396 |
|
397 |
@Override
|
398 |
public void execute() { |
399 |
onWindowResized(Window.getClientHeight());
|
400 |
} |
401 |
}); |
402 |
|
403 |
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
404 |
@Override
|
405 |
public void execute() { |
406 |
fetchAccount(new Command() {
|
407 |
|
408 |
@Override
|
409 |
public void execute() { |
410 |
if (!account.hasHomeContainer())
|
411 |
createHomeContainer(account, this);
|
412 |
else if (!account.hasTrashContainer()) |
413 |
createTrashContainer(this);
|
414 |
else {
|
415 |
for (Folder f : account.getContainers())
|
416 |
if (f.getName().equals(Pithos.TRASH_CONTAINER)) {
|
417 |
trash = f; |
418 |
break;
|
419 |
} |
420 |
trees.add(folderTreeView); |
421 |
folderTreeViewModel.initialize(account, new Command() {
|
422 |
|
423 |
@Override
|
424 |
public void execute() { |
425 |
createMySharedTree(); |
426 |
} |
427 |
}); |
428 |
|
429 |
HorizontalPanel separator = new HorizontalPanel();
|
430 |
separator.addStyleName("pithos-statisticsSeparator");
|
431 |
separator.add(new HTML("")); |
432 |
trees.add(separator); |
433 |
|
434 |
groupTreeViewModel = new GroupTreeViewModel(Pithos.this);
|
435 |
groupTreeView = new GroupTreeView(groupTreeViewModel);
|
436 |
treeViews.add(groupTreeView); |
437 |
trees.add(groupTreeView); |
438 |
folderTreeView.showStatistics(account); |
439 |
} |
440 |
} |
441 |
}); |
442 |
} |
443 |
}); |
444 |
|
445 |
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
|
446 |
|
447 |
@Override
|
448 |
public boolean execute() { |
449 |
Folder f = getSelection(); |
450 |
if (f != null) { |
451 |
if (getSelectedTree().equals(folderTreeView))
|
452 |
updateFolder(f, true, null, false); |
453 |
else if (getSelectedTree().equals(mysharedTreeView)) |
454 |
updateSharedFolder(f, true);
|
455 |
} |
456 |
return true; |
457 |
} |
458 |
}, 3000);
|
459 |
} |
460 |
|
461 |
public void applyPermissions(Folder f) { |
462 |
if (f != null) { |
463 |
if (f.isInTrash())
|
464 |
upload.setEnabled(false);
|
465 |
else {
|
466 |
Boolean[] perms = f.getPermissions().get(username); |
467 |
if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) { |
468 |
upload.setEnabled(true);
|
469 |
} |
470 |
else
|
471 |
upload.setEnabled(false);
|
472 |
} |
473 |
} |
474 |
else
|
475 |
upload.setEnabled(false);
|
476 |
} |
477 |
|
478 |
@SuppressWarnings({ "rawtypes", "unchecked" }) |
479 |
public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) { |
480 |
selectedTree = _selectedTree; |
481 |
|
482 |
for (SingleSelectionModel s : selectionModels) |
483 |
if (!s.equals(model) && s.getSelectedObject() != null) |
484 |
s.setSelected(s.getSelectedObject(), false);
|
485 |
} |
486 |
|
487 |
public void showFiles(final Folder f) { |
488 |
Set<File> files = f.getFiles(); |
489 |
showFiles(files); |
490 |
} |
491 |
|
492 |
public void showFiles(Set<File> files) { |
493 |
fileList.setFiles(new ArrayList<File>(files)); |
494 |
} |
495 |
|
496 |
/**
|
497 |
* Parse and store the user credentials to the appropriate fields.
|
498 |
*/
|
499 |
private boolean parseUserCredentials() { |
500 |
Configuration conf = (Configuration) GWT.create(Configuration.class); |
501 |
Dictionary otherProperties = Dictionary.getDictionary("otherProperties"); |
502 |
String cookie = otherProperties.get("authCookie"); |
503 |
String auth = Cookies.getCookie(cookie);
|
504 |
if (auth == null) { |
505 |
authenticateUser(); |
506 |
return false; |
507 |
} |
508 |
if (auth.startsWith("\"")) |
509 |
auth = auth.substring(1);
|
510 |
if (auth.endsWith("\"")) |
511 |
auth = auth.substring(0, auth.length() - 1); |
512 |
String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); |
513 |
if (authSplit.length != 2) { |
514 |
authenticateUser(); |
515 |
return false; |
516 |
} |
517 |
username = authSplit[0];
|
518 |
token = authSplit[1];
|
519 |
|
520 |
String gotoUrl = Window.Location.getParameter("goto"); |
521 |
if (gotoUrl != null && gotoUrl.length() > 0) { |
522 |
Window.Location.assign(gotoUrl);
|
523 |
return false; |
524 |
} |
525 |
return true; |
526 |
} |
527 |
|
528 |
/**
|
529 |
* Redirect the user to the login page for authentication.
|
530 |
*/
|
531 |
protected void authenticateUser() { |
532 |
Dictionary otherProperties = Dictionary.getDictionary("otherProperties"); |
533 |
Window.Location.assign(otherProperties.get("loginUrl") + Window.Location.getHref()); |
534 |
} |
535 |
|
536 |
protected void fetchAccount(final Command callback) { |
537 |
String path = "?format=json"; |
538 |
|
539 |
GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
|
540 |
@Override
|
541 |
public void onSuccess(AccountResource _result) { |
542 |
account = _result; |
543 |
if (callback != null) |
544 |
callback.execute(); |
545 |
} |
546 |
|
547 |
@Override
|
548 |
public void onError(Throwable t) { |
549 |
GWT.log("Error getting account", t);
|
550 |
setError(t); |
551 |
if (t instanceof RestException) |
552 |
displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
553 |
else
|
554 |
displayError("System error fetching user data: " + t.getMessage());
|
555 |
} |
556 |
|
557 |
@Override
|
558 |
protected void onUnauthorized(Response response) { |
559 |
sessionExpired(); |
560 |
} |
561 |
}; |
562 |
getAccount.setHeader("X-Auth-Token", token);
|
563 |
Scheduler.get().scheduleDeferred(getAccount); |
564 |
} |
565 |
|
566 |
public void updateStatistics() { |
567 |
HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) { |
568 |
|
569 |
@Override
|
570 |
public void onSuccess(AccountResource _result) { |
571 |
folderTreeView.showStatistics(account); |
572 |
} |
573 |
|
574 |
@Override
|
575 |
public void onError(Throwable t) { |
576 |
GWT.log("Error getting account", t);
|
577 |
setError(t); |
578 |
if (t instanceof RestException) |
579 |
displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
|
580 |
else
|
581 |
displayError("System error fetching user data: " + t.getMessage());
|
582 |
} |
583 |
|
584 |
@Override
|
585 |
protected void onUnauthorized(Response response) { |
586 |
sessionExpired(); |
587 |
} |
588 |
}; |
589 |
headAccount.setHeader("X-Auth-Token", token);
|
590 |
Scheduler.get().scheduleDeferred(headAccount); |
591 |
} |
592 |
|
593 |
protected void createHomeContainer(final AccountResource _account, final Command callback) { |
594 |
String path = "/" + Pithos.HOME_CONTAINER; |
595 |
PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
|
596 |
@Override
|
597 |
public void onSuccess(Resource result) { |
598 |
if (!_account.hasTrashContainer())
|
599 |
createTrashContainer(callback); |
600 |
else
|
601 |
fetchAccount(callback); |
602 |
} |
603 |
|
604 |
@Override
|
605 |
public void onError(Throwable t) { |
606 |
GWT.log("Error creating pithos", t);
|
607 |
setError(t); |
608 |
if (t instanceof RestException) |
609 |
displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
|
610 |
else
|
611 |
displayError("System error Error creating pithos: " + t.getMessage());
|
612 |
} |
613 |
|
614 |
@Override
|
615 |
protected void onUnauthorized(Response response) { |
616 |
sessionExpired(); |
617 |
} |
618 |
}; |
619 |
createPithos.setHeader("X-Auth-Token", getToken());
|
620 |
Scheduler.get().scheduleDeferred(createPithos); |
621 |
} |
622 |
|
623 |
protected void createTrashContainer(final Command callback) { |
624 |
String path = "/" + Pithos.TRASH_CONTAINER; |
625 |
PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
|
626 |
@Override
|
627 |
public void onSuccess(Resource result) { |
628 |
fetchAccount(callback); |
629 |
} |
630 |
|
631 |
@Override
|
632 |
public void onError(Throwable t) { |
633 |
GWT.log("Error creating pithos", t);
|
634 |
setError(t); |
635 |
if (t instanceof RestException) |
636 |
displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
|
637 |
else
|
638 |
displayError("System error Error creating pithos: " + t.getMessage());
|
639 |
} |
640 |
|
641 |
@Override
|
642 |
protected void onUnauthorized(Response response) { |
643 |
sessionExpired(); |
644 |
} |
645 |
}; |
646 |
createPithos.setHeader("X-Auth-Token", getToken());
|
647 |
Scheduler.get().scheduleDeferred(createPithos); |
648 |
} |
649 |
|
650 |
/**
|
651 |
* Creates an HTML fragment that places an image & caption together, for use
|
652 |
* in a group header.
|
653 |
*
|
654 |
* @param imageProto an image prototype for an image
|
655 |
* @param caption the group caption
|
656 |
* @return the header HTML fragment
|
657 |
*/
|
658 |
private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) { |
659 |
String captionHTML = "<table class='caption' cellpadding='0' " |
660 |
+ "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML() |
661 |
+ "</td><td id =" + caption +" class='rcaption'><b style='white-space:nowrap'> " |
662 |
+ caption + "</b></td></tr></table>";
|
663 |
return captionHTML;
|
664 |
} |
665 |
|
666 |
protected void onWindowResized(int height) { |
667 |
// Adjust the split panel to take up the available room in the window.
|
668 |
int newHeight = height - splitPanel.getAbsoluteTop();
|
669 |
if (newHeight < 1) |
670 |
newHeight = 1;
|
671 |
splitPanel.setHeight("" + newHeight);
|
672 |
inner.setHeight("" + newHeight);
|
673 |
} |
674 |
|
675 |
@Override
|
676 |
public void onResize(ResizeEvent event) { |
677 |
int height = event.getHeight();
|
678 |
onWindowResized(height); |
679 |
} |
680 |
|
681 |
/**
|
682 |
* Display an error message.
|
683 |
*
|
684 |
* @param msg the message to display
|
685 |
*/
|
686 |
public void displayError(String msg) { |
687 |
messagePanel.displayError(msg); |
688 |
} |
689 |
|
690 |
/**
|
691 |
* Display a warning message.
|
692 |
*
|
693 |
* @param msg the message to display
|
694 |
*/
|
695 |
public void displayWarning(String msg) { |
696 |
messagePanel.displayWarning(msg); |
697 |
} |
698 |
|
699 |
/**
|
700 |
* Display an informational message.
|
701 |
*
|
702 |
* @param msg the message to display
|
703 |
*/
|
704 |
public void displayInformation(String msg) { |
705 |
messagePanel.displayInformation(msg); |
706 |
} |
707 |
|
708 |
/**
|
709 |
* Retrieve the fileList.
|
710 |
*
|
711 |
* @return the fileList
|
712 |
*/
|
713 |
public FileList getFileList() {
|
714 |
return fileList;
|
715 |
} |
716 |
|
717 |
/**
|
718 |
* Retrieve the topPanel.
|
719 |
*
|
720 |
* @return the topPanel
|
721 |
*/
|
722 |
TopPanel getTopPanel() { |
723 |
return topPanel;
|
724 |
} |
725 |
|
726 |
/**
|
727 |
* Retrieve the clipboard.
|
728 |
*
|
729 |
* @return the clipboard
|
730 |
*/
|
731 |
public Clipboard getClipboard() { |
732 |
return clipboard;
|
733 |
} |
734 |
|
735 |
public StatusPanel getStatusPanel() {
|
736 |
return statusPanel;
|
737 |
} |
738 |
|
739 |
public String getToken() { |
740 |
return token;
|
741 |
} |
742 |
|
743 |
public static native void preventIESelection() /*-{ |
744 |
$doc.body.onselectstart = function () { return false; };
|
745 |
}-*/;
|
746 |
|
747 |
public static native void enableIESelection() /*-{ |
748 |
if ($doc.body.onselectstart != null)
|
749 |
$doc.body.onselectstart = null;
|
750 |
}-*/;
|
751 |
|
752 |
/**
|
753 |
* @return the absolute path of the API root URL
|
754 |
*/
|
755 |
public String getApiPath() { |
756 |
Configuration conf = (Configuration) GWT.create(Configuration.class); |
757 |
return conf.apiPath();
|
758 |
} |
759 |
|
760 |
/**
|
761 |
* History support for folder navigation
|
762 |
* adds a new browser history entry
|
763 |
*
|
764 |
* @param key
|
765 |
*/
|
766 |
public void updateHistory(String key){ |
767 |
// Replace any whitespace of the initial string to "+"
|
768 |
// String result = key.replaceAll("\\s","+");
|
769 |
// Add a new browser history entry.
|
770 |
// History.newItem(result);
|
771 |
History.newItem(key); |
772 |
} |
773 |
|
774 |
public void deleteFolder(final Folder folder, final Command callback) { |
775 |
String path = getApiPath() + folder.getOwner() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(folder.getPrefix()) + "&t=" + System.currentTimeMillis(); |
776 |
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
777 |
builder.setHeader("X-Auth-Token", getToken());
|
778 |
try {
|
779 |
builder.sendRequest("", new RequestCallback() { |
780 |
@Override
|
781 |
public void onResponseReceived(Request request, Response response) { |
782 |
if (response.getStatusCode() == Response.SC_OK) {
|
783 |
JSONValue json = JSONParser.parseStrict(response.getText()); |
784 |
JSONArray array = json.isArray(); |
785 |
int i = 0; |
786 |
if (array != null) { |
787 |
deleteObject(folder, i, array, callback); |
788 |
} |
789 |
} |
790 |
} |
791 |
|
792 |
@Override
|
793 |
public void onError(Request request, Throwable exception) { |
794 |
setError(exception); |
795 |
displayError("System error unable to delete folder: " + exception.getMessage());
|
796 |
} |
797 |
}); |
798 |
} |
799 |
catch (RequestException e) {
|
800 |
} |
801 |
} |
802 |
|
803 |
void deleteObject(final Folder folder, final int i, final JSONArray array, final Command callback) { |
804 |
if (i < array.size()) {
|
805 |
JSONObject o = array.get(i).isObject(); |
806 |
if (o != null && !o.containsKey("subdir")) { |
807 |
JSONString name = o.get("name").isString();
|
808 |
String path = "/" + folder.getContainer() + "/" + name.stringValue(); |
809 |
DeleteRequest delete = new DeleteRequest(getApiPath(), folder.getOwner(), URL.encode(path)) { |
810 |
@Override
|
811 |
public void onSuccess(Resource result) { |
812 |
deleteObject(folder, i + 1, array, callback);
|
813 |
} |
814 |
|
815 |
@Override
|
816 |
public void onError(Throwable t) { |
817 |
GWT.log("", t);
|
818 |
setError(t); |
819 |
displayError("System error unable to delete folder: " + t.getMessage());
|
820 |
} |
821 |
|
822 |
@Override
|
823 |
protected void onUnauthorized(Response response) { |
824 |
sessionExpired(); |
825 |
} |
826 |
}; |
827 |
delete.setHeader("X-Auth-Token", getToken());
|
828 |
Scheduler.get().scheduleDeferred(delete); |
829 |
} |
830 |
else if (o != null) { |
831 |
String subdir = o.get("subdir").isString().stringValue(); |
832 |
subdir = subdir.substring(0, subdir.length() - 1); |
833 |
String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis(); |
834 |
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
|
835 |
builder.setHeader("X-Auth-Token", getToken());
|
836 |
try {
|
837 |
builder.sendRequest("", new RequestCallback() { |
838 |
@Override
|
839 |
public void onResponseReceived(Request request, Response response) { |
840 |
if (response.getStatusCode() == Response.SC_OK) {
|
841 |
JSONValue json = JSONParser.parseStrict(response.getText()); |
842 |
JSONArray array2 = json.isArray(); |
843 |
if (array2 != null) { |
844 |
int l = array.size();
|
845 |
for (int j=0; j<array2.size(); j++) { |
846 |
array.set(l++, array2.get(j)); |
847 |
} |
848 |
} |
849 |
deleteObject(folder, i + 1, array, callback);
|
850 |
} |
851 |
} |
852 |
|
853 |
@Override
|
854 |
public void onError(Request request, Throwable exception) { |
855 |
setError(exception); |
856 |
displayError("System error unable to delete folder: " + exception.getMessage());
|
857 |
} |
858 |
}); |
859 |
} |
860 |
catch (RequestException e) {
|
861 |
} |
862 |
} |
863 |
} |
864 |
else {
|
865 |
String path = folder.getUri();
|
866 |
DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), URL.encode(path)) { |
867 |
@Override
|
868 |
public void onSuccess(Resource result) { |
869 |
updateFolder(folder.getParent(), true, new Command() { |
870 |
|
871 |
@Override
|
872 |
public void execute() { |
873 |
folderTreeSelectionModel.setSelected(folder.getParent(), true);
|
874 |
updateStatistics(); |
875 |
if (callback != null) |
876 |
callback.execute(); |
877 |
} |
878 |
}, true);
|
879 |
} |
880 |
|
881 |
@Override
|
882 |
public void onError(Throwable t) { |
883 |
GWT.log("", t);
|
884 |
setError(t); |
885 |
if (t instanceof RestException) { |
886 |
if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND)
|
887 |
displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
|
888 |
else
|
889 |
onSuccess(null);
|
890 |
} |
891 |
else
|
892 |
displayError("System error unable to delete folder: " + t.getMessage());
|
893 |
} |
894 |
|
895 |
@Override
|
896 |
protected void onUnauthorized(Response response) { |
897 |
sessionExpired(); |
898 |
} |
899 |
}; |
900 |
deleteFolder.setHeader("X-Auth-Token", getToken());
|
901 |
Scheduler.get().scheduleDeferred(deleteFolder); |
902 |
} |
903 |
} |
904 |
|
905 |
public FolderTreeView getFolderTreeView() {
|
906 |
return folderTreeView;
|
907 |
} |
908 |
|
909 |
public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) { |
910 |
if (iter.hasNext()) {
|
911 |
File file = iter.next();
|
912 |
String path = targetUri + "/" + file.getName(); |
913 |
PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
|
914 |
@Override
|
915 |
public void onSuccess(Resource result) { |
916 |
copyFiles(iter, targetUsername, targetUri, callback); |
917 |
} |
918 |
|
919 |
@Override
|
920 |
public void onError(Throwable t) { |
921 |
GWT.log("", t);
|
922 |
setError(t); |
923 |
if (t instanceof RestException) { |
924 |
displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
|
925 |
} |
926 |
else
|
927 |
displayError("System error unable to copy file: "+t.getMessage());
|
928 |
} |
929 |
|
930 |
@Override
|
931 |
protected void onUnauthorized(Response response) { |
932 |
sessionExpired(); |
933 |
} |
934 |
}; |
935 |
copyFile.setHeader("X-Auth-Token", getToken());
|
936 |
copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri())); |
937 |
if (!file.getOwner().equals(targetUsername))
|
938 |
copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner())); |
939 |
copyFile.setHeader("Content-Type", file.getContentType());
|
940 |
Scheduler.get().scheduleDeferred(copyFile); |
941 |
} |
942 |
else if (callback != null) { |
943 |
callback.execute(); |
944 |
} |
945 |
} |
946 |
|
947 |
public void copySubfolders(final Iterator<Folder> iter, final String targetUsername, final String targetUri, final Command callback) { |
948 |
if (iter.hasNext()) {
|
949 |
final Folder f = iter.next();
|
950 |
copyFolder(f, targetUsername, targetUri, new Command() {
|
951 |
|
952 |
@Override
|
953 |
public void execute() { |
954 |
copySubfolders(iter, targetUsername, targetUri, callback); |
955 |
} |
956 |
}); |
957 |
} |
958 |
else if (callback != null) { |
959 |
callback.execute(); |
960 |
} |
961 |
} |
962 |
|
963 |
public void copyFolder(final Folder f, final String targetUsername, final String targetUri, final Command callback) { |
964 |
String path = targetUri + "/" + f.getName(); |
965 |
PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) {
|
966 |
@Override
|
967 |
public void onSuccess(Resource result) { |
968 |
GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) { |
969 |
|
970 |
@Override
|
971 |
public void onSuccess(final Folder _f) { |
972 |
Iterator<File> iter = _f.getFiles().iterator(); |
973 |
copyFiles(iter, targetUsername, targetUri + "/" + _f.getName(), new Command() { |
974 |
@Override
|
975 |
public void execute() { |
976 |
Iterator<Folder> iterf = _f.getSubfolders().iterator();
|
977 |
copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback);
|
978 |
} |
979 |
}); |
980 |
} |
981 |
|
982 |
@Override
|
983 |
public void onError(Throwable t) { |
984 |
GWT.log("", t);
|
985 |
setError(t); |
986 |
if (t instanceof RestException) { |
987 |
displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
|
988 |
} |
989 |
else
|
990 |
displayError("System error getting folder: " + t.getMessage());
|
991 |
} |
992 |
|
993 |
@Override
|
994 |
protected void onUnauthorized(Response response) { |
995 |
sessionExpired(); |
996 |
} |
997 |
}; |
998 |
getFolder.setHeader("X-Auth-Token", getToken());
|
999 |
Scheduler.get().scheduleDeferred(getFolder); |
1000 |
} |
1001 |
|
1002 |
@Override
|
1003 |
public void onError(Throwable t) { |
1004 |
GWT.log("", t);
|
1005 |
setError(t); |
1006 |
if (t instanceof RestException) { |
1007 |
displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText());
|
1008 |
} |
1009 |
else
|
1010 |
displayError("System error creating folder: " + t.getMessage());
|
1011 |
} |
1012 |
|
1013 |
@Override
|
1014 |
protected void onUnauthorized(Response response) { |
1015 |
sessionExpired(); |
1016 |
} |
1017 |
}; |
1018 |
createFolder.setHeader("X-Auth-Token", getToken());
|
1019 |
createFolder.setHeader("Accept", "*/*"); |
1020 |
createFolder.setHeader("Content-Length", "0"); |
1021 |
createFolder.setHeader("Content-Type", "application/folder"); |
1022 |
Scheduler.get().scheduleDeferred(createFolder); |
1023 |
} |
1024 |
|
1025 |
public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) { |
1026 |
selectionModels.add(model); |
1027 |
} |
1028 |
|
1029 |
public OtherSharedTreeView getOtherSharedTreeView() {
|
1030 |
return otherSharedTreeView;
|
1031 |
} |
1032 |
|
1033 |
public void updateTrash(boolean showFiles, Command callback) { |
1034 |
updateFolder(trash, showFiles, callback, true);
|
1035 |
} |
1036 |
|
1037 |
public void updateGroupsNode() { |
1038 |
groupTreeView.updateGroupNode(null);
|
1039 |
} |
1040 |
|
1041 |
public void addGroup(String groupname) { |
1042 |
Group newGroup = new Group(groupname); |
1043 |
account.addGroup(newGroup); |
1044 |
groupTreeView.updateGroupNode(null);
|
1045 |
} |
1046 |
|
1047 |
public void removeGroup(Group group) { |
1048 |
account.removeGroup(group); |
1049 |
updateGroupsNode(); |
1050 |
} |
1051 |
|
1052 |
public TreeView getSelectedTree() {
|
1053 |
return selectedTree;
|
1054 |
} |
1055 |
|
1056 |
public void setSelectedTree(TreeView selected) { |
1057 |
selectedTree = selected; |
1058 |
} |
1059 |
|
1060 |
public Folder getSelection() {
|
1061 |
if (selectedTree != null) |
1062 |
return selectedTree.getSelection();
|
1063 |
return null; |
1064 |
} |
1065 |
|
1066 |
public void showFolderStatistics(int folderFileCount) { |
1067 |
numOfFiles.setHTML(String.valueOf(folderFileCount));
|
1068 |
} |
1069 |
|
1070 |
public GroupTreeView getGroupTreeView() {
|
1071 |
return groupTreeView;
|
1072 |
} |
1073 |
|
1074 |
public void sessionExpired() { |
1075 |
new SessionExpiredDialog(this).center(); |
1076 |
} |
1077 |
|
1078 |
public void updateRootFolder(Command callback) { |
1079 |
updateFolder(account.getPithos(), false, callback, true); |
1080 |
} |
1081 |
|
1082 |
void createMySharedTree() {
|
1083 |
mysharedTreeSelectionModel = new SingleSelectionModel<Folder>(); |
1084 |
mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
1085 |
@Override
|
1086 |
public void onSelectionChange(SelectionChangeEvent event) { |
1087 |
if (mysharedTreeSelectionModel.getSelectedObject() != null) { |
1088 |
deselectOthers(mysharedTreeView, mysharedTreeSelectionModel); |
1089 |
upload.setEnabled(false);
|
1090 |
updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
|
1091 |
showRelevantToolbarButtons(); |
1092 |
} |
1093 |
else {
|
1094 |
if (getSelectedTree().equals(mysharedTreeView))
|
1095 |
setSelectedTree(null);
|
1096 |
if (getSelectedTree() == null) |
1097 |
showRelevantToolbarButtons(); |
1098 |
} |
1099 |
} |
1100 |
}); |
1101 |
selectionModels.add(mysharedTreeSelectionModel); |
1102 |
mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel);
|
1103 |
mysharedTreeViewModel.initialize(new Command() {
|
1104 |
|
1105 |
@Override
|
1106 |
public void execute() { |
1107 |
mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
|
1108 |
trees.insert(mysharedTreeView, 2);
|
1109 |
treeViews.add(mysharedTreeView); |
1110 |
createOtherSharedTree(); |
1111 |
} |
1112 |
}); |
1113 |
} |
1114 |
|
1115 |
void createOtherSharedTree() {
|
1116 |
otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>(); |
1117 |
otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { |
1118 |
@Override
|
1119 |
public void onSelectionChange(SelectionChangeEvent event) { |
1120 |
if (otherSharedTreeSelectionModel.getSelectedObject() != null) { |
1121 |
deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel); |
1122 |
applyPermissions(otherSharedTreeSelectionModel.getSelectedObject()); |
1123 |
updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
|
1124 |
showRelevantToolbarButtons(); |
1125 |
} |
1126 |
else {
|
1127 |
if (getSelectedTree().equals(otherSharedTreeView))
|
1128 |
setSelectedTree(null);
|
1129 |
if (getSelectedTree() == null) |
1130 |
showRelevantToolbarButtons(); |
1131 |
} |
1132 |
} |
1133 |
}); |
1134 |
selectionModels.add(otherSharedTreeSelectionModel); |
1135 |
otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel);
|
1136 |
otherSharedTreeViewModel.initialize(new Command() {
|
1137 |
|
1138 |
@Override
|
1139 |
public void execute() { |
1140 |
otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
|
1141 |
trees.insert(otherSharedTreeView, 1);
|
1142 |
treeViews.add(otherSharedTreeView); |
1143 |
} |
1144 |
}); |
1145 |
} |
1146 |
|
1147 |
public native void log1(String message)/*-{ |
1148 |
$wnd.console.log(message);
|
1149 |
}-*/;
|
1150 |
|
1151 |
public String getErrorData() { |
1152 |
if (error != null) |
1153 |
return error.toString();
|
1154 |
return ""; |
1155 |
} |
1156 |
|
1157 |
public void setError(Throwable t) { |
1158 |
error = t; |
1159 |
} |
1160 |
|
1161 |
public void showRelevantToolbarButtons() { |
1162 |
toolbar.showRelevantButtons(); |
1163 |
} |
1164 |
|
1165 |
public FileUploadDialog getFileUploadDialog() {
|
1166 |
if (fileUploadDialog == null) |
1167 |
fileUploadDialog = new FileUploadDialog(this); |
1168 |
return fileUploadDialog;
|
1169 |
} |
1170 |
|
1171 |
public void hideUploadIndicator() { |
1172 |
upload.removeStyleName("pithos-uploadButton-loading");
|
1173 |
upload.setTitle("");
|
1174 |
} |
1175 |
|
1176 |
public void showUploadIndicator() { |
1177 |
upload.addStyleName("pithos-uploadButton-loading");
|
1178 |
upload.setTitle("Upload in progress. Click for details.");
|
1179 |
} |
1180 |
|
1181 |
public void scheduleFolderHeadCommand(final Folder folder, final Command callback) { |
1182 |
if (folder == null) { |
1183 |
if (callback != null) |
1184 |
callback.execute(); |
1185 |
} |
1186 |
else {
|
1187 |
HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getApiPath(), folder.getOwner(), folder.getUri(), folder) {
|
1188 |
|
1189 |
@Override
|
1190 |
public void onSuccess(Folder _result) { |
1191 |
if (callback != null) |
1192 |
callback.execute(); |
1193 |
} |
1194 |
|
1195 |
@Override
|
1196 |
public void onError(Throwable t) { |
1197 |
if (t instanceof RestException) { |
1198 |
if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
|
1199 |
final String path = folder.getUri(); |
1200 |
PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwner(), path) {
|
1201 |
@Override
|
1202 |
public void onSuccess(Resource _result) { |
1203 |
scheduleFolderHeadCommand(folder, callback); |
1204 |
} |
1205 |
|
1206 |
@Override
|
1207 |
public void onError(Throwable _t) { |
1208 |
GWT.log("", _t);
|
1209 |
setError(_t); |
1210 |
if(_t instanceof RestException){ |
1211 |
displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());
|
1212 |
} |
1213 |
else
|
1214 |
displayError("System error creating folder: " + _t.getMessage());
|
1215 |
} |
1216 |
|
1217 |
@Override
|
1218 |
protected void onUnauthorized(Response response) { |
1219 |
sessionExpired(); |
1220 |
} |
1221 |
}; |
1222 |
newFolder.setHeader("X-Auth-Token", getToken());
|
1223 |
newFolder.setHeader("Content-Type", "application/folder"); |
1224 |
newFolder.setHeader("Accept", "*/*"); |
1225 |
newFolder.setHeader("Content-Length", "0"); |
1226 |
Scheduler.get().scheduleDeferred(newFolder); |
1227 |
} |
1228 |
else
|
1229 |
displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
|
1230 |
} |
1231 |
else
|
1232 |
displayError("System error heading folder: " + t.getMessage());
|
1233 |
|
1234 |
GWT.log("Error heading folder", t);
|
1235 |
setError(t); |
1236 |
} |
1237 |
|
1238 |
@Override
|
1239 |
protected void onUnauthorized(Response response) { |
1240 |
sessionExpired(); |
1241 |
} |
1242 |
}; |
1243 |
headFolder.setHeader("X-Auth-Token", getToken());
|
1244 |
Scheduler.get().scheduleDeferred(headFolder); |
1245 |
} |
1246 |
} |
1247 |
|
1248 |
public void scheduleFileHeadCommand(File f, final Command callback) { |
1249 |
HeadRequest<File> headFile = new HeadRequest<File>(File.class, getApiPath(), f.getOwner(), f.getUri(), f) { |
1250 |
|
1251 |
@Override
|
1252 |
public void onSuccess(File _result) { |
1253 |
if (callback != null) |
1254 |
callback.execute(); |
1255 |
} |
1256 |
|
1257 |
@Override
|
1258 |
public void onError(Throwable t) { |
1259 |
GWT.log("Error heading file", t);
|
1260 |
setError(t); |
1261 |
if (t instanceof RestException) |
1262 |
displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
|
1263 |
else
|
1264 |
displayError("System error heading file: " + t.getMessage());
|
1265 |
} |
1266 |
|
1267 |
@Override
|
1268 |
protected void onUnauthorized(Response response) { |
1269 |
sessionExpired(); |
1270 |
} |
1271 |
}; |
1272 |
headFile.setHeader("X-Auth-Token", getToken());
|
1273 |
Scheduler.get().scheduleDeferred(headFile); |
1274 |
} |
1275 |
|
1276 |
public boolean isMySharedSelected() { |
1277 |
return getSelectedTree().equals(getMySharedTreeView());
|
1278 |
} |
1279 |
} |