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