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