Refresh the MyShared tree when certain file properties are changed
[pithos-web-client] / src / gr / grnet / pithos / web / client / Pithos.java
index 47f1ac8..08d6261 100644 (file)
@@ -141,6 +141,10 @@ public class Pithos implements EntryPoint, ResizeHandler {
         groupTreeView.updateGroupNode(group);
     }
 
+    public void updateMySharedRoot() {
+       mysharedTreeView.updateRoot();
+    }
+    
     public void updateSharedFolder(Folder f, boolean showfiles) {
        mysharedTreeView.updateFolder(f, showfiles);
     }
@@ -177,6 +181,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
                ImageResource tools();
        }
 
+       private Throwable error;
+       
        /**
         * The Application Clipboard implementation;
         */
@@ -190,7 +196,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
        /**
         * The panel that contains the various system messages.
         */
-       private MessagePanel messagePanel = new MessagePanel(Pithos.images);
+       private MessagePanel messagePanel = new MessagePanel(this, Pithos.images);
 
        /**
         * The bottom panel that contains the status bar.
@@ -245,7 +251,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
     GroupTreeViewModel groupTreeViewModel;
     private GroupTreeView groupTreeView;
 
-    private TreeView selectedTree;
+    TreeView selectedTree;
     protected AccountResource account;
     
     Folder trash;
@@ -264,6 +270,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
     
     private HTML numOfFiles;
     
+    private Image refreshButton;
+
     private Image toolsButton;
 
        @Override
@@ -311,6 +319,33 @@ public class Pithos implements EntryPoint, ResizeHandler {
         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() {
@@ -534,6 +569,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 @Override
                 public void onError(Throwable t) {
                     GWT.log("Error getting file", t);
+                                       setError(t);
                     if (t instanceof RestException)
                         displayError("Error getting file: " + ((RestException) t).getHttpStatusText());
                     else
@@ -566,6 +602,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();
@@ -602,6 +642,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
             @Override
             public void onError(Throwable t) {
                 GWT.log("Error getting account", t);
+                               setError(t);
                 if (t instanceof RestException)
                     displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
                 else
@@ -628,6 +669,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                        @Override
                        public void onError(Throwable t) {
                 GWT.log("Error getting account", t);
+                               setError(t);
                 if (t instanceof RestException)
                     displayError("Error getting account: " + ((RestException) t).getHttpStatusText());
                 else
@@ -664,6 +706,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
             @Override
             public void onError(Throwable t) {
                 GWT.log("Error creating pithos", t);
+                               setError(t);
                 if (t instanceof RestException)
                     displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
                 else
@@ -690,6 +733,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
             @Override
             public void onError(Throwable t) {
                 GWT.log("Error creating pithos", t);
+                               setError(t);
                 if (t instanceof RestException)
                     displayError("Error creating pithos: " + ((RestException) t).getHttpStatusText());
                 else
@@ -849,6 +893,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
                 @Override
                 public void onError(@SuppressWarnings("unused") Request request, Throwable exception) {
+                       setError(exception);
                     displayError("System error unable to delete folder: " + exception.getMessage());
                 }
             });
@@ -872,6 +917,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                     @Override
                     public void onError(Throwable t) {
                         GWT.log("", t);
+                                               setError(t);
                         displayError("System error unable to delete folder: " + t.getMessage());
                     }
 
@@ -908,6 +954,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
                         @Override
                         public void onError(@SuppressWarnings("unused") Request request, Throwable exception) {
+                               setError(exception);
                             displayError("System error unable to delete folder: " + exception.getMessage());
                         }
                     });
@@ -933,6 +980,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 @Override
                 public void onError(Throwable t) {
                     GWT.log("", t);
+                                       setError(t);
                     if (t instanceof RestException) {
                        if (((RestException) t).getHttpStatusCode() != Response.SC_NOT_FOUND)
                                displayError("Unable to delete folder: "+((RestException) t).getHttpStatusText());
@@ -970,6 +1018,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                 @Override
                 public void onError(Throwable t) {
                     GWT.log("", t);
+                                       setError(t);
                     if (t instanceof RestException) {
                         displayError("Unable to copy file: " + ((RestException) t).getHttpStatusText());
                     }
@@ -983,9 +1032,10 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                }
             };
             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", file.getOwner());
+               copyFile.setHeader("X-Source-Account", URL.encodePathSegment(file.getOwner()));
+            copyFile.setHeader("Content-Type", file.getContentType());
             Scheduler.get().scheduleDeferred(copyFile);
         }
         else  if (callback != null) {
@@ -1031,6 +1081,7 @@ public class Pithos implements EntryPoint, ResizeHandler {
                                        @Override
                                        public void onError(Throwable t) {
                                GWT.log("", t);
+                                               setError(t);
                                if (t instanceof RestException) {
                                    displayError("Unable to get folder: " + ((RestException) t).getHttpStatusText());
                                }
@@ -1050,7 +1101,8 @@ public class Pithos implements EntryPoint, ResizeHandler {
             @Override
             public void onError(Throwable t) {
                 GWT.log("", t);
-                if (t instanceof RestException) {
+                               setError(t);
+               if (t instanceof RestException) {
                     displayError("Unable to create folder: " + ((RestException) t).getHttpStatusText());
                 }
                 else
@@ -1174,11 +1226,21 @@ public class Pithos implements EntryPoint, ResizeHandler {
 
        public void logoff() {
         Configuration conf = (Configuration) GWT.create(Configuration.class);
-               Cookies.removeCookie(conf.authCookie());
+               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());
        }
+
+       public String getErrorData() {
+               if (error != null)
+                       return error.toString();
+               return "";
+       }
+       
+       public void setError(Throwable t) {
+               error = t;
+       }
 }