2 * Copyright 2011-2012 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
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.
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.
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.
35 package gr.grnet.pithos.web.client;
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;
78 * Entry point classes define <code>onModuleLoad()</code>.
80 public class Pithos implements EntryPoint, ResizeHandler {
82 public static final Configuration config = GWT.create(Configuration.class);
84 public interface Style extends CssResource {
85 String commandAnchor();
89 @ClassName("gwt-HTML")
94 String uploadAlertLink();
96 String uploadAlertProgress();
98 String uploadAlertPercent();
100 String uploadAlertClose();
103 public interface Resources extends ClientBundle {
104 @Source("Pithos.css")
107 @Source("gr/grnet/pithos/resources/close-popup.png")
108 ImageResource closePopup();
111 public static Resources resources = GWT.create(Resources.class);
114 * Instantiate an application-level image bundle. This object will provide
115 * programmatic access to all the images needed by widgets.
117 static Images images = (Images) GWT.create(Images.class);
119 public String getUserID() {
123 public UserCatalogs getUserCatalogs() {
127 public String getCurrentUserDisplayNameOrID() {
128 final String displayName = userCatalogs.getDisplayName(getUserID());
129 return displayName == null ? getUserID() : displayName;
132 public boolean hasUserDisplayNameForID(String userID) {
133 return userCatalogs.getDisplayName(userID) != null;
136 public String getUserDisplayNameForID(String userID) {
137 return userCatalogs.getDisplayName(userID);
140 public String getUserIDForDisplayName(String displayName) {
141 return userCatalogs.getUserID(displayName);
144 public List<String> getUserDisplayNamesForIDs(List<String> userIDs) {
145 if(userIDs == null) {
146 userIDs = new ArrayList<String>();
148 final List<String> userDisplayNames = new ArrayList<String>();
149 for(String userID : userIDs) {
150 final String displayName = getUserDisplayNameForID(userID);
151 userDisplayNames.add(displayName);
154 return userDisplayNames;
157 public List<String> filterUserIDsWithUnknownDisplayName(Collection<String> userIDs) {
158 if(userIDs == null) {
159 userIDs = new ArrayList<String>();
161 final List<String> filtered = new ArrayList<String>();
162 for(String userID : userIDs) {
163 if(!this.userCatalogs.hasID(userID)) {
164 filtered.add(userID);
170 public void setAccount(AccountResource acct) {
174 public AccountResource getAccount() {
178 public void updateFolder(Folder f, boolean showfiles, Command callback, final boolean openParent) {
179 folderTreeView.updateFolder(f, showfiles, callback, openParent);
182 public void updateGroupNode(Group group) {
183 groupTreeView.updateGroupNode(group);
186 public void updateMySharedRoot() {
187 mysharedTreeView.updateRoot();
190 public void updateSharedFolder(Folder f, boolean showfiles, Command callback) {
191 mysharedTreeView.updateFolder(f, showfiles, callback);
194 public void updateSharedFolder(Folder f, boolean showfiles) {
195 updateSharedFolder(f, showfiles, null);
198 public void updateOtherSharedFolder(Folder f, boolean showfiles, Command callback) {
199 otherSharedTreeView.updateFolder(f, showfiles, callback);
202 public MysharedTreeView getMySharedTreeView() {
203 return mysharedTreeView;
207 * An aggregate image bundle that pulls together all the images for this
208 * application into a single bundle.
210 public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images {
212 @Source("gr/grnet/pithos/resources/document.png")
213 ImageResource folders();
215 @Source("gr/grnet/pithos/resources/advancedsettings.png")
216 @ImageOptions(width = 32, height = 32)
217 ImageResource tools();
220 private Throwable error;
223 * The Application Clipboard implementation;
225 private Clipboard clipboard = new Clipboard();
228 * The top panel that contains the menu bar.
230 private TopPanel topPanel;
233 * The panel that contains the various system messages.
235 private MessagePanel messagePanel = new MessagePanel(this, Pithos.images);
238 * The bottom panel that contains the status bar.
240 StatusPanel statusPanel = null;
243 * The file list widget.
245 private FileList fileList;
248 * The tab panel that occupies the right side of the screen.
250 private VerticalPanel inner = new VerticalPanel();
254 * The split panel that will contain the left and right panels.
256 private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
259 * The currently selected item in the application, for use by the Edit menu
260 * commands. Potential types are Folder, File, User and Group.
262 private Object currentSelection;
264 public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
267 * The ID that uniquely identifies the user in Pithos+.
268 * Currently this is a UUID. It used to be the user's email.
270 private String userID = null;
273 * Hold mappings from user UUIDs to emails and vice-versa.
275 private UserCatalogs userCatalogs = new UserCatalogs();
278 * The authentication token of the current user.
280 private String userToken;
284 SingleSelectionModel<Folder> folderTreeSelectionModel;
285 FolderTreeViewModel folderTreeViewModel;
286 FolderTreeView folderTreeView;
288 SingleSelectionModel<Folder> mysharedTreeSelectionModel;
289 MysharedTreeViewModel mysharedTreeViewModel;
290 MysharedTreeView mysharedTreeView = null;
292 protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel;
293 OtherSharedTreeViewModel otherSharedTreeViewModel;
294 OtherSharedTreeView otherSharedTreeView = null;
296 GroupTreeViewModel groupTreeViewModel;
297 GroupTreeView groupTreeView;
299 TreeView selectedTree;
300 protected AccountResource account;
304 List<Composite> treeViews = new ArrayList<Composite>();
306 @SuppressWarnings("rawtypes")
307 List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
309 public Button upload;
311 private HTML numOfFiles;
313 private Toolbar toolbar;
315 private FileUploadDialog fileUploadDialog = new FileUploadDialog(this);
317 UploadAlert uploadAlert;
322 public void onModuleLoad() {
323 if(parseUserCredentials()) {
328 static native void __ConsoleLog(String message) /*-{
330 console.log(message);
335 public static void LOG(String ...args) {
336 final StringBuilder sb = new StringBuilder();
337 for(String arg : args) {
340 if(sb.length() > 0) {
341 __ConsoleLog(sb.toString());
345 private void initialize() {
346 lastModified = new Date(); //Initialize if-modified-since value with now.
347 resources.pithosCss().ensureInjected();
348 boolean bareContent = Window.Location.getParameter("noframe") != null;
349 String contentWidth = bareContent ? Const.PERCENT_100 : "75%";
351 VerticalPanel outer = new VerticalPanel();
352 outer.setWidth(Const.PERCENT_100);
354 outer.addStyleName("pithos-outer");
358 topPanel = new TopPanel(this, Pithos.images);
359 topPanel.setWidth(Const.PERCENT_100);
361 outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER);
364 messagePanel.setVisible(false);
365 outer.add(messagePanel);
366 outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
367 outer.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE);
369 HorizontalPanel header = new HorizontalPanel();
370 header.addStyleName("pithos-header");
371 header.setWidth(contentWidth);
373 header.addStyleName("pithos-header-noframe");
375 upload = new Button("Upload", new ClickHandler() {
377 public void onClick(ClickEvent event) {
378 if(getSelection() != null) {
379 new UploadFileCommand(Pithos.this, null, getSelection()).execute();
383 upload.addStyleName("pithos-uploadButton");
385 header.setCellHorizontalAlignment(upload, HasHorizontalAlignment.ALIGN_LEFT);
386 header.setCellVerticalAlignment(upload, HasVerticalAlignment.ALIGN_MIDDLE);
388 toolbar = new Toolbar(this);
390 header.setCellHorizontalAlignment(toolbar, HasHorizontalAlignment.ALIGN_CENTER);
391 header.setCellVerticalAlignment(toolbar, HasVerticalAlignment.ALIGN_MIDDLE);
393 HorizontalPanel folderStatistics = new HorizontalPanel();
394 folderStatistics.addStyleName("pithos-folderStatistics");
395 numOfFiles = new HTML();
396 folderStatistics.add(numOfFiles);
397 folderStatistics.setCellVerticalAlignment(numOfFiles, HasVerticalAlignment.ALIGN_MIDDLE);
398 HTML numOfFilesLabel = new HTML(" Files");
399 folderStatistics.add(numOfFilesLabel);
400 folderStatistics.setCellVerticalAlignment(numOfFilesLabel, HasVerticalAlignment.ALIGN_MIDDLE);
401 header.add(folderStatistics);
402 header.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT);
403 header.setCellVerticalAlignment(folderStatistics, HasVerticalAlignment.ALIGN_MIDDLE);
404 header.setCellWidth(folderStatistics, "40px");
406 outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER);
407 // Inner contains the various lists
408 inner.sinkEvents(Event.ONCONTEXTMENU);
409 inner.setWidth(Const.PERCENT_100);
411 folderTreeSelectionModel = new SingleSelectionModel<Folder>();
412 folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
414 public void onSelectionChange(SelectionChangeEvent event) {
415 if(folderTreeSelectionModel.getSelectedObject() != null) {
416 deselectOthers(folderTreeView, folderTreeSelectionModel);
417 applyPermissions(folderTreeSelectionModel.getSelectedObject());
418 Folder f = folderTreeSelectionModel.getSelectedObject();
419 updateFolder(f, true, new Command() {
422 public void execute() {
426 showRelevantToolbarButtons();
429 if(getSelectedTree().equals(folderTreeView)) {
430 setSelectedTree(null);
432 if(getSelectedTree() == null) {
433 showRelevantToolbarButtons();
438 selectionModels.add(folderTreeSelectionModel);
440 folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel);
441 folderTreeView = new FolderTreeView(folderTreeViewModel);
442 treeViews.add(folderTreeView);
444 fileList = new FileList(this, images);
447 trees = new VerticalPanel();
448 trees.setWidth(Const.PERCENT_100);
450 // Add the left and right panels to the split panel.
451 splitPanel.setLeftWidget(trees);
452 FlowPanel right = new FlowPanel();
453 right.getElement().setId("rightPanel");
455 splitPanel.setRightWidget(right);
456 splitPanel.setSplitPosition("219px");
457 splitPanel.setSize(Const.PERCENT_100, Const.PERCENT_100);
458 splitPanel.addStyleName("pithos-splitPanel");
459 splitPanel.setWidth(contentWidth);
460 outer.add(splitPanel);
461 outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER);
464 statusPanel = new StatusPanel();
465 statusPanel.setWidth(Const.PERCENT_100);
466 outer.add(statusPanel);
467 outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER);
470 splitPanel.addStyleName("pithos-splitPanel-noframe");
473 // Hook the window resize event, so that we can adjust the UI.
474 Window.addResizeHandler(this);
475 // Clear out the window's built-in margin, because we want to take
476 // advantage of the entire client area.
477 Window.setMargin("0px");
478 // Finally, add the outer panel to the RootPanel, so that it will be
480 RootPanel.get().add(outer);
481 // Call the window resized handler to get the initial sizes setup. Doing
482 // this in a deferred command causes it to occur after all widgets'
483 // sizes have been computed by the browser.
484 Scheduler.get().scheduleIncremental(new RepeatingCommand() {
487 public boolean execute() {
488 if(!isCloudbarReady()) {
491 onWindowResized(Window.getClientHeight());
496 Scheduler.get().scheduleDeferred(new ScheduledCommand() {
498 public void execute() {
499 fetchAccount(new Command() {
502 public void execute() {
503 if(!account.hasHomeContainer()) {
504 createHomeContainer(account, this);
506 else if(!account.hasTrashContainer()) {
507 createTrashContainer(this);
510 for(Folder f : account.getContainers()) {
511 if(f.getName().equals(Const.TRASH_CONTAINER)) {
516 trees.add(folderTreeView);
517 folderTreeViewModel.initialize(account, new Command() {
520 public void execute() {
521 createMySharedTree();
525 HorizontalPanel separator = new HorizontalPanel();
526 separator.addStyleName("pithos-statisticsSeparator");
527 separator.add(new HTML(""));
528 trees.add(separator);
530 groupTreeViewModel = new GroupTreeViewModel(Pithos.this);
531 groupTreeView = new GroupTreeView(groupTreeViewModel);
532 treeViews.add(groupTreeView);
533 trees.add(groupTreeView);
534 folderTreeView.showStatistics(account);
542 public void scheduleResfresh() {
543 Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
546 public boolean execute() {
547 final Folder f = getSelection();
552 HeadRequest<Folder> head = new HeadRequest<Folder>(Folder.class, getApiPath(), f.getOwnerID(), "/" + f.getContainer()) {
555 public void onSuccess(Folder _result) {
556 lastModified = new Date();
557 if(getSelectedTree().equals(folderTreeView)) {
558 updateFolder(f, true, new Command() {
561 public void execute() {
567 else if(getSelectedTree().equals(mysharedTreeView)) {
568 updateSharedFolder(f, true, new Command() {
571 public void execute() {
582 public void onError(Throwable t) {
583 if(t instanceof RestException && ((RestException) t).getHttpStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
586 else if(retries >= MAX_RETRIES) {
587 GWT.log("Error heading folder", t);
589 if(t instanceof RestException) {
590 displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
593 displayError("System error heading folder: " + t.getMessage());
597 GWT.log("Retry " + retries);
598 Scheduler.get().scheduleDeferred(this);
603 protected void onUnauthorized(Response response) {
604 if(retries >= MAX_RETRIES) {
609 Scheduler.get().scheduleDeferred(this);
613 head.setHeader(Const.X_AUTH_TOKEN, getUserToken());
614 head.setHeader(Const.IF_MODIFIED_SINCE, DateTimeFormat.getFormat(Const.DATE_FORMAT_1).format(lastModified, TimeZone.createTimeZone(0)) + " GMT");
615 Scheduler.get().scheduleDeferred(head);
622 public void applyPermissions(Folder f) {
625 upload.setEnabled(false);
629 Boolean[] perms = f.getPermissions().get(userID);
630 if(f.getOwnerID().equals(userID) || (perms != null && perms[1] != null && perms[1])) {
631 upload.setEnabled(true);
635 upload.setEnabled(false);
641 upload.setEnabled(false);
646 @SuppressWarnings({"rawtypes", "unchecked"})
647 public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) {
648 selectedTree = _selectedTree;
650 for(SingleSelectionModel s : selectionModels) {
651 if(!s.equals(model) && s.getSelectedObject() != null) {
652 s.setSelected(s.getSelectedObject(), false);
657 public void showFiles(final Folder f) {
658 Set<File> files = f.getFiles();
662 public void showFiles(Set<File> files) {
663 fileList.setFiles(new ArrayList<File>(files));
667 * Parse and store the user credentials to the appropriate fields.
669 private boolean parseUserCredentials() {
670 Configuration conf = (Configuration) GWT.create(Configuration.class);
671 Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES);
672 String cookie = otherProperties.get(Const.AUTH_COOKIE);
673 String auth = Cookies.getCookie(cookie);
678 if(auth.startsWith("\"")) {
679 auth = auth.substring(1);
681 if(auth.endsWith("\"")) {
682 auth = auth.substring(0, auth.length() - 1);
684 String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
685 if(authSplit.length != 2) {
689 userID = authSplit[0];
690 userToken = authSplit[1];
692 String gotoUrl = Window.Location.getParameter("goto");
693 if(gotoUrl != null && gotoUrl.length() > 0) {
694 Window.Location.assign(gotoUrl);
701 * Redirect the user to the login page for authentication.
703 protected void authenticateUser() {
704 Dictionary otherProperties = Dictionary.getDictionary(Const.OTHER_PROPERTIES);
705 Window.Location.assign(otherProperties.get(Const.LOGIN_URL) + Window.Location.getHref());
708 public void fetchAccount(final Command callback) {
709 String path = "?format=json";
711 GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), userID, path) {
713 public void onSuccess(AccountResource _result) {
715 if(callback != null) {
718 // Initialize the user catalog
719 new UpdateUserCatalogs(Pithos.this, Pithos.this.getUserID()).scheduleDeferred();
723 public void onError(Throwable t) {
724 GWT.log("Error getting account", t);
726 if(t instanceof RestException) {
727 displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
730 displayError("System error fetching user data: " + t.getMessage());
735 protected void onUnauthorized(Response response) {
739 getAccount.setHeader(Const.X_AUTH_TOKEN, userToken);
740 Scheduler.get().scheduleDeferred(getAccount);
743 public void updateStatistics() {
744 HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), userID, "", account) {
747 public void onSuccess(AccountResource _result) {
748 folderTreeView.showStatistics(account);
752 public void onError(Throwable t) {
753 GWT.log("Error getting account", t);
755 if(t instanceof RestException) {
756 displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
759 displayError("System error fetching user data: " + t.getMessage());
764 protected void onUnauthorized(Response response) {
768 headAccount.setHeader(Const.X_AUTH_TOKEN, userToken);
769 Scheduler.get().scheduleDeferred(headAccount);
772 protected void createHomeContainer(final AccountResource _account, final Command callback) {
773 String path = "/" + Const.HOME_CONTAINER;
774 PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) {
776 public void onSuccess(Resource result) {
777 if(!_account.hasTrashContainer()) {
778 createTrashContainer(callback);
781 fetchAccount(callback);
786 public void onError(Throwable t) {
787 GWT.log("Error creating pithos", t);
789 if(t instanceof RestException) {
790 displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
793 displayError("System error Error creating pithos: " + t.getMessage());
798 protected void onUnauthorized(Response response) {
802 createPithos.setHeader(Const.X_AUTH_TOKEN, getUserToken());
803 Scheduler.get().scheduleDeferred(createPithos);
806 protected void createTrashContainer(final Command callback) {
807 String path = "/" + Const.TRASH_CONTAINER;
808 PutRequest createPithos = new PutRequest(getApiPath(), getUserID(), path) {
810 public void onSuccess(Resource result) {
811 fetchAccount(callback);
815 public void onError(Throwable t) {
816 GWT.log("Error creating pithos", t);
818 if(t instanceof RestException) {
819 displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
822 displayError("System error Error creating pithos: " + t.getMessage());
827 protected void onUnauthorized(Response response) {
831 createPithos.setHeader(Const.X_AUTH_TOKEN, getUserToken());
832 Scheduler.get().scheduleDeferred(createPithos);
836 * Creates an HTML fragment that places an image & caption together, for use
839 * @param imageProto an image prototype for an image
840 * @param caption the group caption
841 * @return the header HTML fragment
843 private String createHeaderHTML(AbstractImagePrototype imageProto, String caption) {
844 String captionHTML = "<table class='caption' cellpadding='0' "
845 + "cellspacing='0'>" + "<tr><td class='lcaption'>" + imageProto.getHTML()
846 + "</td><td id =" + caption + " class='rcaption'><b style='white-space:nowrap'> "
847 + caption + "</b></td></tr></table>";
851 protected void onWindowResized(int height) {
852 // Adjust the split panel to take up the available room in the window.
853 int newHeight = height - splitPanel.getAbsoluteTop() - 153;
857 splitPanel.setHeight("" + newHeight);
858 inner.setHeight("" + newHeight);
861 native boolean isCloudbarReady()/*-{
862 if ($wnd.$("div.cloudbar") && $wnd.$("div.cloudbar").height() > 0)
868 public void onResize(ResizeEvent event) {
869 int height = event.getHeight();
870 onWindowResized(height);
874 * Display an error message.
876 * @param msg the message to display
878 public void displayError(String msg) {
879 messagePanel.displayError(msg);
880 onWindowResized(Window.getClientHeight());
884 * Display a warning message.
886 * @param msg the message to display
888 public void displayWarning(String msg) {
889 messagePanel.displayWarning(msg);
890 onWindowResized(Window.getClientHeight());
894 * Display an informational message.
896 * @param msg the message to display
898 public void displayInformation(String msg) {
899 messagePanel.displayInformation(msg);
900 onWindowResized(Window.getClientHeight());
904 * Retrieve the fileList.
906 * @return the fileList
908 public FileList getFileList() {
913 * Retrieve the topPanel.
915 * @return the topPanel
917 TopPanel getTopPanel() {
922 * Retrieve the clipboard.
924 * @return the clipboard
926 public Clipboard getClipboard() {
930 public StatusPanel getStatusPanel() {
934 public String getUserToken() {
938 public static native void preventIESelection() /*-{
939 $doc.body.onselectstart = function () {
944 public static native void enableIESelection() /*-{
945 if ($doc.body.onselectstart != null)
946 $doc.body.onselectstart = null;
950 * @return the absolute path of the API root URL
952 public String getApiPath() {
953 Configuration conf = (Configuration) GWT.create(Configuration.class);
954 return conf.apiPath();
958 * History support for folder navigation
959 * adds a new browser history entry
963 public void updateHistory(String key) {
964 // Replace any whitespace of the initial string to "+"
965 // String result = key.replaceAll("\\s","+");
966 // Add a new browser history entry.
967 // History.newItem(result);
968 History.newItem(key);
971 public void deleteFolder(final Folder folder, final Command callback) {
972 final PleaseWaitPopup pwp = new PleaseWaitPopup();
974 String path = "/" + folder.getContainer() + "/" + folder.getPrefix() + "?delimiter=/" + "&t=" + System.currentTimeMillis();
975 DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), folder.getOwnerID(), path) {
978 protected void onUnauthorized(Response response) {
984 public void onSuccess(Resource result) {
985 updateFolder(folder.getParent(), true, new Command() {
988 public void execute() {
989 folderTreeSelectionModel.setSelected(folder.getParent(), true);
991 if(callback != null) {
1000 public void onError(Throwable t) {
1003 if(t instanceof RestException) {
1004 if(((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND) {
1005 displayError("Unable to delete folder: " + ((RestException) t).getHttpStatusText());
1012 displayError("System error unable to delete folder: " + t.getMessage());
1017 deleteFolder.setHeader(Const.X_AUTH_TOKEN, getUserToken());
1018 Scheduler.get().scheduleDeferred(deleteFolder);
1021 public FolderTreeView getFolderTreeView() {
1022 return folderTreeView;
1025 public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) {
1026 if(iter.hasNext()) {
1027 File file = iter.next();
1028 String path = targetUri + "/" + file.getName();
1029 PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
1031 public void onSuccess(Resource result) {
1032 copyFiles(iter, targetUsername, targetUri, callback);
1036 public void onError(Throwable t) {
1039 if(t instanceof RestException) {
1040 displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
1043 displayError("System error unable to copy file: " + t.getMessage());
1048 protected void onUnauthorized(Response response) {
1052 copyFile.setHeader(Const.X_AUTH_TOKEN, getUserToken());
1053 copyFile.setHeader(Const.X_COPY_FROM, URL.encodePathSegment(file.getUri()));
1054 if(!file.getOwnerID().equals(targetUsername)) {
1055 copyFile.setHeader(Const.X_SOURCE_ACCOUNT, URL.encodePathSegment(file.getOwnerID()));
1057 copyFile.setHeader(Const.CONTENT_TYPE, file.getContentType());
1058 Scheduler.get().scheduleDeferred(copyFile);
1060 else if(callback != null) {
1065 public void copyFolder(final Folder f, final String targetUsername, final String targetUri, boolean move, final Command callback) {
1066 String path = targetUri + "?delimiter=/";
1067 PutRequest copyFolder = new PutRequest(getApiPath(), targetUsername, path) {
1069 public void onSuccess(Resource result) {
1070 if(callback != null) {
1076 public void onError(Throwable t) {
1079 if(t instanceof RestException) {
1080 displayError("Unable to copy folder: " + ((RestException) t).getHttpStatusText());
1083 displayError("System error copying folder: " + t.getMessage());
1088 protected void onUnauthorized(Response response) {
1092 copyFolder.setHeader(Const.X_AUTH_TOKEN, getUserToken());
1093 copyFolder.setHeader(Const.ACCEPT, "*/*");
1094 copyFolder.setHeader(Const.CONTENT_LENGTH, "0");
1095 copyFolder.setHeader(Const.CONTENT_TYPE, "application/directory");
1096 if(!f.getOwnerID().equals(targetUsername)) {
1097 copyFolder.setHeader(Const.X_SOURCE_ACCOUNT, f.getOwnerID());
1100 copyFolder.setHeader(Const.X_MOVE_FROM, URL.encodePathSegment(f.getUri()));
1103 copyFolder.setHeader(Const.X_COPY_FROM, URL.encodePathSegment(f.getUri()));
1105 Scheduler.get().scheduleDeferred(copyFolder);
1108 public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) {
1109 selectionModels.add(model);
1112 public OtherSharedTreeView getOtherSharedTreeView() {
1113 return otherSharedTreeView;
1116 public void updateTrash(boolean showFiles, Command callback) {
1117 updateFolder(trash, showFiles, callback, true);
1120 public void updateGroupsNode() {
1121 groupTreeView.updateGroupNode(null);
1124 public Group addGroup(String groupname) {
1125 Group newGroup = new Group(groupname);
1126 account.addGroup(newGroup);
1127 groupTreeView.updateGroupNode(null);
1131 public void removeGroup(Group group) {
1132 account.removeGroup(group);
1136 public TreeView getSelectedTree() {
1137 return selectedTree;
1140 public void setSelectedTree(TreeView selected) {
1141 selectedTree = selected;
1144 public Folder getSelection() {
1145 if(selectedTree != null) {
1146 return selectedTree.getSelection();
1151 public void showFolderStatistics(int folderFileCount) {
1152 numOfFiles.setHTML(String.valueOf(folderFileCount));
1155 public GroupTreeView getGroupTreeView() {
1156 return groupTreeView;
1159 public void sessionExpired() {
1160 new SessionExpiredDialog(this).center();
1163 public void updateRootFolder(Command callback) {
1164 updateFolder(account.getPithos(), false, callback, true);
1167 void createMySharedTree() {
1168 mysharedTreeSelectionModel = new SingleSelectionModel<Folder>();
1169 mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
1171 public void onSelectionChange(SelectionChangeEvent event) {
1172 if(mysharedTreeSelectionModel.getSelectedObject() != null) {
1173 deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
1174 upload.setEnabled(false);
1175 disableUploadArea();
1176 updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
1177 showRelevantToolbarButtons();
1180 if(getSelectedTree().equals(mysharedTreeView)) {
1181 setSelectedTree(null);
1183 if(getSelectedTree() == null) {
1184 showRelevantToolbarButtons();
1189 selectionModels.add(mysharedTreeSelectionModel);
1190 mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel);
1191 mysharedTreeViewModel.initialize(new Command() {
1194 public void execute() {
1195 mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
1196 trees.insert(mysharedTreeView, 2);
1197 treeViews.add(mysharedTreeView);
1198 createOtherSharedTree();
1203 void createOtherSharedTree() {
1204 otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>();
1205 otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
1207 public void onSelectionChange(SelectionChangeEvent event) {
1208 if(otherSharedTreeSelectionModel.getSelectedObject() != null) {
1209 deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
1210 applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
1211 updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true, null);
1212 showRelevantToolbarButtons();
1215 if(getSelectedTree().equals(otherSharedTreeView)) {
1216 setSelectedTree(null);
1218 if(getSelectedTree() == null) {
1219 showRelevantToolbarButtons();
1224 selectionModels.add(otherSharedTreeSelectionModel);
1225 otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel);
1226 otherSharedTreeViewModel.initialize(new Command() {
1229 public void execute() {
1230 otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
1231 trees.insert(otherSharedTreeView, 1);
1232 treeViews.add(otherSharedTreeView);
1238 public native void log1(String message)/*-{
1239 $wnd.console.log(message);
1242 public String getErrorData() {
1244 return error.toString();
1249 public void setError(Throwable t) {
1253 public void showRelevantToolbarButtons() {
1254 toolbar.showRelevantButtons();
1257 public FileUploadDialog getFileUploadDialog() {
1258 if(fileUploadDialog == null) {
1259 fileUploadDialog = new FileUploadDialog(this);
1261 return fileUploadDialog;
1264 public void hideUploadIndicator() {
1265 upload.removeStyleName("pithos-uploadButton-loading");
1266 upload.setTitle("");
1269 public void showUploadIndicator() {
1270 upload.addStyleName("pithos-uploadButton-loading");
1271 upload.setTitle("Upload in progress. Click for details.");
1274 public void scheduleFolderHeadCommand(final Folder folder, final Command callback) {
1275 if(folder == null) {
1276 if(callback != null) {
1281 HeadRequest<Folder> headFolder = new HeadRequest<Folder>(Folder.class, getApiPath(), folder.getOwnerID(), folder.getUri(), folder) {
1284 public void onSuccess(Folder _result) {
1285 if(callback != null) {
1291 public void onError(Throwable t) {
1292 if(t instanceof RestException) {
1293 if(((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) {
1294 final String path = folder.getUri();
1295 PutRequest newFolder = new PutRequest(getApiPath(), folder.getOwnerID(), path) {
1297 public void onSuccess(Resource _result) {
1298 scheduleFolderHeadCommand(folder, callback);
1302 public void onError(Throwable _t) {
1305 if(_t instanceof RestException) {
1306 displayError("Unable to create folder: " + ((RestException) _t).getHttpStatusText());
1309 displayError("System error creating folder: " + _t.getMessage());
1314 protected void onUnauthorized(Response response) {
1318 newFolder.setHeader(Const.X_AUTH_TOKEN, getUserToken());
1319 newFolder.setHeader(Const.CONTENT_TYPE, "application/folder");
1320 newFolder.setHeader(Const.ACCEPT, "*/*");
1321 newFolder.setHeader(Const.CONTENT_LENGTH, "0");
1322 Scheduler.get().scheduleDeferred(newFolder);
1324 else if(((RestException) t).getHttpStatusCode() == Response.SC_FORBIDDEN) {
1328 displayError("Error heading folder: " + ((RestException) t).getHttpStatusText());
1332 displayError("System error heading folder: " + t.getMessage());
1335 GWT.log("Error heading folder", t);
1340 protected void onUnauthorized(Response response) {
1344 headFolder.setHeader(Const.X_AUTH_TOKEN, getUserToken());
1345 Scheduler.get().scheduleDeferred(headFolder);
1349 public void scheduleFileHeadCommand(File f, final Command callback) {
1350 HeadRequest<File> headFile = new HeadRequest<File>(File.class, getApiPath(), f.getOwnerID(), f.getUri(), f) {
1353 public void onSuccess(File _result) {
1354 if(callback != null) {
1360 public void onError(Throwable t) {
1361 GWT.log("Error heading file", t);
1363 if(t instanceof RestException) {
1364 displayError("Error heading file: " + ((RestException) t).getHttpStatusText());
1367 displayError("System error heading file: " + t.getMessage());
1372 protected void onUnauthorized(Response response) {
1376 headFile.setHeader(Const.X_AUTH_TOKEN, getUserToken());
1377 Scheduler.get().scheduleDeferred(headFile);
1380 public boolean isMySharedSelected() {
1381 return getSelectedTree().equals(getMySharedTreeView());
1384 private Folder getUploadFolder() {
1385 if(folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
1386 return getSelection();
1391 private void updateUploadFolder() {
1392 updateUploadFolder(null);
1395 private void updateUploadFolder(final JsArrayString urls) {
1396 if(folderTreeView.equals(getSelectedTree()) || otherSharedTreeView.equals(getSelectedTree())) {
1397 Folder f = getSelection();
1398 if(getSelectedTree().equals(getFolderTreeView())) {
1399 updateFolder(f, true, new Command() {
1402 public void execute() {
1405 selectUploadedFiles(urls);
1411 updateOtherSharedFolder(f, true, null);
1416 public native void disableUploadArea() /*-{
1417 var uploader = $wnd.$("#uploader").pluploadQueue();
1418 var dropElm = $wnd.document.getElementById('rightPanel');
1419 $wnd.plupload.removeAllEvents(dropElm, uploader.id);
1422 public native void enableUploadArea() /*-{
1423 var uploader = $wnd.$("#uploader").pluploadQueue();
1424 var dropElm = $wnd.document.getElementById('rightPanel');
1425 $wnd.plupload.removeAllEvents(dropElm, uploader.id);
1426 if (uploader.runtime == 'html5') {
1427 uploader.settings.drop_element = 'rightPanel';
1428 uploader.trigger('PostInit');
1432 public void showUploadAlert(int nOfFiles) {
1433 if(uploadAlert == null) {
1434 uploadAlert = new UploadAlert(this, nOfFiles);
1436 if(!uploadAlert.isShowing()) {
1437 uploadAlert.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
1440 public void setPosition(int offsetWidth, int offsetHeight) {
1441 uploadAlert.setPopupPosition((Window.getClientWidth() - offsetWidth) / 2, statusPanel.getAbsoluteTop() - offsetHeight);
1445 uploadAlert.setNumOfFiles(nOfFiles);
1448 public void hideUploadAlert() {
1449 if(uploadAlert != null && uploadAlert.isShowing()) {
1454 public void selectUploadedFiles(JsArrayString urls) {
1455 List<String> selectedUrls = new ArrayList<String>();
1456 for(int i = 0; i < urls.length(); i++) {
1457 selectedUrls.add(urls.get(i));
1459 fileList.selectByUrl(selectedUrls);
1462 public void emptyContainer(final Folder container) {
1463 String path = "/" + container.getName() + "?delimiter=/";
1464 DeleteRequest delete = new DeleteRequest(getApiPath(), getUserID(), path) {
1467 protected void onUnauthorized(Response response) {
1472 public void onSuccess(Resource result) {
1473 updateFolder(container, true, null, true);
1477 public void onError(Throwable t) {
1478 GWT.log("Error deleting trash", t);
1480 if(t instanceof RestException) {
1481 displayError("Error deleting trash: " + ((RestException) t).getHttpStatusText());
1484 displayError("System error deleting trash: " + t.getMessage());
1488 delete.setHeader(Const.X_AUTH_TOKEN, getUserToken());
1489 Scheduler.get().scheduleDeferred(delete);