Got file info from headers
authorChristos Stathis <chstath@ebs.gr>
Thu, 30 Jun 2011 15:57:17 +0000 (18:57 +0300)
committerChristos Stathis <chstath@ebs.gr>
Thu, 30 Jun 2011 15:57:17 +0000 (18:57 +0300)
web_client/src/gr/grnet/pithos/web/client/FileList.java
web_client/src/gr/grnet/pithos/web/client/GSS.java
web_client/src/gr/grnet/pithos/web/client/foldertree/File.java
web_client/src/gr/grnet/pithos/web/client/foldertree/Folder.java
web_client/src/gr/grnet/pithos/web/client/foldertree/Resource.java

index a2e7bae..c998957 100644 (file)
@@ -638,8 +638,6 @@ public class FileList extends Composite {
         Folder selectedItem = treeView.getSelection();
 
         provider.setList(files);
-        provider.refresh();
-        celltable.redrawHeaders();
        }
 
        /**
index c3e678d..f6fc3b1 100644 (file)
@@ -5,13 +5,8 @@ package gr.grnet.pithos.web.client;
 
 import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.core.client.Scheduler.ScheduledCommand;
-import com.google.gwt.user.client.ui.DockPanel;
-import com.google.gwt.user.client.ui.HasVerticalAlignment;
-import com.google.gwt.view.client.ListDataProvider;
 import com.google.gwt.view.client.SelectionChangeEvent;
-import com.google.gwt.view.client.SelectionChangeEvent.Handler;
 import com.google.gwt.view.client.SingleSelectionModel;
-import com.google.gwt.view.client.TreeViewModel.NodeInfo;
 import gr.grnet.pithos.web.client.clipboard.Clipboard;
 import gr.grnet.pithos.web.client.commands.GetUserCommand;
 import gr.grnet.pithos.web.client.foldertree.AccountResource;
@@ -46,10 +41,8 @@ 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;
@@ -309,9 +302,36 @@ public class GSS implements EntryPoint, ResizeHandler {
     }
 
     private void showFiles(Folder f) {
-        Set<File> files = f.getFiles();
-        fileList.setFiles(new ArrayList<File>(files));
         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));
     }
 
     /**
index cfd8049..8118cce 100644 (file)
@@ -4,8 +4,13 @@
 
 package gr.grnet.pithos.web.client.foldertree;
 
+import com.google.gwt.http.client.Response;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
 import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONParser;
+import com.google.gwt.json.client.JSONValue;
 import java.util.Date;
 
 public class File extends Resource {
@@ -31,6 +36,8 @@ public class File extends Resource {
 
     private boolean inTrash;
 
+    private String container;
+
     public String getContentType() {
         return contentType;
     }
@@ -99,8 +106,8 @@ public class File extends Resource {
         return inTrash;
     }
 
-    public void populate(JSONObject o) {
-        String path = unmarshallString(o, "name");
+    public void populate(JSONObject o, String container) {
+        path = unmarshallString(o, "name");
         if (path.contains("/"))
             name = path.substring(path.lastIndexOf("/") + 1, path.length()); //strip the prefix
         else
@@ -112,6 +119,7 @@ public class File extends Resource {
         lastModified = unmarshallDate(o, "last_modified");
         modifiedBy = unmarshallString(o, "modified_by");
         versionTimestamp = unmarshallDate(o, "version_timestamp");
+        this.container = container;
     }
 
     public boolean equals(Object other) {
@@ -125,4 +133,24 @@ public class File extends Resource {
     public int hashCode() {
         return name.hashCode();
     }
+
+    public String getContainer() {
+        return container;
+    }
+
+    public static File createFromResponse(Response response, File result) {
+        result.populate(response);
+        return result;
+    }
+
+    private void populate(Response response) {
+        String header = response.getHeader("X-Object-Meta-Trash");
+        if (header != null)
+            inTrash = Boolean.valueOf(header);
+        else
+            inTrash = false;
+
+        JSONValue json = JSONParser.parseStrict(response.getText());
+        JSONObject o = json.isObject();
+    }
 }
index e58e894..37b4d53 100644 (file)
@@ -100,14 +100,14 @@ public class Folder extends Resource {
                 JSONObject o = array.get(i).isObject();
                 if (o != null) {
                     String contentType = unmarshallString(o, "content_type");
-                    if (o.containsKey("subdir") || (contentType != null && contentType.startsWith("application/directory"))) {
+                    if (o.containsKey("subdir") || (contentType != null && (contentType.startsWith("application/directory") || contentType.startsWith("application/folder")))) {
                         Folder f = new Folder();
                         f.populate(o, container);
                         subfolders.add(f);
                     }
                     else {
                         File file = new File();
-                        file.populate(o);
+                        file.populate(o, container);
                         files.add(file);
                     }
                 }
index 479df02..532cb1c 100644 (file)
@@ -71,6 +71,9 @@ public abstract class Resource {
         else if (aClass.equals(Folder.class)) {
             result = (T) Folder.createFromResponse(response, (Folder) result);
         }
+        else if (aClass.equals(File.class)) {
+            result = (T) File.createFromResponse(response, (File) result);
+        }
         return result;
     }
 }