X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/b8822fe7bee6b7c4924a5c58e9ff588bf1e4f14a..1a0db4f4e007b18707f875e8129e7b418da5f822:/src/gr/grnet/pithos/web/client/Pithos.java diff --git a/src/gr/grnet/pithos/web/client/Pithos.java b/src/gr/grnet/pithos/web/client/Pithos.java index f420b4d..2adb7fd 100644 --- a/src/gr/grnet/pithos/web/client/Pithos.java +++ b/src/gr/grnet/pithos/web/client/Pithos.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 GRNET S.A. All rights reserved. + * Copyright 2011-2012 GRNET S.A. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following @@ -34,92 +34,90 @@ */ package gr.grnet.pithos.web.client; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONObject; -import com.google.gwt.json.client.JSONParser; -import com.google.gwt.json.client.JSONString; -import com.google.gwt.json.client.JSONValue; -import com.google.gwt.user.client.Command; -import com.google.gwt.view.client.SelectionChangeEvent; -import com.google.gwt.view.client.SelectionChangeEvent.Handler; -import com.google.gwt.view.client.SingleSelectionModel; -import gr.grnet.pithos.web.client.commands.GetUserCommand; +import gr.grnet.pithos.web.client.commands.UploadFileCommand; import gr.grnet.pithos.web.client.foldertree.AccountResource; import gr.grnet.pithos.web.client.foldertree.File; import gr.grnet.pithos.web.client.foldertree.Folder; import gr.grnet.pithos.web.client.foldertree.FolderTreeView; import gr.grnet.pithos.web.client.foldertree.FolderTreeViewModel; import gr.grnet.pithos.web.client.foldertree.Resource; +import gr.grnet.pithos.web.client.grouptree.Group; +import gr.grnet.pithos.web.client.grouptree.GroupTreeView; +import gr.grnet.pithos.web.client.grouptree.GroupTreeViewModel; +import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView; +import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel; +import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView; +import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeViewModel; import gr.grnet.pithos.web.client.rest.DeleteRequest; import gr.grnet.pithos.web.client.rest.GetRequest; +import gr.grnet.pithos.web.client.rest.HeadRequest; import gr.grnet.pithos.web.client.rest.PutRequest; import gr.grnet.pithos.web.client.rest.RestException; -import gr.grnet.pithos.web.client.rest.resource.FileResource; -import gr.grnet.pithos.web.client.rest.resource.OtherUserResource; -import gr.grnet.pithos.web.client.rest.resource.RestResource; -import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; -import gr.grnet.pithos.web.client.rest.resource.SharedResource; -import gr.grnet.pithos.web.client.rest.resource.TrashResource; -import gr.grnet.pithos.web.client.rest.resource.UserResource; - import gr.grnet.pithos.web.client.tagtree.Tag; -import gr.grnet.pithos.web.client.tagtree.TagTreeView; -import gr.grnet.pithos.web.client.tagtree.TagTreeViewModel; + import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Set; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.logical.shared.ResizeEvent; import com.google.gwt.event.logical.shared.ResizeHandler; -import com.google.gwt.event.logical.shared.SelectionEvent; -import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.http.client.Request; +import com.google.gwt.http.client.RequestBuilder; +import com.google.gwt.http.client.RequestCallback; +import com.google.gwt.http.client.RequestException; +import com.google.gwt.http.client.Response; import com.google.gwt.http.client.URL; -import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.json.client.JSONArray; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONParser; +import com.google.gwt.json.client.JSONString; +import com.google.gwt.json.client.JSONValue; import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.resources.client.ImageResource.ImageOptions; +import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Cookies; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.History; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.AbstractImagePrototype; -import com.google.gwt.user.client.ui.DecoratedTabPanel; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HasVerticalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.HorizontalSplitPanel; import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.TabPanel; import com.google.gwt.user.client.ui.VerticalPanel; -import java.util.Set; +import com.google.gwt.view.client.SelectionChangeEvent; +import com.google.gwt.view.client.SelectionChangeEvent.Handler; +import com.google.gwt.view.client.SingleSelectionModel; /** * Entry point classes define onModuleLoad(). */ public class Pithos implements EntryPoint, ResizeHandler { - /** - * A constant that denotes the completion of an IncrementalCommand. - */ - public static final boolean DONE = false; + public static final String HOME_CONTAINER = "pithos"; - public static final int VISIBLE_FILE_COUNT = 25; + public static final String TRASH_CONTAINER = "trash"; + public static final Configuration config = GWT.create(Configuration.class); + /** * Instantiate an application-level image bundle. This object will provide * programmatic access to all the images needed by widgets. */ - private static Images images = (Images) GWT.create(Images.class); + static Images images = (Images) GWT.create(Images.class); public String getUsername() { return username; @@ -133,16 +131,24 @@ public class Pithos implements EntryPoint, ResizeHandler { return account; } - public void updateFolder(Folder f) { - folderTreeView.updateFolder(f); + public void updateFolder(Folder f, boolean showfiles, Command callback) { + folderTreeView.updateFolder(f, showfiles, callback); } - public void updateTag(Tag t) { - tagTreeView.updateTag(t); + public void updateGroupNode(Group group) { + groupTreeView.updateGroupNode(group); } - public void updateTags() { - tagTreeViewModel.initialize(getAllTags()); + public void updateMySharedRoot() { + mysharedTreeView.updateRoot(); + } + + public void updateSharedFolder(Folder f, boolean showfiles) { + mysharedTreeView.updateFolder(f, showfiles); + } + + public void updateOtherSharedFolder(Folder f, boolean showfiles) { + otherSharedTreeView.updateFolder(f, showfiles); } public List getAllTags() { @@ -155,45 +161,31 @@ public class Pithos implements EntryPoint, ResizeHandler { return tagList; } + public MysharedTreeView getMySharedTreeView() { + return mysharedTreeView; + } + /** * An aggregate image bundle that pulls together all the images for this * application into a single bundle. */ - public interface Images extends ClientBundle, TopPanel.Images, StatusPanel.Images, FileMenu.Images, EditMenu.Images, SettingsMenu.Images, FilePropertiesDialog.Images, MessagePanel.Images, FileList.Images, Search.Images, CellTreeView.Images { + public interface Images extends TopPanel.Images, FileList.Images, ToolsMenu.Images { @Source("gr/grnet/pithos/resources/document.png") ImageResource folders(); - @Source("gr/grnet/pithos/resources/edit_group_22.png") - ImageResource groups(); - - @Source("gr/grnet/pithos/resources/search.png") - ImageResource search(); - } - - /** - * The single Pithos instance. - */ - private static Pithos singleton; - - /** - * Gets the singleton Pithos instance. - * - * @return the Pithos object - */ - public static Pithos get() { - if (Pithos.singleton == null) - Pithos.singleton = new Pithos(); - return Pithos.singleton; + @Source("gr/grnet/pithos/resources/advancedsettings.png") + @ImageOptions(width=32, height=32) + ImageResource tools(); } + private Throwable error; + /** * The Application Clipboard implementation; */ private Clipboard clipboard = new Clipboard(); - private UserResource currentUserResource; - /** * The top panel that contains the menu bar. */ @@ -202,7 +194,7 @@ public class Pithos implements EntryPoint, ResizeHandler { /** * The panel that contains the various system messages. */ - private MessagePanel messagePanel = new MessagePanel(Pithos.images); + private MessagePanel messagePanel = new MessagePanel(this, Pithos.images); /** * The bottom panel that contains the status bar. @@ -210,11 +202,6 @@ public class Pithos implements EntryPoint, ResizeHandler { private StatusPanel statusPanel = null; /** - * The top right panel that displays the logged in user details - */ - private UserDetailsPanel userDetailsPanel = new UserDetailsPanel(); - - /** * The file list widget. */ private FileList fileList; @@ -222,16 +209,7 @@ public class Pithos implements EntryPoint, ResizeHandler { /** * The tab panel that occupies the right side of the screen. */ - private TabPanel inner = new DecoratedTabPanel(){ - -// public void onBrowserEvent(com.google.gwt.user.client.Event event) { -// if (DOM.eventGetType(event) == Event.ONCONTEXTMENU){ -// if(isFileListShowing()){ -// getFileList().showContextMenu(event); -// } -// } -// }; - }; + private VerticalPanel inner = new VerticalPanel(); /** @@ -240,22 +218,11 @@ public class Pithos implements EntryPoint, ResizeHandler { private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel(); /** - * The widget that displays the tree of folders. - */ - - private CellTreeView treeView = null; - /** * The currently selected item in the application, for use by the Edit menu * commands. Potential types are Folder, File, User and Group. */ private Object currentSelection; - - /** - * The WebDAV password of the current user - */ - private String webDAVPassword; - public HashMap userFullNameMap = new HashMap(); private String username = null; @@ -265,109 +232,190 @@ public class Pithos implements EntryPoint, ResizeHandler { */ private String token; - private SingleSelectionModel folderTreeSelectionModel; - private FolderTreeViewModel folderTreeViewModel; - private FolderTreeView folderTreeView; - - private SingleSelectionModel tagTreeSelectionModel; - private TagTreeViewModel tagTreeViewModel; - private TagTreeView tagTreeView; - - private AccountResource account; - + VerticalPanel trees; + + SingleSelectionModel folderTreeSelectionModel; + FolderTreeViewModel folderTreeViewModel; + FolderTreeView folderTreeView; + + SingleSelectionModel mysharedTreeSelectionModel; + MysharedTreeViewModel mysharedTreeViewModel; + MysharedTreeView mysharedTreeView = null;; + + protected SingleSelectionModel otherSharedTreeSelectionModel; + OtherSharedTreeViewModel otherSharedTreeViewModel; + OtherSharedTreeView otherSharedTreeView = null; + + GroupTreeViewModel groupTreeViewModel; + private GroupTreeView groupTreeView; + + TreeView selectedTree; + protected AccountResource account; + + Folder trash; + + List treeViews = new ArrayList(); + + @SuppressWarnings("rawtypes") List selectionModels = new ArrayList(); + + Button upload; + + private HTML usedBytes; + + private HTML totalBytes; + + private HTML usedPercent; + + private HTML numOfFiles; + + private Toolbar toolbar; + + private FileUploadDialog fileUploadDialog; + @Override public void onModuleLoad() { - // Initialize the singleton before calling the constructors of the - // various widgets that might call Pithos.get(). - singleton = this; if (parseUserCredentials()) initialize(); } private void initialize() { - topPanel = new TopPanel(Pithos.images); - topPanel.setWidth("100%"); + boolean bareContent = Window.Location.getParameter("noframe") != null; + String contentWidth = bareContent ? "100%" : "75%"; - messagePanel.setWidth("100%"); + VerticalPanel outer = new VerticalPanel(); + outer.setWidth("100%"); + if (!bareContent) { + outer.addStyleName("pithos-outer"); + } + + if (!bareContent) { + topPanel = new TopPanel(this, Pithos.images); + topPanel.setWidth("100%"); + outer.add(topPanel); + outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER); + } + messagePanel.setVisible(false); - - - // Inner contains the various lists. - inner.sinkEvents(Event.ONCONTEXTMENU); - inner.setAnimationEnabled(true); - inner.getTabBar().addStyleName("pithos-MainTabBar"); - inner.getDeckPanel().addStyleName("pithos-MainTabPanelBottom"); - - inner.setWidth("100%"); - - inner.addSelectionHandler(new SelectionHandler() { - + outer.add(messagePanel); + outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); + outer.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE); + + HorizontalPanel header = new HorizontalPanel(); + header.addStyleName("pithos-header"); + header.setWidth(contentWidth); + if (bareContent) + header.addStyleName("pithos-header-noframe"); + upload = new Button("Upload", new ClickHandler() { @Override - public void onSelection(SelectionEvent event) { - int tabIndex = event.getSelectedItem(); - switch (tabIndex) { - case 0: - fileList.updateCurrentlyShowingStats(); - break; - } + public void onClick(ClickEvent event) { + if (getSelection() != null) + new UploadFileCommand(Pithos.this, null, getSelection()).execute(); } }); + upload.addStyleName("pithos-uploadButton"); + header.add(upload); + header.setCellHorizontalAlignment(upload, HasHorizontalAlignment.ALIGN_LEFT); + header.setCellVerticalAlignment(upload, HasVerticalAlignment.ALIGN_MIDDLE); + + toolbar = new Toolbar(this); + header.add(toolbar); + header.setCellHorizontalAlignment(toolbar, HasHorizontalAlignment.ALIGN_CENTER); + header.setCellVerticalAlignment(toolbar, HasVerticalAlignment.ALIGN_MIDDLE); + + HorizontalPanel folderStatistics = new HorizontalPanel(); + folderStatistics.addStyleName("pithos-folderStatistics"); + numOfFiles = new HTML(); + folderStatistics.add(numOfFiles); + folderStatistics.setCellVerticalAlignment(numOfFiles, HasVerticalAlignment.ALIGN_MIDDLE); + HTML numOfFilesLabel = new HTML(" Files"); + folderStatistics.add(numOfFilesLabel); + folderStatistics.setCellVerticalAlignment(numOfFilesLabel, HasVerticalAlignment.ALIGN_MIDDLE); + header.add(folderStatistics); + header.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT); + header.setCellVerticalAlignment(folderStatistics, HasVerticalAlignment.ALIGN_MIDDLE); + header.setCellWidth(folderStatistics, "40px"); + outer.add(header); + outer.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_CENTER); + // Inner contains the various lists.nner + inner.sinkEvents(Event.ONCONTEXTMENU); + inner.setWidth("100%"); folderTreeSelectionModel = new SingleSelectionModel(); folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(SelectionChangeEvent event) { if (folderTreeSelectionModel.getSelectedObject() != null) { - tagTreeSelectionModel.setSelected(tagTreeSelectionModel.getSelectedObject(), false); + deselectOthers(folderTreeView, folderTreeSelectionModel); + applyPermissions(folderTreeSelectionModel.getSelectedObject()); Folder f = folderTreeSelectionModel.getSelectedObject(); - updateFolder(f); + updateFolder(f, true, new Command() { + + @Override + public void execute() { + updateStatistics(); + } + }); } + showRelevantToolbarButtons(); } }); + selectionModels.add(folderTreeSelectionModel); - folderTreeViewModel = new FolderTreeViewModel(folderTreeSelectionModel); + folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel); folderTreeView = new FolderTreeView(folderTreeViewModel); + treeViews.add(folderTreeView); + + fileList = new FileList(this, images, folderTreeView); + inner.add(fileList); + + groupTreeViewModel = new GroupTreeViewModel(this); + groupTreeView = new GroupTreeView(groupTreeViewModel); + treeViews.add(groupTreeView); + + trees = new VerticalPanel(); + trees.setWidth("100%"); + + + HorizontalPanel treeHeader = new HorizontalPanel(); + treeHeader.addStyleName("pithos-treeHeader"); + treeHeader.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); + treeHeader.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); + HorizontalPanel statistics = new HorizontalPanel(); + statistics.addStyleName("pithos-statistics"); + statistics.add(new HTML("Used: ")); + usedBytes = new HTML(); + statistics.add(usedBytes); + statistics.add(new HTML(" of ")); + totalBytes = new HTML(); + statistics.add(totalBytes); + statistics.add(new HTML(" (")); + usedPercent = new HTML(); + statistics.add(usedPercent); + statistics.add(new HTML(")")); + treeHeader.add(statistics); + treeHeader.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_LEFT); + trees.add(treeHeader); - fileList = new FileList(images, folderTreeView); - inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true); - - tagTreeSelectionModel = new SingleSelectionModel(); - tagTreeSelectionModel.addSelectionChangeHandler(new Handler() { - @Override - public void onSelectionChange(SelectionChangeEvent event) { - if (tagTreeSelectionModel.getSelectedObject() != null) { - folderTreeSelectionModel.setSelected(folderTreeSelectionModel.getSelectedObject(), false); - Tag t = tagTreeSelectionModel.getSelectedObject(); - updateTag(t); - } - } - }); - tagTreeViewModel = new TagTreeViewModel(tagTreeSelectionModel); - tagTreeView = new TagTreeView(tagTreeViewModel); - - VerticalPanel trees = new VerticalPanel(); trees.add(folderTreeView); - trees.add(tagTreeView); + trees.add(groupTreeView); // Add the left and right panels to the split panel. splitPanel.setLeftWidget(trees); splitPanel.setRightWidget(inner); - splitPanel.setSplitPosition("25%"); + splitPanel.setSplitPosition("35%"); splitPanel.setSize("100%", "100%"); splitPanel.addStyleName("pithos-splitPanel"); - - // Create a dock panel that will contain the menu bar at the top, - // the shortcuts to the left, the status bar at the bottom and the - // right panel taking the rest. - VerticalPanel outer = new VerticalPanel(); - outer.add(topPanel); - outer.add(messagePanel); + splitPanel.setWidth(contentWidth); outer.add(splitPanel); - statusPanel = new StatusPanel(Pithos.images); - outer.add(statusPanel); - outer.setWidth("100%"); - outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER); + outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER); - outer.setSpacing(4); + if (!bareContent) { + statusPanel = new StatusPanel(); + statusPanel.setWidth("100%"); + outer.add(statusPanel); + outer.setCellHorizontalAlignment(statusPanel, HasHorizontalAlignment.ALIGN_CENTER); + } + else + splitPanel.addStyleName("pithos-splitPanel-noframe"); // Hook the window resize event, so that we can adjust the UI. Window.addResizeHandler(this); @@ -391,46 +439,110 @@ public class Pithos implements EntryPoint, ResizeHandler { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { - fetchAccount(); + fetchAccount(new Command() { + + @Override + public void execute() { + if (!account.hasHomeContainer()) + createHomeContainer(account, this); + else if (!account.hasTrashContainer()) + createTrashContainer(this); + else { + for (Folder f : account.getContainers()) + if (f.getName().equals(Pithos.TRASH_CONTAINER)) { + trash = f; + break; + } + folderTreeViewModel.initialize(account, new Command() { + + @Override + public void execute() { + createMySharedTree(); + } + }); + groupTreeViewModel.initialize(); + showStatistics(); + } + } + }); } }); + +// Scheduler.get().scheduleDeferred(new Command() { +// +// @Override +// public void execute() { +// displayError("lalala"); +// +// } +// }); } - public void showFiles(Folder f) { - inner.selectTab(0); - if (f.isTrash()) { - fileList.showTrash(); - } - else - fileList.showFiles(); + public void applyPermissions(Folder f) { + if (f != null) { + if (f.isInTrash()) + upload.setEnabled(false); + else { + Boolean[] perms = f.getPermissions().get(username); + if (f.getOwner().equals(username) || (perms != null && perms[1] != null && perms[1])) { + upload.setEnabled(true); + } + else + upload.setEnabled(false); + } + } + else + upload.setEnabled(false); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public void deselectOthers(TreeView _selectedTree, SingleSelectionModel model) { + selectedTree = _selectedTree; + + for (Composite c : treeViews) + if (c.equals(selectedTree)) + c.addStyleName("cellTreeWidget-selectedTree"); + else + c.removeStyleName("cellTreeWidget-selectedTree"); + + for (SingleSelectionModel s : selectionModels) + if (!s.equals(model)) + s.setSelected(s.getSelectedObject(), false); + } + + public void showFiles(final Folder f) { Set files = f.getFiles(); showFiles(files); } public void showFiles(Set files) { - //Iterator iter = files.iterator(); - //fetchFile(iter, files); fileList.setFiles(new ArrayList(files)); } - private void fetchFile(final Iterator iter, final Set files) { + protected void fetchFile(final Iterator iter, final Set files) { if (iter.hasNext()) { File file = iter.next(); - String path = getApiPath() + username + "/" + file.getContainer() + "/" + file.getPath() + "?format=json"; - GetRequest getFile = new GetRequest(File.class, path, file) { + String path = file.getUri() + "?format=json"; + GetRequest getFile = new GetRequest(File.class, getApiPath(), username, path, file) { @Override - public void onSuccess(File result) { + public void onSuccess(File _result) { fetchFile(iter, files); } @Override public void onError(Throwable t) { GWT.log("Error getting file", t); + setError(t); if (t instanceof RestException) - Pithos.get().displayError("Error getting file: " + ((RestException) t).getHttpStatusText()); + displayError("Error getting file: " + ((RestException) t).getHttpStatusText()); else - Pithos.get().displayError("System error fetching file: " + t.getMessage()); + displayError("System error fetching file: " + t.getMessage()); } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } }; getFile.setHeader("X-Auth-Token", "0000"); Scheduler.get().scheduleDeferred(getFile); @@ -443,102 +555,163 @@ public class Pithos implements EntryPoint, ResizeHandler { * Parse and store the user credentials to the appropriate fields. */ private boolean parseUserCredentials() { - Configuration conf = (Configuration) GWT.create(Configuration.class); - String cookie = conf.authCookie(); - String auth = Cookies.getCookie(cookie); - if (auth == null) { - authenticateUser(); - return false; - } - else { - String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); - if (authSplit.length != 2) { + username = Window.Location.getParameter("user"); + token = Window.Location.getParameter("token"); + Configuration conf = (Configuration) GWT.create(Configuration.class); + if (username == null || username.length() == 0 || token == null || token.length() == 0) { + String cookie = conf.authCookie(); + String auth = Cookies.getCookie(cookie); + if (auth == null) { authenticateUser(); return false; } - else { - username = authSplit[0]; - token = authSplit[1]; - return true; - } + if (auth.startsWith("\"")) + auth = auth.substring(1); + if (auth.endsWith("\"")) + auth = auth.substring(0, auth.length() - 1); + String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2); + if (authSplit.length != 2) { + authenticateUser(); + return false; + } + username = authSplit[0]; + token = authSplit[1]; + return true; } - } + + Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token, null, "", "/", false); + return true; + } /** * Redirect the user to the login page for authentication. */ protected void authenticateUser() { - Configuration conf = (Configuration) GWT.create(Configuration.class); - -// Window.Location.assign(GWT.getModuleBaseURL() + conf.loginUrl() + "?next=" + Window.Location.getHref()); - Cookies.setCookie(conf.authCookie(), "test" + conf.cookieSeparator() + "0000"); - Window.Location.assign(GWT.getModuleBaseURL() + "pithos.html"); + Window.Location.assign(config.loginUrl()); } - private void fetchAccount() { - String path = getApiPath() + username + "?format=json"; + protected void fetchAccount(final Command callback) { + String path = "?format=json"; - GetRequest getAccount = new GetRequest(AccountResource.class, path) { + GetRequest getAccount = new GetRequest(AccountResource.class, getApiPath(), username, path) { @Override - public void onSuccess(AccountResource result) { - account = result; - statusPanel.displayStats(account); - inner.selectTab(0); - if (account.getContainers().isEmpty()) - createHomeContainers(); - else - folderTreeViewModel.initialize(account); + public void onSuccess(AccountResource _result) { + account = _result; + if (callback != null) + callback.execute(); } @Override public void onError(Throwable t) { GWT.log("Error getting account", t); + setError(t); if (t instanceof RestException) - Pithos.get().displayError("Error getting account: " + ((RestException) t).getHttpStatusText()); + displayError("Error getting account: " + ((RestException) t).getHttpStatusText()); else - Pithos.get().displayError("System error fetching user data: " + t.getMessage()); + displayError("System error fetching user data: " + t.getMessage()); } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } }; getAccount.setHeader("X-Auth-Token", token); Scheduler.get().scheduleDeferred(getAccount); } - private void createHomeContainers() { - String path = getApiPath() + getUsername() + "/pithos"; - PutRequest createPithos = new PutRequest(path) { + public void updateStatistics() { + HeadRequest headAccount = new HeadRequest(AccountResource.class, getApiPath(), username, "", account) { + + @Override + public void onSuccess(AccountResource _result) { + showStatistics(); + } + + @Override + public void onError(Throwable t) { + GWT.log("Error getting account", t); + setError(t); + if (t instanceof RestException) + displayError("Error getting account: " + ((RestException) t).getHttpStatusText()); + else + displayError("System error fetching user data: " + t.getMessage()); + } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } + }; + headAccount.setHeader("X-Auth-Token", token); + Scheduler.get().scheduleDeferred(headAccount); + } + + protected void showStatistics() { + usedBytes.setHTML(String.valueOf(account.getFileSizeAsString())); + totalBytes.setHTML(String.valueOf(account.getQuotaAsString())); + NumberFormat nf = NumberFormat.getPercentFormat(); + usedPercent.setHTML(nf.format(account.getUsedPercentage())); + } + + protected void createHomeContainer(final AccountResource _account, final Command callback) { + String path = "/" + Pithos.HOME_CONTAINER; + PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) { @Override public void onSuccess(Resource result) { - fetchAccount(); + if (!_account.hasTrashContainer()) + createTrashContainer(callback); + else + fetchAccount(callback); } @Override public void onError(Throwable t) { GWT.log("Error creating pithos", t); + setError(t); if (t instanceof RestException) - Pithos.get().displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText()); + displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText()); else - Pithos.get().displayError("System error Error creating pithos: " + t.getMessage()); + displayError("System error Error creating pithos: " + t.getMessage()); } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } }; createPithos.setHeader("X-Auth-Token", getToken()); Scheduler.get().scheduleDeferred(createPithos); } - /** - * Clear the cookie and redirect the user to the logout page. - */ - void logout() { - Configuration conf = (Configuration) GWT.create(Configuration.class); - String cookie = conf.authCookie(); - String domain = Window.Location.getHostName(); - String path = Window.Location.getPath(); - Cookies.setCookie(cookie, "", null, domain, path, false); - String baseUrl = GWT.getModuleBaseURL(); - String homeUrl = baseUrl.substring(0, baseUrl.indexOf(path)); - Window.Location.assign(homeUrl + conf.logoutUrl()); - } + protected void createTrashContainer(final Command callback) { + String path = "/" + Pithos.TRASH_CONTAINER; + PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) { + @Override + public void onSuccess(Resource result) { + fetchAccount(callback); + } - /** + @Override + public void onError(Throwable t) { + GWT.log("Error creating pithos", t); + setError(t); + if (t instanceof RestException) + displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText()); + else + displayError("System error Error creating pithos: " + t.getMessage()); + } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } + }; + createPithos.setHeader("X-Auth-Token", getToken()); + Scheduler.get().scheduleDeferred(createPithos); + } + + /** * Creates an HTML fragment that places an image & caption together, for use * in a group header. * @@ -554,9 +727,9 @@ public class Pithos implements EntryPoint, ResizeHandler { return captionHTML; } - private void onWindowResized(int height) { + protected void onWindowResized(int height) { // Adjust the split panel to take up the available room in the window. - int newHeight = height - splitPanel.getAbsoluteTop() - 44; + int newHeight = height - splitPanel.getAbsoluteTop(); if (newHeight < 1) newHeight = 1; splitPanel.setHeight("" + newHeight); @@ -569,93 +742,6 @@ public class Pithos implements EntryPoint, ResizeHandler { onWindowResized(height); } - public boolean isFileListShowing() { - int tab = inner.getTabBar().getSelectedTab(); - if (tab == 0) - return true; - return false; - } - - public boolean isSearchResultsShowing() { - int tab = inner.getTabBar().getSelectedTab(); - if (tab == 2) - return true; - return false; - } - - /** - * Make the file list visible. - * - * @param update - */ - public void showFileList(boolean update) { - if(update){ - getTreeView().refreshCurrentNode(true); - } - else{ - RestResource currentFolder = getTreeView().getSelection(); - if(currentFolder!=null){ - showFileList(currentFolder); - } - } - - } - - public void showFileList(RestResource r) { - showFileList(r,true); - } - - public void showFileList(RestResource r, boolean clearSelection) { - RestResource currentFolder = r; - if(currentFolder!=null){ - List files = null; - if (currentFolder instanceof RestResourceWrapper) { - RestResourceWrapper folder = (RestResourceWrapper) currentFolder; - files = folder.getResource().getFiles(); - } - } - inner.selectTab(0); - } - - /** - * Display the 'loading' indicator. - */ - public void showLoadingIndicator(String message, String path) { - if(path!=null){ - String[] split = path.split("/"); - message = message +" "+URL.decode(split[split.length-1]); - } - topPanel.getLoading().show(message); - } - - /** - * Hide the 'loading' indicator. - */ - public void hideLoadingIndicator() { - topPanel.getLoading().hide(); - } - - /** - * A native JavaScript method to reach out to the browser's window and - * invoke its resizeTo() method. - * - * @param x the new width - * @param y the new height - */ - public static native void resizeTo(int x, int y) /*-{ - $wnd.resizeTo(x,y); - }-*/; - - /** - * A helper method that returns true if the user's list is currently visible - * and false if it is hidden. - * - * @return true if the user list is visible - */ - public boolean isUserListVisible() { - return inner.getTabBar().getSelectedTab() == 1; - } - /** * Display an error message. * @@ -684,33 +770,6 @@ public class Pithos implements EntryPoint, ResizeHandler { } /** - * Retrieve the folders. - * - * @return the folders - - public Folders getFolders() { - return folders; - }*/ - - /** - * Retrieve the currentSelection. - * - * @return the currentSelection - */ - public Object getCurrentSelection() { - return currentSelection; - } - - /** - * Modify the currentSelection. - * - * @param newCurrentSelection the currentSelection to set - */ - public void setCurrentSelection(Object newCurrentSelection) { - currentSelection = newCurrentSelection; - } - - /** * Retrieve the fileList. * * @return the fileList @@ -741,43 +800,10 @@ public class Pithos implements EntryPoint, ResizeHandler { return statusPanel; } - /** - * Retrieve the userDetailsPanel. - * - * @return the userDetailsPanel - */ - public UserDetailsPanel getUserDetailsPanel() { - return userDetailsPanel; - } - - - public String getToken() { return token; } - public String getWebDAVPassword() { - return webDAVPassword; - } - - /** - * Retrieve the currentUserResource. - * - * @return the currentUserResource - */ - public UserResource getCurrentUserResource() { - return currentUserResource; - } - - /** - * Modify the currentUserResource. - * - * @param newUser the new currentUserResource - */ - public void setCurrentUserResource(UserResource newUser) { - currentUserResource = newUser; - } - public static native void preventIESelection() /*-{ $doc.body.onselectstart = function () { return false; }; }-*/; @@ -796,25 +822,6 @@ public class Pithos implements EntryPoint, ResizeHandler { } /** - * Convert server date to local time according to browser timezone - * and format it according to localized pattern. - * Time is always formatted to 24hr format. - * NB: This assumes that server runs in UTC timezone. Otherwise - * we would need to adjust for server time offset as well. - * - * @param date - * @return String - */ - public static String formatLocalDateTime(Date date) { - Date convertedDate = new Date(date.getTime() - date.getTimezoneOffset()); - final DateTimeFormat dateFormatter = DateTimeFormat.getShortDateFormat(); - final DateTimeFormat timeFormatter = DateTimeFormat.getFormat("HH:mm"); - String datePart = dateFormatter.format(convertedDate); - String timePart = timeFormatter.format(convertedDate); - return datePart + " " + timePart; - } - - /** * History support for folder navigation * adds a new browser history entry * @@ -828,72 +835,9 @@ public class Pithos implements EntryPoint, ResizeHandler { History.newItem(key); } - /** - * This method examines the token input and add a "/" at the end in case it's omitted. - * This happens only in Files/trash/, Files/shared/, Files/others. - * - * @param tokenInput - * @return the formated token with a "/" at the end or the same tokenInput parameter - */ - - private String handleSpecialFolderNames(String tokenInput){ - List pathsToCheck = Arrays.asList("Files/trash", "Files/shared", "Files/others"); - if(pathsToCheck.contains(tokenInput)) - return tokenInput + "/"; - return tokenInput; - - } - - /** - * Reject illegal resource names, like '.' or '..' or slashes '/'. - */ - static boolean isValidResourceName(String name) { - if (".".equals(name) || "..".equals(name) || name.contains("/")) - return false; - return true; - } - - public void putUserToMap(String _userName, String _userFullName){ - userFullNameMap.put(_userName, _userFullName); - } - - public String findUserFullName(String _userName){ - return userFullNameMap.get(_userName); - } - public String getUserFullName(String _userName) { - - if (Pithos.get().findUserFullName(_userName) == null) - //if there is no userFullName found then the map fills with the given _userName, - //so userFullName = _userName - Pithos.get().putUserToMap(_userName, _userName); - else if(Pithos.get().findUserFullName(_userName).indexOf('@') != -1){ - //if the userFullName = _userName the GetUserCommand updates the userFullName in the map - GetUserCommand guc = new GetUserCommand(_userName); - guc.execute(); - } - return Pithos.get().findUserFullName(_userName); - } - /** - * Retrieve the treeView. - * - * @return the treeView - */ - public CellTreeView getTreeView() { - return treeView; - } - - public void onResourceUpdate(RestResource resource,boolean clearSelection){ - if(resource instanceof RestResourceWrapper || resource instanceof OtherUserResource || resource instanceof TrashResource || resource instanceof SharedResource){ - if(getTreeView().getSelection()!=null&&getTreeView().getSelection().getUri().equals(resource.getUri())) - showFileList(resource,clearSelection); - } - - } - public void deleteFolder(final Folder folder) { - String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + folder.getPrefix(); + String path = getApiPath() + folder.getOwner() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(folder.getPrefix()) + "&t=" + System.currentTimeMillis(); RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path); - builder.setHeader("If-Modified-Since", "0"); builder.setHeader("X-Auth-Token", getToken()); try { builder.sendRequest("", new RequestCallback() { @@ -911,7 +855,8 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Request request, Throwable exception) { - Pithos.get().displayError("System error unable to delete folder: " + exception.getMessage()); + setError(exception); + displayError("System error unable to delete folder: " + exception.getMessage()); } }); } @@ -919,13 +864,13 @@ public class Pithos implements EntryPoint, ResizeHandler { } } - public void deleteObject(final Folder folder, final int i, final JSONArray array) { + void deleteObject(final Folder folder, final int i, final JSONArray array) { if (i < array.size()) { JSONObject o = array.get(i).isObject(); if (o != null && !o.containsKey("subdir")) { JSONString name = o.get("name").isString(); - String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "/" + name.stringValue(); - DeleteRequest delete = new DeleteRequest(path) { + String path = "/" + folder.getContainer() + "/" + name.stringValue(); + DeleteRequest delete = new DeleteRequest(getApiPath(), folder.getOwner(), URL.encode(path)) { @Override public void onSuccess(Resource result) { deleteObject(folder, i + 1, array); @@ -934,18 +879,23 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Throwable t) { GWT.log("", t); - Pithos.get().displayError("System error unable to delete folder: " + t.getMessage()); + setError(t); + displayError("System error unable to delete folder: " + t.getMessage()); } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } }; delete.setHeader("X-Auth-Token", getToken()); Scheduler.get().scheduleDeferred(delete); } - else { + else if (o != null) { String subdir = o.get("subdir").isString().stringValue(); subdir = subdir.substring(0, subdir.length() - 1); - String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + subdir; + String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(subdir) + "&t=" + System.currentTimeMillis(); RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path); - builder.setHeader("If-Modified-Since", "0"); builder.setHeader("X-Auth-Token", getToken()); try { builder.sendRequest("", new RequestCallback() { @@ -966,7 +916,8 @@ public class Pithos implements EntryPoint, ResizeHandler { @Override public void onError(Request request, Throwable exception) { - Pithos.get().displayError("System error unable to delete folder: " + exception.getMessage()); + setError(exception); + displayError("System error unable to delete folder: " + exception.getMessage()); } }); } @@ -975,23 +926,37 @@ public class Pithos implements EntryPoint, ResizeHandler { } } else { - String prefix = folder.getPrefix(); - String path = getApiPath() + getUsername() + "/" + folder.getContainer() + (prefix.length() == 0 ? "" : "/" + prefix); - DeleteRequest deleteFolder = new DeleteRequest(path) { + String path = folder.getUri(); + DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), URL.encode(path)) { @Override public void onSuccess(Resource result) { - updateFolder(folder.getParent()); + updateFolder(folder.getParent(), true, new Command() { + + @Override + public void execute() { + updateStatistics(); + } + }); } @Override public void onError(Throwable t) { GWT.log("", t); + setError(t); if (t instanceof RestException) { - displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText()); + if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND) + displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText()); + else + onSuccess(null); } else - Pithos.get().displayError("System error unable to delete folder: " + t.getMessage()); + displayError("System error unable to delete folder: " + t.getMessage()); } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } }; deleteFolder.setHeader("X-Auth-Token", getToken()); Scheduler.get().scheduleDeferred(deleteFolder); @@ -1002,28 +967,37 @@ public class Pithos implements EntryPoint, ResizeHandler { return folderTreeView; } - public void copyFiles(final Iterator iter, final String targetUri, final Command callback) { + public void copyFiles(final Iterator iter, final String targetUsername, final String targetUri, final Command callback) { if (iter.hasNext()) { File file = iter.next(); - String path = getApiPath() + getUsername() + targetUri + "/" + file.getName(); - PutRequest copyFile = new PutRequest(path) { + String path = targetUri + "/" + file.getName(); + PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) { @Override public void onSuccess(Resource result) { - copyFiles(iter, targetUri, callback); + copyFiles(iter, targetUsername, targetUri, callback); } @Override public void onError(Throwable t) { GWT.log("", t); + setError(t); if (t instanceof RestException) { - Pithos.get().displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText()); + displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText()); } else - Pithos.get().displayError("System error unable to copy file: "+t.getMessage()); + displayError("System error unable to copy file: "+t.getMessage()); } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } }; copyFile.setHeader("X-Auth-Token", getToken()); - copyFile.setHeader("X-Copy-From", file.getUri()); + copyFile.setHeader("X-Copy-From", URL.encodePathSegment(file.getUri())); + if (!file.getOwner().equals(targetUsername)) + copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner())); + copyFile.setHeader("Content-Type", file.getContentType()); Scheduler.get().scheduleDeferred(copyFile); } else if (callback != null) { @@ -1031,45 +1005,76 @@ public class Pithos implements EntryPoint, ResizeHandler { } } - public void copySubfolders(final Iterator iter, final String targetUri, final Command callback) { + public void copySubfolders(final Iterator iter, final String targetUsername, final String targetUri, final Command callback) { if (iter.hasNext()) { final Folder f = iter.next(); - copyFolder(f, targetUri, callback); + copyFolder(f, targetUsername, targetUri, new Command() { + + @Override + public void execute() { + copySubfolders(iter, targetUsername, targetUri, callback); + } + }); } else if (callback != null) { callback.execute(); } } - public void copyFolder(final Folder f, final String targetUri, final Command callback) { - String path = getApiPath() + getUsername() + targetUri + "/" + f.getName(); - PutRequest createFolder = new PutRequest(path) { + public void copyFolder(final Folder f, final String targetUsername, final String targetUri, final Command callback) { + String path = targetUri + "/" + f.getName(); + PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) { @Override public void onSuccess(Resource result) { - Iterator iter = f.getFiles().iterator(); - copyFiles(iter, targetUri + "/" + f.getName(), new Command() { - @Override - public void execute() { - Iterator iterf = f.getSubfolders().iterator(); - copySubfolders(iterf, targetUri + "/" + f.getName(), new Command() { - @Override - public void execute() { - callback.execute(); - } - }); - } - }); + GetRequest getFolder = new GetRequest(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) { + + @Override + public void onSuccess(final Folder _f) { + Iterator iter = _f.getFiles().iterator(); + copyFiles(iter, targetUsername, targetUri + "/" + _f.getName(), new Command() { + @Override + public void execute() { + Iterator iterf = _f.getSubfolders().iterator(); + copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback); + } + }); + } + + @Override + public void onError(Throwable t) { + GWT.log("", t); + setError(t); + if (t instanceof RestException) { + displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText()); + } + else + displayError("System error getting folder: " + t.getMessage()); + } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } + }; + getFolder.setHeader("X-Auth-Token", getToken()); + Scheduler.get().scheduleDeferred(getFolder); } @Override public void onError(Throwable t) { GWT.log("", t); - if (t instanceof RestException) { - displayError("Unable to create folder:" + ((RestException) t).getHttpStatusText()); + setError(t); + if (t instanceof RestException) { + displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText()); } else - displayError("System error creating folder:" + t.getMessage()); + displayError("System error creating folder: " + t.getMessage()); } + + @Override + protected void onUnauthorized(Response response) { + sessionExpired(); + } }; createFolder.setHeader("X-Auth-Token", getToken()); createFolder.setHeader("Accept", "*/*"); @@ -1077,4 +1082,152 @@ public class Pithos implements EntryPoint, ResizeHandler { createFolder.setHeader("Content-Type", "application/folder"); Scheduler.get().scheduleDeferred(createFolder); } + + public void addSelectionModel(@SuppressWarnings("rawtypes") SingleSelectionModel model) { + selectionModels.add(model); + } + + public OtherSharedTreeView getOtherSharedTreeView() { + return otherSharedTreeView; + } + + public void updateTrash(boolean showFiles, Command callback) { + updateFolder(trash, showFiles, callback); + } + + public void updateGroupsNode() { + groupTreeView.updateGroupNode(null); + } + + public void addGroup(String groupname) { + Group newGroup = new Group(groupname); + account.addGroup(newGroup); + groupTreeView.updateGroupNode(null); + } + + public void removeGroup(Group group) { + account.removeGroup(group); + updateGroupsNode(); + } + + public TreeView getSelectedTree() { + return selectedTree; + } + + public Folder getSelection() { + return selectedTree.getSelection(); + } + + public void showFolderStatistics(int folderFileCount) { + numOfFiles.setHTML(String.valueOf(folderFileCount)); + } + + public GroupTreeView getGroupTreeView() { + return groupTreeView; + } + + public void sessionExpired() { + new SessionExpiredDialog(this).center(); + } + + public void updateRootFolder(Command callback) { + updateFolder(account.getPithos(), false, callback); + } + + void createMySharedTree() { + mysharedTreeSelectionModel = new SingleSelectionModel(); + mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { + @Override + public void onSelectionChange(SelectionChangeEvent event) { + if (mysharedTreeSelectionModel.getSelectedObject() != null) { + deselectOthers(mysharedTreeView, mysharedTreeSelectionModel); + upload.setEnabled(false); + updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true); + } + showRelevantToolbarButtons(); + } + }); + selectionModels.add(mysharedTreeSelectionModel); + mysharedTreeViewModel = new MysharedTreeViewModel(Pithos.this, mysharedTreeSelectionModel); + mysharedTreeViewModel.initialize(new Command() { + + @Override + public void execute() { + mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel); + trees.insert(mysharedTreeView, 2); + treeViews.add(mysharedTreeView); + createOtherSharedTree(); + } + }); + } + + void createOtherSharedTree() { + otherSharedTreeSelectionModel = new SingleSelectionModel(); + otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() { + @Override + public void onSelectionChange(SelectionChangeEvent event) { + if (otherSharedTreeSelectionModel.getSelectedObject() != null) { + deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel); + otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree"); + applyPermissions(otherSharedTreeSelectionModel.getSelectedObject()); + updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true); + } + showRelevantToolbarButtons(); + } + }); + selectionModels.add(otherSharedTreeSelectionModel); + otherSharedTreeViewModel = new OtherSharedTreeViewModel(Pithos.this, otherSharedTreeSelectionModel); + otherSharedTreeViewModel.initialize(new Command() { + + @Override + public void execute() { + otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel); + trees.insert(otherSharedTreeView, 3); + treeViews.add(otherSharedTreeView); + } + }); + } + + public void logoff() { + Cookies.removeCookie(config.authCookie(), "/"); + Cookies.removeCookie(config.authTokenCookie(), "/"); + for (String s: Cookies.getCookieNames()) + if (s.startsWith(config.shibSessionCookiePrefix())) + Cookies.removeCookie(s, "/"); + Window.Location.assign(config.logoutUrl()); + } + + public native void log1(String message)/*-{ + $wnd.console.log(message); + }-*/; + + public String getErrorData() { + if (error != null) + return error.toString(); + return ""; + } + + public void setError(Throwable t) { + error = t; + } + + public void showRelevantToolbarButtons() { + toolbar.showRelevantButtons(); + } + + public FileUploadDialog getFileUploadDialog() { + if (fileUploadDialog == null) + fileUploadDialog = new FileUploadDialog(this); + return fileUploadDialog; + } + + public void hideUploadIndicator() { + upload.removeStyleName("pithos-uploadButton-loading"); + upload.setTitle(""); + } + + public void showUploadIndicator() { + upload.addStyleName("pithos-uploadButton-loading"); + upload.setTitle("Upload in progress. Click for details."); + } }