Implemented move folder
[pithos] / web_client / src / gr / grnet / pithos / web / client / GSS.java
index 40d91a0..e952aa2 100644 (file)
@@ -1,26 +1,62 @@
 /*
- * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
+ * Copyright 2011 GRNET S.A. All rights reserved.
  *
- * This file is part of GSS.
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
  *
- * GSS is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ *   1. Redistributions of source code must retain the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer.
  *
- * GSS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials
+ *      provided with the distribution.
  *
- * You should have received a copy of the GNU General Public License
- * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
  */
 package gr.grnet.pithos.web.client;
 
-import gr.grnet.pithos.web.client.clipboard.Clipboard;
+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.view.client.SelectionChangeEvent;
+import com.google.gwt.view.client.SingleSelectionModel;
 import gr.grnet.pithos.web.client.commands.GetUserCommand;
-import gr.grnet.pithos.web.client.rest.GetCommand;
+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.rest.DeleteRequest;
+import gr.grnet.pithos.web.client.rest.GetRequest;
 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;
@@ -34,6 +70,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 
 import com.google.gwt.core.client.EntryPoint;
@@ -42,28 +79,23 @@ 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.event.logical.shared.ValueChangeEvent;
-import com.google.gwt.event.logical.shared.ValueChangeHandler;
 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.resources.client.ImageResource;
-import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.Cookies;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.DeferredCommand;
 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.DockPanel;
 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
-import com.google.gwt.user.client.ui.HasVerticalAlignment;
 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;
+
 /**
  * Entry point classes define <code>onModuleLoad()</code>.
  */
