Fixed refresh button to update stats
[pithos-web-client] / src / gr / grnet / pithos / web / client / Pithos.java
index ced54ac..f3b3681 100644 (file)
@@ -44,7 +44,6 @@ 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.grouptree.User;
 import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeView;
 import gr.grnet.pithos.web.client.mysharedtree.MysharedTreeViewModel;
 import gr.grnet.pithos.web.client.othersharedtree.OtherSharedTreeView;
@@ -59,6 +58,7 @@ import gr.grnet.pithos.web.client.tagtree.TagTreeView;
 import gr.grnet.pithos.web.client.tagtree.TagTreeViewModel;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -77,12 +77,15 @@ 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.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;
@@ -90,13 +93,13 @@ 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.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.Image;
-import com.google.gwt.user.client.ui.PushButton;
 import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.view.client.SelectionChangeEvent;
@@ -116,7 +119,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
         * 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;
@@ -146,14 +149,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
        otherSharedTreeView.updateFolder(f, showfiles);
     }
 
-    public void updateTag(Tag t) {
-        tagTreeView.updateTag(t);
-    }
-
-    public void updateTags() {
-        tagTreeViewModel.initialize(getAllTags());
-    }
-
     public List<Tag> getAllTags() {
         List<Tag> tagList = new ArrayList<Tag>();
         for (Folder f : account.getContainers()) {
@@ -172,16 +167,14 @@ public class Pithos implements EntryPoint, ResizeHandler {
         * An aggregate image bundle that pulls together all the images for this
         * application into a single bundle.
         */
-       public interface Images extends TopPanel.Images, FileList.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();
+               @Source("gr/grnet/pithos/resources/advancedsettings.png")
+               @ImageOptions(width=32, height=32)
+               ImageResource tools();
        }
 
        /**
@@ -226,12 +219,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
         */
        private Object currentSelection;
 
-
-       /**
-        * The WebDAV password of the current user
-        */
-       private String webDAVPassword;
-
        public HashMap<String, String> userFullNameMap = new HashMap<String, String>();
 
     private String username = null;
@@ -241,42 +228,45 @@ public class Pithos implements EntryPoint, ResizeHandler {
      */
     private String token;
 
+    VerticalPanel trees;
+    
     SingleSelectionModel<Folder> folderTreeSelectionModel;
     FolderTreeViewModel folderTreeViewModel;
     FolderTreeView folderTreeView;
 
     SingleSelectionModel<Folder> mysharedTreeSelectionModel;
-    private MysharedTreeViewModel mysharedTreeViewModel;
-    MysharedTreeView mysharedTreeView;
+    MysharedTreeViewModel mysharedTreeViewModel;
+    MysharedTreeView mysharedTreeView = null;;
 
     protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel;
-    private OtherSharedTreeViewModel otherSharedTreeViewModel;
-    OtherSharedTreeView otherSharedTreeView;
+    OtherSharedTreeViewModel otherSharedTreeViewModel;
+    OtherSharedTreeView otherSharedTreeView = null;
 
-    protected SingleSelectionModel<Tag> tagTreeSelectionModel;
-    private TagTreeViewModel tagTreeViewModel;
-    private TagTreeView tagTreeView;
-
-    private GroupTreeViewModel groupTreeViewModel;
+    GroupTreeViewModel groupTreeViewModel;
     private GroupTreeView groupTreeView;
 
-    private TreeView selectedTree;
+    TreeView selectedTree;
     protected AccountResource account;
     
-    private Folder trash;
+    Folder trash;
+    
+    List<Composite> treeViews = new ArrayList<Composite>();
 
-    @SuppressWarnings("rawtypes")
-       private List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
+    @SuppressWarnings("rawtypes") List<SingleSelectionModel> selectionModels = new ArrayList<SingleSelectionModel>();
     
     Button upload;
     
-    private HTML totalFiles;
-    
     private HTML usedBytes;
     
     private HTML totalBytes;
     
     private HTML usedPercent;
+    
+    private HTML numOfFiles;
+    
+    private Image refreshButton;
+
+    private Image toolsButton;
 
        @Override
        public void onModuleLoad() {
@@ -285,35 +275,107 @@ public class Pithos implements EntryPoint, ResizeHandler {
        }
 
     private void initialize() {
-        VerticalPanel outer = new VerticalPanel();
+       boolean bareContent = Window.Location.getParameter("noframe") != null;
+       String contentWidth = bareContent ? "100%" : "75%";
+
+       VerticalPanel outer = new VerticalPanel();
         outer.setWidth("100%");
+       if (!bareContent) {
+               outer.addStyleName("pithos-outer");
+       }
 
-        topPanel = new TopPanel(this, Pithos.images);
-        topPanel.setWidth("100%");
-        outer.add(topPanel);
+        if (!bareContent) {
+               topPanel = new TopPanel(this, Pithos.images);
+               topPanel.setWidth("100%");
+               outer.add(topPanel);
+               outer.setCellHorizontalAlignment(topPanel, HasHorizontalAlignment.ALIGN_CENTER);
+        }
+        
+        HorizontalPanel header = new HorizontalPanel();
+        header.addStyleName("pithos-header");
+        header.setWidth(contentWidth);
+        if (bareContent)
+               header.addStyleName("pithos-header-noframe");
+        upload = new Button("Upload File", new ClickHandler() {
+            @Override
+            public void onClick(@SuppressWarnings("unused") ClickEvent event) {
+                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);
+//        header.setCellWidth(upload, "146px");
 
-        messagePanel.setWidth("100%");
         messagePanel.setVisible(false);
-        outer.add(messagePanel);
-        outer.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
-
-
-        // Inner contains the various lists.
+        header.add(messagePanel);
+        header.setCellHorizontalAlignment(messagePanel, HasHorizontalAlignment.ALIGN_CENTER);
+        header.setCellVerticalAlignment(messagePanel, HasVerticalAlignment.ALIGN_MIDDLE);
+        
+        refreshButton = new Image(images.refresh());
+        refreshButton.addStyleName("pithos-toolsButton");
+        refreshButton.setWidth("32px");
+        refreshButton.setHeight("32px");
+        refreshButton.addClickHandler(new ClickHandler() {
+                       
+                       @Override
+                       public void onClick(@SuppressWarnings("unused") ClickEvent event) {
+                       boolean isFolderTreeSelected = selectedTree.equals(getFolderTreeView());
+                       boolean otherSharedTreeSelected = selectedTree.equals(getOtherSharedTreeView());
+                       Folder folder = getSelectedTree().getSelection();
+                       
+                       if (folder != null && (isFolderTreeSelected || otherSharedTreeSelected))
+                               updateFolder(folder, true, new Command() {
+                                       
+                                       @Override
+                                       public void execute() {
+                                               updateStatistics();
+                                       }
+                               });
+                       }
+               });
+        header.add(refreshButton);
+        header.setCellHorizontalAlignment(refreshButton, HasHorizontalAlignment.ALIGN_CENTER);
+        header.setCellVerticalAlignment(refreshButton, HasVerticalAlignment.ALIGN_MIDDLE);
+        header.setCellWidth(refreshButton, "40px");
+
+        toolsButton = new Image(images.tools());
+        toolsButton.addStyleName("pithos-toolsButton");
+        toolsButton.addClickHandler(new ClickHandler() {
+                       
+                       @Override
+                       public void onClick(ClickEvent event) {
+                ToolsMenu menu = new ToolsMenu(Pithos.this, images, getSelectedTree(), getSelectedTree().getSelection(), getFileList().getSelectedFiles());
+                if (!menu.isEmpty()) {
+                           menu.setPopupPosition(event.getClientX(), event.getClientY());
+                           menu.show();
+                }
+                       }
+               });
+        header.add(toolsButton);
+        header.setCellHorizontalAlignment(toolsButton, HasHorizontalAlignment.ALIGN_CENTER);
+        header.setCellVerticalAlignment(toolsButton, HasVerticalAlignment.ALIGN_MIDDLE);
+        header.setCellWidth(toolsButton, "40px");
+       
+        HorizontalPanel folderStatistics = new HorizontalPanel();
+        folderStatistics.addStyleName("pithos-folderStatistics");
+        numOfFiles = new HTML();
+        folderStatistics.add(numOfFiles);
+        folderStatistics.setCellVerticalAlignment(numOfFiles, HasVerticalAlignment.ALIGN_MIDDLE);
+        HTML numOfFilesLabel = new HTML("&nbsp;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%");
 
-        HorizontalPanel rightside = new HorizontalPanel();
-        rightside.addStyleName("pithos-rightSide");
-        rightside.setSpacing(5);
-
-        HTML folderStatistics = new HTML("5 Files (size: 1.1GB)");
-        folderStatistics.addStyleName("pithos-folderStatistics");
-        rightside.add(folderStatistics);
-        inner.add(rightside);
-        inner.setCellHorizontalAlignment(rightside, HasHorizontalAlignment.ALIGN_RIGHT);
-        inner.setCellVerticalAlignment(rightside, HasVerticalAlignment.ALIGN_MIDDLE);
-        inner.setCellHeight(rightside, "60px");
-
         folderTreeSelectionModel = new SingleSelectionModel<Folder>();
         folderTreeSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
             @Override
@@ -322,7 +384,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                     deselectOthers(folderTreeView, folderTreeSelectionModel);
                     applyPermissions(folderTreeSelectionModel.getSelectedObject());
                     Folder f = folderTreeSelectionModel.getSelectedObject();
-                    updateFolder(f, true, null);
+                    showFiles(f);
                 }
             }
         });
@@ -330,61 +392,26 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
         folderTreeViewModel = new FolderTreeViewModel(this, folderTreeSelectionModel);
         folderTreeView = new FolderTreeView(folderTreeViewModel);
-
+        treeViews.add(folderTreeView);
+        
         fileList = new FileList(this, images, folderTreeView);
         inner.add(fileList);
 
-        mysharedTreeSelectionModel = new SingleSelectionModel<Folder>();
-        mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
-            @Override
-            public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
-                if (mysharedTreeSelectionModel.getSelectedObject() != null) {
-                    deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
-                    upload.setEnabled(false);
-                    updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
-                }
-            }
-        });
-        selectionModels.add(mysharedTreeSelectionModel);
-        mysharedTreeViewModel = new MysharedTreeViewModel(this, mysharedTreeSelectionModel);
-        mysharedTreeView = new MysharedTreeView(mysharedTreeViewModel);
-
-        otherSharedTreeSelectionModel = new SingleSelectionModel<Folder>();
-        otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
-            @Override
-            public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
-                if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
-                    deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
-                    applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
-                    updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
-                }
-            }
-        });
-        selectionModels.add(otherSharedTreeSelectionModel);
-        otherSharedTreeViewModel = new OtherSharedTreeViewModel(this, otherSharedTreeSelectionModel);
-        otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
-
         groupTreeViewModel = new GroupTreeViewModel(this);
         groupTreeView = new GroupTreeView(groupTreeViewModel);
