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