@@ -82,13 +114,27 @@ public class GSS implements EntryPoint, ResizeHandler {
         */
        private static Images images = (Images) GWT.create(Images.class);
 
-       private GlassPanel glassPanel = new GlassPanel();
+    public String getUsername() {
+        return username;
+    }
 
-       /**
+    public void setAccount(AccountResource acct) {
+        account = acct;
+    }
+
+    public AccountResource getAccount() {
+        return account;
+    }
+
+    public void updateFolder(Folder f) {
+        folderTreeView.updateFolder(f);
+    }
+
+    /**
         * 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, GroupMenu.Images, FilePropertiesDialog.Images, MessagePanel.Images, FileList.Images, SearchResults.Images, Search.Images, Groups.Images, CellTreeView.Images {
+       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 {
 
                @Source("gr/grnet/pithos/resources/document.png")
                ImageResource folders();
@@ -136,7 +182,7 @@ public class GSS implements EntryPoint, ResizeHandler {
        /**
         * The bottom panel that contains the status bar.
         */
-       private StatusPanel statusPanel = new StatusPanel(GSS.images);
+       private StatusPanel statusPanel = null;
 
        /**
         * The top right panel that displays the logged in user details
@@ -149,288 +195,251 @@ public class GSS implements EntryPoint, ResizeHandler {
        private FileList fileList;
 
        /**
-        * The group list widget.
-        */
-       private Groups groups = new Groups(images);
-
-       /**
-        * The search result widget.
-        */
-       private SearchResults searchResults;
-
-       /**
         * 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);
-                               }
-                               else if(isUserListVisible()){
-                                       getGroups().setCurrent(null);
-                                       getGroups().showPopup(event.getClientX(),event.getClientY());
-                               }
-                       }
-               };
+//             public void onBrowserEvent(com.google.gwt.user.client.Event event) {
+//                     if (DOM.eventGetType(event) == Event.ONCONTEXTMENU){
+//                             if(isFileListShowing()){
+//                                     getFileList().showContextMenu(event);
+//                             }
+//                     }
+//             };
        };
 
+
        /**
         * The split panel that will contain the left and right panels.
         */
        private HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
 
        /**
-        * The horizontal panel that will contain the search and status panels.
-        */
-       private DockPanel searchStatus = new DockPanel();
-
-       /**
-        * The search widget.
-        */
-       private Search search;
-
-       /**
         * The widget that displays the tree of folders.
         */
        
-       private CellTreeView treeView = new CellTreeView(images);
+       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 authentication token of the current user.
-        */
-       private String token;
 
        /**
         * The WebDAV password of the current user
         */
        private String webDAVPassword;
 
-       
-
        public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
 
+    private String username = null;
+
+    /**
+     * The authentication token of the current user.
+     */
+    private String token;
+
+    private SingleSelectionModel<Folder> folderTreeSelectionModel;
+    private FolderTreeViewModel folderTreeViewModel;
+    private FolderTreeView folderTreeView;
+
+    private AccountResource account;
+
        @Override
        public void onModuleLoad() {
                // Initialize the singleton before calling the constructors of the
                // various widgets that might call GSS.get().
                singleton = this;
-               RootPanel.get().add(glassPanel, 0, 0);
-               parseUserCredentials();
-               
-               topPanel = new TopPanel(GSS.images);
-               topPanel.setWidth("100%");
-
-               messagePanel.setWidth("100%");
-               messagePanel.setVisible(false);
-
-               search = new Search(images);
-               searchStatus.add(search, DockPanel.WEST);
-               searchStatus.add(userDetailsPanel, DockPanel.EAST);
-               searchStatus.setCellHorizontalAlignment(userDetailsPanel, HasHorizontalAlignment.ALIGN_RIGHT);
-               searchStatus.setCellVerticalAlignment(search, HasVerticalAlignment.ALIGN_MIDDLE);
-               searchStatus.setCellVerticalAlignment(userDetailsPanel, HasVerticalAlignment.ALIGN_MIDDLE);
-               searchStatus.setWidth("100%");
-
-               fileList = new FileList(images);
-
-               searchResults = new SearchResults(images);
-
-               // Inner contains the various lists.
-               inner.sinkEvents(Event.ONCONTEXTMENU);
-               inner.setAnimationEnabled(true);
-               inner.getTabBar().addStyleName("pithos-MainTabBar");
-               inner.getDeckPanel().addStyleName("pithos-MainTabPanelBottom");
-               inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true);
-               
-               inner.add(groups, createHeaderHTML(AbstractImagePrototype.create(images.groups()), "Groups"), true);
-               inner.add(searchResults, createHeaderHTML(AbstractImagePrototype.create(images.search()), "Search Results"), true);
-               //inner.add(new CellTreeView(images), createHeaderHTML(AbstractImagePrototype.create(images.search()), "Cell tree sample"), true);
-               inner.setWidth("100%");
-               inner.selectTab(0);
-
-               inner.addSelectionHandler(new SelectionHandler<Integer>() {
-
-                       @Override
-                       public void onSelection(SelectionEvent<Integer> event) {
-                               int tabIndex = event.getSelectedItem();
-//                             TreeItem treeItem = GSS.get().getFolders().getCurrent();
-                               switch (tabIndex) {
-                                       case 0:
-//                                             Files tab selected
-                                               //fileList.clearSelectedRows();
-                                               fileList.updateCurrentlyShowingStats();
-                                               break;
-                                       case 1:
-//                                             Groups tab selected
-                                               groups.updateCurrentlyShowingStats();
-                                       updateHistory("Groups");
-                                               break;
-                                       case 2:
-//                                             Search tab selected
-                                               searchResults.clearSelectedRows();
-                                               searchResults.updateCurrentlyShowingStats();
-                                       updateHistory("Search");
-                                               break;
-                               }
-                       }
-               });
-//             If the application starts with no history token, redirect to a new "Files" state
-               String initToken = History.getToken();
-               if(initToken.length() == 0)
-                       History.newItem("Files");
-//                Add history listener to handle any history events
-               History.addValueChangeHandler(new ValueChangeHandler<String>() {
-                       @Override
-                       public void onValueChange(ValueChangeEvent<String> event) {
-                               String tokenInput = event.getValue();
-                               String historyToken = handleSpecialFolderNames(tokenInput);
-                               try {
-                                       if(historyToken.equals("Search"))
-                                               inner.selectTab(2);
-                                       else if(historyToken.equals("Groups"))
-                                               inner.selectTab(1);
-                                       else if(historyToken.equals("Files")|| historyToken.length()==0)
-                                               inner.selectTab(0);
-                                       else {
-                                               /*TODO: CELLTREE
-                                               PopupTree popupTree = GSS.get().getFolders().getPopupTree();
-                                               TreeItem treeObj = GSS.get().getFolders().getPopupTree().getTreeItem(historyToken);
-                                               SelectionEvent.fire(popupTree, treeObj);
-                                               */
-                                       }
-                               } catch (IndexOutOfBoundsException e) {
-                                       inner.selectTab(0);
-                               }
-                       }
-               });
-
-               // Add the left and right panels to the split panel.
-               splitPanel.setLeftWidget(treeView);
-               splitPanel.setRightWidget(inner);
-               splitPanel.setSplitPosition("25%");
-               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(searchStatus);
-               outer.add(messagePanel);
-               outer.add(splitPanel);
-               outer.add(statusPanel);
-               outer.setWidth("100%");
-               outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
-
-               outer.setSpacing(4);
-
-               // Hook the window resize event, so that we can adjust the UI.
-               Window.addResizeHandler(this);
-               // Clear out the window's built-in margin, because we want to take
-               // advantage of the entire client area.
-               Window.setMargin("0px");
-               // Finally, add the outer panel to the RootPanel, so that it will be
-               // displayed.
-               RootPanel.get().add(outer);
-               // Call the window resized handler to get the initial sizes setup. Doing
-               // this in a deferred command causes it to occur after all widgets'
-               // sizes have been computed by the browser.
-               DeferredCommand.addCommand(new Command() {
-
-                       @Override
-                       public void execute() {
-                               onWindowResized(Window.getClientHeight());
-                       }
-               });
-       }
-
-       /**
-        * Fetches the User object for the specified username.
-        *
-        * @param username the username of the user
-        */
-       private void fetchUser(final String username) {
-               String path = getApiPath() + username + "/";
-               GetCommand<UserResource> getUserCommand = new GetCommand<UserResource>(UserResource.class, username, path, null) {
-
-                       @Override
-                       public void onComplete() {
-                               
-                               currentUserResource = getResult();
-                               final String announcement = currentUserResource.getAnnouncement();
-                               if (announcement != null)
-                                       DeferredCommand.addCommand(new Command() {
-
-                                               @Override
-                                               public void execute() {
-                                                       displayInformation(announcement);
-                                               }
-                                       });
-                       }
-
-                       @Override
-                       public void onError(Throwable t) {
-                               GWT.log("Fetching user error", t);
-                               if (t instanceof RestException)
-                                       GSS.get().displayError("No user found:" + ((RestException) t).getHttpStatusText());
-                               else
-                                       GSS.get().displayError("System error fetching user data:" + t.getMessage());
-                               authenticateUser();
-                       }
-               };
-               DeferredCommand.addCommand(getUserCommand);
-       }
+               if (parseUserCredentials())
+            initialize();
+       }
+
+    private void initialize() {
+        topPanel = new TopPanel(GSS.images);
+        topPanel.setWidth("100%");
+
+        messagePanel.setWidth("100%");
+        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<Integer>() {
+
+            @Override
+            public void onSelection(SelectionEvent<Integer> event) {
+                int tabIndex = event.getSelectedItem();
+                switch (tabIndex) {
+                    case 0:
+                        fileList.updateCurrentlyShowingStats();
+                        break;
+                }
+            }
+        });
+
+        folderTreeSelectionModel = new SingleSelectionModel<Folder>();
+        folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
+            @Override
+            public void onSelectionChange(SelectionChangeEvent event) {
+                Folder f = folderTreeSelectionModel.getSelectedObject();
+                updateFolder(f);
+            }
+        });
+
+        folderTreeViewModel = new FolderTreeViewModel(folderTreeSelectionModel);
+        folderTreeView = new FolderTreeView(folderTreeViewModel);
+
+        fileList = new FileList(images, folderTreeView);
+        inner.add(fileList, createHeaderHTML(AbstractImagePrototype.create(images.folders()), "Files"), true);
+
+        // Add the left and right panels to the split panel.
+        splitPanel.setLeftWidget(folderTreeView);
+        splitPanel.setRightWidget(inner);
+        splitPanel.setSplitPosition("25%");
+        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);
+        outer.add(splitPanel);
+        statusPanel = new StatusPanel(GSS.images);
+        outer.add(statusPanel);
+        outer.setWidth("100%");
+        outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
+
+        outer.setSpacing(4);
+
+        // Hook the window resize event, so that we can adjust the UI.
+        Window.addResizeHandler(this);
+        // Clear out the window's built-in margin, because we want to take
+        // advantage of the entire client area.
+        Window.setMargin("0px");
+        // Finally, add the outer panel to the RootPanel, so that it will be
+        // displayed.
+        RootPanel.get().add(outer);
+        // Call the window resized handler to get the initial sizes setup. Doing
+        // this in a deferred command causes it to occur after all widgets'
+        // sizes have been computed by the browser.
+        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
+
+            @Override
+            public void execute() {
+                onWindowResized(Window.getClientHeight());
+            }
+        });
+
+        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
+            @Override
+            public void execute() {
+                fetchAccount();
+            }
+        });
+    }
+
+    public void showFiles(Folder f) {
+        inner.selectTab(0);
+        Set<File> files = f.getFiles();
+        Iterator<File> iter = files.iterator();
+        fetchFile(iter, files);
+    }
+
+    private void fetchFile(final Iterator<File> iter, final Set<File> files) {
+        if (iter.hasNext()) {
+            File file = iter.next();
+            String path = getApiPath() + username + "/" + file.getContainer() + "/" + file.getPath() + "?format=json";
+            GetRequest<File> getFile = new GetRequest<File>(File.class, path, file) {
+                @Override
+                public void onSuccess(File result) {
+                    fetchFile(iter, files);
+                }
+
+                @Override
+                public void onError(Throwable t) {
+                    GWT.log("Error getting file", t);
+                    if (t instanceof RestException)
+                        GSS.get().displayError("Error getting file: " + ((RestException) t).getHttpStatusText());
+                    else
+                        GSS.get().displayError("System error fetching file: " + t.getMessage());
+                }
+            };
+            getFile.setHeader("X-Auth-Token", "0000");
+            Scheduler.get().scheduleDeferred(getFile);
+        }
+        else
+            fileList.setFiles(new ArrayList<File>(files));
+    }
 