+        treeViews.add(groupTreeView);
+        
+        trees = new VerticalPanel();
+        trees.setWidth("100%");
 
-        VerticalPanel trees = new VerticalPanel();
-
-        upload = new Button("Upload File", new ClickHandler() {
-            @Override
-            public void onClick(@SuppressWarnings("unused") ClickEvent event) {
-                new UploadFileCommand(Pithos.this, null, getSelection()).execute();
-            }
-        });
-        upload.addStyleName("pithos-uploadButton");
-        trees.add(upload);
         
         HorizontalPanel treeHeader = new HorizontalPanel();
         treeHeader.addStyleName("pithos-treeHeader");
+        treeHeader.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
+        treeHeader.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
         HorizontalPanel statistics = new HorizontalPanel();
-        statistics.add(new HTML("Total Objects:&nbsp;"));
-        totalFiles = new HTML();
-        statistics.add(totalFiles);
-        statistics.add(new HTML("&nbsp;|&nbsp;Used:&nbsp;"));
+        statistics.addStyleName("pithos-statistics");
+        statistics.add(new HTML("Used:&nbsp;"));
         usedBytes = new HTML();
         statistics.add(usedBytes);
         statistics.add(new HTML("&nbsp;of&nbsp;"));
@@ -393,26 +420,31 @@ public class Pithos implements EntryPoint, ResizeHandler {
         statistics.add(new HTML("&nbsp;("));
         usedPercent = new HTML();
         statistics.add(usedPercent);
-        statistics.add(new HTML("%)"));
+        statistics.add(new HTML(")"));
         treeHeader.add(statistics);
+        treeHeader.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_LEFT);
         trees.add(treeHeader);
 
         trees.add(folderTreeView);
