Added logoff option to username menu
[pithos] / web_client / src / gr / grnet / pithos / web / client / Pithos.java
index f9421a5..24a39b6 100644 (file)
@@ -41,12 +41,16 @@ 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.tagtree.Tag;
@@ -72,6 +76,7 @@ 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.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
@@ -90,8 +95,6 @@ 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;
@@ -104,12 +107,14 @@ import com.google.gwt.view.client.SingleSelectionModel;
 public class Pithos implements EntryPoint, ResizeHandler {
 
        public static final String HOME_CONTAINER = "pithos";
+
+       public static final String TRASH_CONTAINER = "trash";
        
        /**
         * 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;
@@ -123,8 +128,12 @@ public class Pithos implements EntryPoint, ResizeHandler {
         return account;
     }
 
-    public void updateFolder(Folder f, boolean showfiles) {
-        folderTreeView.updateFolder(f, showfiles);
+    public void updateFolder(Folder f, boolean showfiles, Command callback) {
+        folderTreeView.updateFolder(f, showfiles, callback);
+    }
+
+    public void updateGroupNode(Group group) {
+        groupTreeView.updateGroupNode(group);
     }
 
     public void updateSharedFolder(Folder f, boolean showfiles) {
@@ -135,14 +144,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()) {
@@ -161,16 +162,13 @@ 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")
+               ImageResource tools();
        }
 
        /**
@@ -215,12 +213,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;
@@ -230,26 +222,43 @@ public class Pithos implements EntryPoint, ResizeHandler {
      */
     private String token;
 
-    protected SingleSelectionModel<Folder> folderTreeSelectionModel;
-    protected FolderTreeViewModel folderTreeViewModel;
-    protected FolderTreeView folderTreeView;
+    VerticalPanel trees;
+    
+    SingleSelectionModel<Folder> folderTreeSelectionModel;
+    FolderTreeViewModel folderTreeViewModel;
+    FolderTreeView folderTreeView;
 
-    protected SingleSelectionModel<Folder> mysharedTreeSelectionModel;
-    private MysharedTreeViewModel mysharedTreeViewModel;
-    private MysharedTreeView mysharedTreeView;
+    SingleSelectionModel<Folder> mysharedTreeSelectionModel;
+    MysharedTreeViewModel mysharedTreeViewModel;
+    MysharedTreeView mysharedTreeView = null;;
 
     protected SingleSelectionModel<Folder> otherSharedTreeSelectionModel;
-    private OtherSharedTreeViewModel otherSharedTreeViewModel;
-    private OtherSharedTreeView otherSharedTreeView;
+    OtherSharedTreeViewModel otherSharedTreeViewModel;
+    OtherSharedTreeView otherSharedTreeView = null;
 
-    protected SingleSelectionModel<Tag> tagTreeSelectionModel;
-    private TagTreeViewModel tagTreeViewModel;
-    private TagTreeView tagTreeView;
+    GroupTreeViewModel groupTreeViewModel;
+    private GroupTreeView groupTreeView;
 
+    private TreeView selectedTree;
     protected AccountResource account;
+    
+    Folder trash;
 
-    @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 Button toolsButton;
 
        @Override
        public void onModuleLoad() {
@@ -279,20 +288,31 @@ public class Pithos implements EntryPoint, ResizeHandler {
         rightside.addStyleName("pithos-rightSide");
         rightside.setSpacing(5);
 
-        PushButton parentButton = new PushButton(new Image(images.asc()), new ClickHandler() {
-            @Override
-            public void onClick(@SuppressWarnings("unused") ClickEvent event) {
-
-            }
-        });
-        parentButton.addStyleName("pithos-parentButton");
-        rightside.add(parentButton);
-
-        HTML folderStatistics = new HTML("5 Files (size: 1.1GB)");
+        toolsButton = new Button(AbstractImagePrototype.create(images.tools()).getHTML());
+        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();
+                }
+                       }
+               });
+        rightside.add(toolsButton);
+        rightside.setCellHorizontalAlignment(toolsButton, HasHorizontalAlignment.ALIGN_LEFT);
+        
+        HorizontalPanel folderStatistics = new HorizontalPanel();
         folderStatistics.addStyleName("pithos-folderStatistics");