-       /**
+    /**
         * Parse and store the user credentials to the appropriate fields.
         */
-       private void parseUserCredentials() {
+       private boolean parseUserCredentials() {
                Configuration conf = (Configuration) GWT.create(Configuration.class);
                String cookie = conf.authCookie();
                String auth = Cookies.getCookie(cookie);
                if (auth == null) {
                        authenticateUser();
-                       // Redundant, but silences warnings about possible auth NPE, below.
-                       return;
-               }
-               int sepIndex = auth.indexOf(conf.cookieSeparator());
-               if (sepIndex == -1)
-                       authenticateUser();
-               token = auth.substring(sepIndex + 1);
-               final String username = auth.substring(0, sepIndex);
-               if (username == null)
-                       authenticateUser();
-
-               refreshWebDAVPassword();
-
-               DeferredCommand.addCommand(new Command() {
-
-                       @Override
-                       public void execute() {
-                               fetchUser(username);
-                       }
-               });
+            return false;
+        }
+        else {
+            String[] authSplit = auth.split("\\" + conf.cookieSeparator(), 2);
+            if (authSplit.length != 2) {
+                authenticateUser();
+                return false;
+            }
+            else {
+                username = authSplit[0];
+                token = authSplit[1];
+                return true;
+            }
+        }
        }
 