-        trees.add(mysharedTreeView);
-        trees.add(otherSharedTreeView);
-//        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");
+        splitPanel.setWidth(contentWidth);
         outer.add(splitPanel);
+        outer.setCellHorizontalAlignment(splitPanel, HasHorizontalAlignment.ALIGN_CENTER);
 
-        statusPanel = new StatusPanel();
-        outer.add(statusPanel);
-
+        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);
@@ -450,7 +482,13 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                                        trash = f;
                                                        break;
                                                }
-                                   folderTreeViewModel.initialize(account);
+                                   folderTreeViewModel.initialize(account, new Command() {
+                                                               
+                                                               @Override
+                                                               public void execute() {
+                                                   createMySharedTree();
+                                                               }
+                                                       });
                                    groupTreeViewModel.initialize();
                                    showStatistics();
                                }
@@ -458,6 +496,15 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                });
             }
         });
+        
+//        Scheduler.get().scheduleDeferred(new Command() {
+//                     
+//                     @Override
+//                     public void execute() {
+//                             displayError("lalala");
+//                             
+//                     }
+//             });
     }
 
     public void applyPermissions(Folder f) {
@@ -480,6 +527,13 @@ public class Pithos implements EntryPoint, ResizeHandler {
        @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);
@@ -514,6 +568,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                     else
                         displayError("System error fetching file: " + t.getMessage());
                 }
