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