+        numOfFiles = new HTML();
+        folderStatistics.add(numOfFiles);
+        HTML numOfFilesLabel = new HTML("&nbsp;Files");
+        folderStatistics.add(numOfFilesLabel);
         rightside.add(folderStatistics);
+        rightside.setCellHorizontalAlignment(folderStatistics, HasHorizontalAlignment.ALIGN_RIGHT);
+
         inner.add(rightside);
-        inner.setCellHorizontalAlignment(rightside, HasHorizontalAlignment.ALIGN_RIGHT);
         inner.setCellVerticalAlignment(rightside, HasVerticalAlignment.ALIGN_MIDDLE);
         inner.setCellHeight(rightside, "60px");
 
@@ -301,9 +321,10 @@ public class Pithos implements EntryPoint, ResizeHandler {
             @Override
             public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
                 if (folderTreeSelectionModel.getSelectedObject() != null) {
-                    deselectOthers(folderTreeSelectionModel);
+                    deselectOthers(folderTreeView, folderTreeSelectionModel);
+                    applyPermissions(folderTreeSelectionModel.getSelectedObject());
                     Folder f = folderTreeSelectionModel.getSelectedObject();
-                    updateFolder(f, true);
+                    updateFolder(f, true, null);
                 }
             }
         });
@@ -315,55 +336,15 @@ public class Pithos implements EntryPoint, ResizeHandler {
         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(mysharedTreeSelectionModel);
-                    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(otherSharedTreeSelectionModel);
-                    updateOtherSharedFolder(otherSharedTreeSelectionModel.getSelectedObject(), true);
-                }
-            }
-        });
-        selectionModels.add(otherSharedTreeSelectionModel);
-        otherSharedTreeViewModel = new OtherSharedTreeViewModel(this, otherSharedTreeSelectionModel);
-        otherSharedTreeView = new OtherSharedTreeView(otherSharedTreeViewModel);
+        groupTreeViewModel = new GroupTreeViewModel(this);
+        groupTreeView = new GroupTreeView(groupTreeViewModel);
 
-        tagTreeSelectionModel = new SingleSelectionModel<Tag>();
-        tagTreeSelectionModel.addSelectionChangeHandler(new Handler() {
-            @Override
-            public void onSelectionChange(@SuppressWarnings("unused") SelectionChangeEvent event) {
-                if (tagTreeSelectionModel.getSelectedObject() != null) {
-                    deselectOthers(tagTreeSelectionModel);
-                    Tag t = tagTreeSelectionModel.getSelectedObject();
-                    updateTag(t);
-                }
-            }
-        });
-        selectionModels.add(tagTreeSelectionModel);
-        tagTreeViewModel = new TagTreeViewModel(this, tagTreeSelectionModel);
-        tagTreeView = new TagTreeView(tagTreeViewModel);
-
-        VerticalPanel trees = new VerticalPanel();
+        trees = new VerticalPanel();
 