+
+                               @Override
+                               protected void onUnauthorized(Response response) {
+                                       sessionExpired();
+                               }
             };
             getFile.setHeader("X-Auth-Token", "0000");
             Scheduler.get().scheduleDeferred(getFile);
@@ -536,6 +595,10 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 authenticateUser();
                 return false;
             }
+            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();
@@ -545,7 +608,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
                        token = authSplit[1];
                        return true;
         }
-               Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token);
+        
+               Cookies.setCookie(conf.authCookie(), username + conf.cookieSeparator() + token, null, "", "/", false);
                return true;
     }
 
@@ -576,6 +640,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 else
                     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);
@@ -585,7 +654,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
        HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) {
 
                        @Override
-                       public void onSuccess(AccountResource _result) {
+                       public void onSuccess(@SuppressWarnings("unused") AccountResource _result) {
                                showStatistics();
                        }
 
@@ -597,24 +666,29 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 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() {
-       totalFiles.setHTML(String.valueOf(account.getNumberOfObjects()));
        usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
        totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
-       usedPercent.setHTML(String.valueOf(account.getUsedPercentage()));
+       NumberFormat nf = NumberFormat.getPercentFormat();
+       usedPercent.setHTML(nf.format(account.getUsedPercentage()));
        }
 
-       protected void createHomeContainer(final AccountResource account, final Command callback) {
+       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(@SuppressWarnings("unused") Resource result) {
-               if (!account.hasTrashContainer())
+               if (!_account.hasTrashContainer())
                        createTrashContainer(callback);
                else
                        fetchAccount(callback);
@@ -628,6 +702,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 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);
@@ -649,6 +728,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 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);
@@ -672,7 +756,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
        protected void onWindowResized(int height) {
                // Adjust the split panel to take up the available room in the window.
-               int newHeight = height - splitPanel.getAbsoluteTop() - 60;
+               int newHeight = height - splitPanel.getAbsoluteTop();
                if (newHeight < 1)
                        newHeight = 1;
                splitPanel.setHeight("" + newHeight);
@@ -747,10 +831,6 @@ public class Pithos implements EntryPoint, ResizeHandler {
                return token;
        }
 
-       public String getWebDAVPassword() {
-               return webDAVPassword;
-       }
-
        public static native void preventIESelection() /*-{
                $doc.body.onselectstart = function () { return false; };
        }-*/;
@@ -783,9 +863,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
        }
 
     public void deleteFolder(final Folder folder) {
-        String path = getApiPath() + folder.getOwner() + "/" + 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() {
@@ -828,6 +907,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                         GWT.log("", 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);
@@ -835,9 +919,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
             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() {
@@ -892,6 +975,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                     else
                         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);
@@ -921,9 +1009,17 @@ public class Pithos implements EntryPoint, ResizeHandler {
                     else
                         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) {
@@ -952,16 +1048,16 @@ public class Pithos implements EntryPoint, ResizeHandler {
         PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) {
             @Override
             public void onSuccess(@SuppressWarnings("unused") Resource result) {
-               GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + f.getPrefix(), f) {
+               GetRequest<Folder> getFolder = new GetRequest<Folder>(Folder.class, getApiPath(), f.getOwner(), "/" + f.getContainer() + "?format=json&delimiter=/&prefix=" + URL.encodeQueryString(f.getPrefix()), f) {
 
                                        @Override
-                                       public void onSuccess(final Folder f) {
-                               Iterator<File> iter = f.getFiles().iterator();
-                               copyFiles(iter, targetUsername, targetUri + "/" + f.getName(), new Command() {
+                                       public void onSuccess(final Folder _f) {
+                               Iterator<File> iter = _f.getFiles().iterator();
+                               copyFiles(iter, targetUsername, targetUri + "/" + _f.getName(), new Command() {
                                    @Override
                                    public void execute() {
-                                       Iterator<Folder> iterf = f.getSubfolders().iterator();
-                                       copySubfolders(iterf, targetUsername, targetUri + "/" + f.getName(), callback);
+                                       Iterator<Folder> iterf = _f.getSubfolders().iterator();
+                                       copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback);
                                    }
                                });
                                        }
@@ -975,6 +1071,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                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);
@@ -989,6 +1090,11 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 else
                     displayError("System error creating folder: " + t.getMessage());
             }
+
+                       @Override
+                       protected void onUnauthorized(Response response) {
+                               sessionExpired();
+                       }
         };
         createFolder.setHeader("X-Auth-Token", getToken());
         createFolder.setHeader("Accept", "*/*");
@@ -1031,4 +1137,82 @@ public class Pithos implements EntryPoint, ResizeHandler {
        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<Folder>();
+               mysharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
+                   @Override
+                   public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
+                       if (mysharedTreeSelectionModel.getSelectedObject() != null) {
+                           deselectOthers(mysharedTreeView, mysharedTreeSelectionModel);
+                           upload.setEnabled(false);
+                           updateSharedFolder(mysharedTreeSelectionModel.getSelectedObject(), true);
+                       }
+                   }
+               });
+               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<Folder>();
+               otherSharedTreeSelectionModel.addSelectionChangeHandler(new Handler() {
+                   @Override
+                   public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
+                       if (otherSharedTreeSelectionModel.getSelectedObject() != null) {
+                           deselectOthers(otherSharedTreeView, otherSharedTreeSelectionModel);
+                           otherSharedTreeView.addStyleName("cellTreeWidget-selectedTree");
+                           applyPermissions(otherSharedTreeSelectionModel.getSelectedObject());
+                           updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
+                       }
+                   }
+               });
+               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() {
+        Configuration conf = (Configuration) GWT.create(Configuration.class);
+               Cookies.removeCookie(conf.authCookie(), "/");
+               Cookies.removeCookie(conf.authTokenCookie(), "/");
+               for (String s: Cookies.getCookieNames())
+                       if (s.startsWith(conf.shibSessionCookiePrefix()))
+                               Cookies.removeCookie(s, "/");
+               Window.Location.assign(Window.Location.getPath());
+       }
 }