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