-        Button upload = new Button("Upload File", new ClickHandler() {
+        upload = new Button("Upload File", new ClickHandler() {
             @Override
             public void onClick(@SuppressWarnings("unused") ClickEvent event) {
-                new UploadFileCommand(Pithos.this, null, folderTreeView.getSelection()).execute();
+                new UploadFileCommand(Pithos.this, null, getSelection()).execute();
             }
         });
         upload.addStyleName("pithos-uploadButton");
@@ -371,13 +352,25 @@ public class Pithos implements EntryPoint, ResizeHandler {
         
         HorizontalPanel treeHeader = new HorizontalPanel();
         treeHeader.addStyleName("pithos-treeHeader");
-        treeHeader.add(new HTML("Total Files: 6 | Used: 2.1 of 50 GB (4.2%)"));
+        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;"));
+        usedBytes = new HTML();
+        statistics.add(usedBytes);
+        statistics.add(new HTML("&nbsp;of&nbsp;"));
+        totalBytes = new HTML();
+        statistics.add(totalBytes);
+        statistics.add(new HTML("&nbsp;("));
+        usedPercent = new HTML();
+        statistics.add(usedPercent);
+        statistics.add(new HTML("%)"));
+        treeHeader.add(statistics);
         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);
@@ -412,13 +405,51 @@ 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);
+                                   groupTreeViewModel.initialize();
+                                   createMySharedTree();
+                                   showStatistics();
+                               }
+                                       }
+                               });
             }
         });
     }
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-       public void deselectOthers(SingleSelectionModel model) {
+    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 (SingleSelectionModel s : selectionModels)
             if (!s.equals(model))
                 s.setSelected(s.getSelectedObject(), false);
@@ -453,6 +484,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);
@@ -493,21 +529,18 @@ public class Pithos implements EntryPoint, ResizeHandler {
         */
        protected void authenticateUser() {
                Configuration conf = (Configuration) GWT.create(Configuration.class);
-        Window.Location.assign(Window.Location.getHost() + conf.loginUrl() + "?next=" + Window.Location.getHref());
+        Window.Location.assign(conf.loginUrl() + "?next=" + Window.Location.getHref());
        }
 
-       protected void fetchAccount() {
+       protected void fetchAccount(final Command callback) {
         String path = "?format=json";
 
         GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, getApiPath(), username, path) {
             @Override
             public void onSuccess(AccountResource _result) {
                 account = _result;
-                if (account.getContainers().isEmpty())
-                    createHomeContainers();
-                else {
-                    folderTreeViewModel.initialize(account);
-                }
+                if (callback != null)
+                       callback.execute();
             }
 
             @Override
@@ -518,17 +551,84 @@ 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);
     }
 
-    protected void createHomeContainers() {
-        String path = "/pithos";
+    public void updateStatistics() {
+       HeadRequest<AccountResource> headAccount = new HeadRequest<AccountResource>(AccountResource.class, getApiPath(), username, "", account) {
+
+                       @Override
+                       public void onSuccess(@SuppressWarnings("unused") AccountResource _result) {
+                               showStatistics();
+                       }
+
+                       @Override
+                       public void onError(Throwable t) {
+                GWT.log("Error getting account", 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() {
+       totalFiles.setHTML(String.valueOf(account.getNumberOfObjects()));
+       usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
+       totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
+       usedPercent.setHTML(String.valueOf(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(@SuppressWarnings("unused") Resource result) {
+               if (!_account.hasTrashContainer())
+                       createTrashContainer(callback);
+               else
+                       fetchAccount(callback);
+            }
+
+            @Override
+            public void onError(Throwable t) {
+                GWT.log("Error creating pithos", 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);
+    }
+
+    protected void createTrashContainer(final Command callback) {
+        String path = "/" + Pithos.TRASH_CONTAINER;
         PutRequest createPithos = new PutRequest(getApiPath(), getUsername(), path) {
             @Override
             public void onSuccess(@SuppressWarnings("unused") Resource result) {
-                fetchAccount();
+                       fetchAccount(callback);
             }
 
             @Override
@@ -539,12 +639,17 @@ 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);
     }
 
-       /**
+    /**
         * Creates an HTML fragment that places an image & caption together, for use
         * in a group header.
         *
@@ -637,10 +742,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; };
        }-*/;
@@ -673,9 +774,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
        }
 
     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() {
@@ -701,13 +801,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 = "/" + folder.getContainer() + "/" + name.stringValue();
-                DeleteRequest delete = new DeleteRequest(getApiPath(), getUsername(), path) {
+                DeleteRequest delete = new DeleteRequest(getApiPath(), folder.getOwner(), path) {
                     @Override
                     public void onSuccess(@SuppressWarnings("unused") Resource result) {
                         deleteObject(folder, i + 1, array);
@@ -718,6 +818,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);
@@ -725,9 +830,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() {
@@ -761,18 +865,32 @@ public class Pithos implements EntryPoint, ResizeHandler {
             DeleteRequest deleteFolder = new DeleteRequest(getApiPath(), getUsername(), path) {
                 @Override
                 public void onSuccess(@SuppressWarnings("unused") Resource result) {
-                    updateFolder(folder.getParent(), true);
+                    updateFolder(folder.getParent(), true, new Command() {
+                                               
+                                               @Override
+                                               public void execute() {
+                                                       updateStatistics();
+                                               }
+                                       });
                 }
 
                 @Override
                 public void onError(Throwable t) {
                     GWT.log("", 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
                         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);
@@ -783,14 +901,14 @@ public class Pithos implements EntryPoint, ResizeHandler {
         return folderTreeView;
     }
 
-    public void copyFiles(final Iterator<File> iter, final String targetUri, final Command callback) {
+    public void copyFiles(final Iterator<File> iter, final String targetUsername, final String targetUri, final Command callback) {
         if (iter.hasNext()) {
             File file = iter.next();
             String path = targetUri + "/" + file.getName();
-            PutRequest copyFile = new PutRequest(getApiPath(), getUsername(), path) {
+            PutRequest copyFile = new PutRequest(getApiPath(), targetUsername, path) {
                 @Override
                 public void onSuccess(@SuppressWarnings("unused") Resource result) {
-                    copyFiles(iter, targetUri, callback);
+                    copyFiles(iter, targetUsername, targetUri, callback);
                 }
 
                 @Override
@@ -802,9 +920,16 @@ 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());
+            if (!file.getOwner().equals(targetUsername))
+               copyFile.setHeader("X-Source-Account", file.getOwner());
             Scheduler.get().scheduleDeferred(copyFile);
         }
         else  if (callback != null) {
@@ -812,45 +937,74 @@ public class Pithos implements EntryPoint, ResizeHandler {
         }
     }
 
-    public void copySubfolders(final Iterator<Folder> iter, final String targetUri, final Command callback) {
+    public void copySubfolders(final Iterator<Folder> 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) {
+    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(), getUsername(), path) {
+        PutRequest createFolder = new PutRequest(getApiPath(), targetUsername, path) {
             @Override
             public void onSuccess(@SuppressWarnings("unused") Resource result) {
-                Iterator<File> iter = f.getFiles().iterator();
-                copyFiles(iter, targetUri + "/" + f.getName(), new Command() {
-                    @Override
-                    public void execute() {
-                        Iterator<Folder> iterf = f.getSubfolders().iterator();
-                        copySubfolders(iterf, targetUri + "/" + f.getName(), new Command() {
-                            @Override
-                            public void execute() {
-                                callback.execute();
-                            }
-                        });
-                    }
-                });
+               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() {
+                                   @Override
+                                   public void execute() {
+                                       Iterator<Folder> iterf = _f.getSubfolders().iterator();
+                                       copySubfolders(iterf, targetUsername, targetUri + "/" + _f.getName(), callback);
+                                   }
+                               });
+                                       }
+
+                                       @Override
+                                       public void onError(Throwable t) {
+                               GWT.log("", 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());
+                    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", "*/*");
@@ -866,4 +1020,102 @@ public class Pithos implements EntryPoint, ResizeHandler {
        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<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, 3);
+                               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);
+                           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, 4);
+                       }
+               });
+       }
+
+       public void logoff() {
+        Configuration conf = (Configuration) GWT.create(Configuration.class);
+               Cookies.removeCookie(conf.authCookie());
+               Window.Location.assign(Window.Location.getHost());
+       }
 }