-       /**
+    /**
         * Redirect the user to the login page for authentication.
         */
        protected void authenticateUser() {
                Configuration conf = (Configuration) GWT.create(Configuration.class);
-        //IMPORTANT: Temporary circumvention of the Shiboleth login process for development and testing
-        //Some time in the future the comment line will be restored
-               //Window.Location.assign(GWT.getModuleBaseURL() + conf.loginUrl() + "?next=" + GWT.getModuleBaseURL());
-        Cookies.setCookie(conf.authCookie(), "chstath@ebs.gr" + conf.cookieSeparator() + "triapoulakiakathontan");
-        Window.Location.assign(GWT.getModuleBaseURL());
-       }
+
+//        Window.Location.assign(GWT.getModuleBaseURL() + conf.loginUrl() + "?next=" + Window.Location.getHref());
+        Cookies.setCookie(conf.authCookie(), "test" + conf.cookieSeparator() + "0000");
+        Window.Location.assign(GWT.getModuleBaseURL() + "GSS.html");
+       }
+
+    private void fetchAccount() {
+        String path = getApiPath() + username + "?format=json";
+
+        GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, path) {
+            @Override
+            public void onSuccess(AccountResource result) {
+                account = result;
+                statusPanel.displayStats(account);
+                folderTreeViewModel.initialize(account);
+                inner.selectTab(0);
+            }
+
+            @Override
+            public void onError(Throwable t) {
+                GWT.log("Error getting account", t);
+                if (t instanceof RestException)
+                    GSS.get().displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
+                else
+                    GSS.get().displayError("System error fetching user data: " + t.getMessage());
+            }
+        };
+        getAccount.setHeader("X-Auth-Token", token);
+        Scheduler.get().scheduleDeferred(getAccount);
+    }
 
        /**
         * Clear the cookie and redirect the user to the logout page.
@@ -469,9 +478,6 @@ public class GSS implements EntryPoint, ResizeHandler {
                        newHeight = 1;
                splitPanel.setHeight("" + newHeight);
                inner.setHeight("" + newHeight);
-               /*if(isFileListShowing()){
-                       getFileList().setHeight("" + (newHeight-50));
-               }*/
        }
 
        @Override
@@ -495,21 +501,6 @@ public class GSS implements EntryPoint, ResizeHandler {
        }
 
        /**
-        * Make the user list visible.
-        */
-       public void showUserList() {
-               inner.selectTab(1);
-       }
-
-       /**
-        * Make the file list visible.
-        */
-       public void showFileList() {
-               fileList.updateFileCache(true /*clear selection*/);
-               inner.selectTab(0);
-       }
-
-       /**
         * Make the file list visible.
         *
         * @param update
@@ -522,9 +513,9 @@ public class GSS implements EntryPoint, ResizeHandler {
                        RestResource currentFolder = getTreeView().getSelection();
                        if(currentFolder!=null){
                                showFileList(currentFolder);
-                       }
                }
-               
+               }
+
        }
        
        public void showFileList(RestResource r) {
@@ -538,39 +529,12 @@ public class GSS implements EntryPoint, ResizeHandler {
                        if (currentFolder instanceof RestResourceWrapper) {
                                RestResourceWrapper folder = (RestResourceWrapper) currentFolder;
                                files = folder.getResource().getFiles();
-                       } else if (currentFolder instanceof TrashResource) {
-                               TrashResource folder = (TrashResource) currentFolder;
-                               files = folder.getFiles();
-                       }
-                       else if (currentFolder instanceof SharedResource) {
-                               SharedResource folder = (SharedResource) currentFolder;
-                               files = folder.getFiles();
-                       }
-                       else if (currentFolder instanceof OtherUserResource) {
-                               OtherUserResource folder = (OtherUserResource) currentFolder;
-                               files = folder.getFiles();
                        }
-                       if (files != null)
-                               getFileList().setFiles(files);
-                       else
-                               getFileList().setFiles(new ArrayList<FileResource>());
                }
-               fileList.updateFileCache(clearSelection /*clear selection*/);
                inner.selectTab(0);
        }
 
        /**
-        * Make the search results visible.
-        *
-        * @param query the search query string
-        */
-       public void showSearchResults(String query) {
-               searchResults.updateFileCache(query);
-               searchResults.updateCurrentlyShowingStats();
-               inner.selectTab(2);
-       }
-
-       /**
         * Display the 'loading' indicator.
         */
        public void showLoadingIndicator(String message, String path) {
@@ -646,15 +610,6 @@ public class GSS implements EntryPoint, ResizeHandler {
        }*/
 
        /**
-        * Retrieve the search.
-        *
-        * @return the search
-        */
-       Search getSearch() {
-               return search;
-       }
-
-       /**
         * Retrieve the currentSelection.
         *
         * @return the currentSelection
@@ -673,15 +628,6 @@ public class GSS implements EntryPoint, ResizeHandler {
        }
 
        /**
-        * Retrieve the groups.
-        *
-        * @return the groups
-        */
-       public Groups getGroups() {
-               return groups;
-       }
-
-       /**
         * Retrieve the fileList.
         *
         * @return the fileList
@@ -690,10 +636,6 @@ public class GSS implements EntryPoint, ResizeHandler {
                return fileList;
        }
 
-       public SearchResults getSearchResults() {
-               return searchResults;
-       }
-
        /**
         * Retrieve the topPanel.
         *
@@ -735,10 +677,6 @@ public class GSS implements EntryPoint, ResizeHandler {
                return webDAVPassword;
        }
 
-       public void removeGlassPanel() {
-               glassPanel.removeFromParent();
-       }
-
        /**
         * Retrieve the currentUserResource.
         *
@@ -771,16 +709,7 @@ public class GSS implements EntryPoint, ResizeHandler {
         */
        public String getApiPath() {
                Configuration conf = (Configuration) GWT.create(Configuration.class);
-               return GWT.getModuleBaseURL() + conf.apiPath();
-       }
-
-       public void refreshWebDAVPassword() {
-               Configuration conf = (Configuration) GWT.create(Configuration.class);
-               String domain = Window.Location.getHostName();
-               String path = Window.Location.getPath();
-               String cookie = conf.webdavCookie();
-               webDAVPassword = Cookies.getCookie(cookie);
-               Cookies.setCookie(cookie, "", null, domain, path, false);
+               return conf.apiPath();
        }
 
        /**
@@ -877,6 +806,112 @@ public class GSS implements EntryPoint, ResizeHandler {
                }
                
        }
-       
-       
+
+    public void deleteFolder(final Folder folder) {
+        String path = getApiPath() + getUsername() + "/" + folder.getContainer() + "?format=json&delimiter=/&prefix=" + folder.getPrefix();
+        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
+        builder.setHeader("If-Modified-Since", "0");
+        builder.setHeader("X-Auth-Token", getToken());
+        try {
+            builder.sendRequest("", new RequestCallback() {
+                @Override
+                public void onResponseReceived(Request request, Response response) {
+                    if (response.getStatusCode() == Response.SC_OK) {
+                        JSONValue json = JSONParser.parseStrict(response.getText());
+                        JSONArray array = json.isArray();
+                        int i = 0;
+                        if (array != null) {
+                            deleteObject(folder, i, array);
+                        }
+                    }
+                }
+
+                @Override
+                public void onError(Request request, Throwable exception) {
+                    GSS.get().displayError("System error unable to delete folder: " + exception.getMessage());
+                }
+            });
+        }
+        catch (RequestException e) {
+        }
+    }
+
+    public 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) {
+                    @Override
+                    public void onSuccess(Resource result) {
+                        deleteObject(folder, i + 1, array);
+                    }
+
+                    @Override
+                    public void onError(Throwable t) {
+                        GWT.log("", t);
+                        GSS.get().displayError("System error unable to delete folder: " + t.getMessage());
+                    }
+                };
+                delete.setHeader("X-Auth-Token", getToken());
+                Scheduler.get().scheduleDeferred(delete);
+            }
+            else {
+                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;
+                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
+                builder.setHeader("If-Modified-Since", "0");
+                builder.setHeader("X-Auth-Token", getToken());
+                try {
+                    builder.sendRequest("", new RequestCallback() {
+                        @Override
+                        public void onResponseReceived(Request request, Response response) {
+                            if (response.getStatusCode() == Response.SC_OK) {
+                                JSONValue json = JSONParser.parseStrict(response.getText());
+                                JSONArray array2 = json.isArray();
+                                if (array2 != null) {
+                                    int l = array.size();
+                                    for (int j=0; j<array2.size(); j++) {
+                                        array.set(l++, array2.get(j));
+                                    }
+                                }
+                                deleteObject(folder, i + 1, array);
+                            }
+                        }
+
+                        @Override
+                        public void onError(Request request, Throwable exception) {
+                            GSS.get().displayError("System error unable to delete folder: " + exception.getMessage());
+                        }
+                    });
+                }
+                catch (RequestException e) {
+                }
+            }
+        }
+        else {
+            String prefix = folder.getPrefix();
+            String path = getApiPath() + getUsername() + "/" + folder.getContainer() + (prefix.length() == 0 ? "" : "/" + prefix);
+            DeleteRequest deleteFolder = new DeleteRequest(path) {
+                @Override
+                public void onSuccess(Resource result) {
+                    updateFolder(folder.getParent());
+                }
+
+                @Override
+                public void onError(Throwable t) {
+                    GWT.log("", t);
+                    if (t instanceof RestException) {
+                        displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
+                    }
+                    else
+                        GSS.get().displayError("System error unable to delete folder: " + t.getMessage());
+                }
+            };
+            deleteFolder.setHeader("X-Auth-Token", getToken());
+            Scheduler.get().scheduleDeferred(deleteFolder);
+        }
+    }
 }