Merge branch 'develop' into debian-develop-wheezy
[pithos-web-client] / src / gr / grnet / pithos / web / client / foldertree / FolderTreeView.java
index cd08416..55c40d2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2012 GRNET S.A. All rights reserved.
+ * Copyright 2011-2013 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
 package gr.grnet.pithos.web.client.foldertree;
 
 import gr.grnet.pithos.web.client.FolderContextMenu;
+import gr.grnet.pithos.web.client.Pithos;
 import gr.grnet.pithos.web.client.PithosDisclosurePanel;
 import gr.grnet.pithos.web.client.TreeView;
 
 import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.NumberFormat;
 import com.google.gwt.resources.client.ImageResource;
 import com.google.gwt.resources.client.ImageResource.ImageOptions;
 import com.google.gwt.resources.client.ImageResource.RepeatStyle;
@@ -50,7 +52,11 @@ import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSe
 import com.google.gwt.user.cellview.client.TreeNode;
 import com.google.gwt.user.client.Command;
 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.HorizontalPanel;
 import com.google.gwt.user.client.ui.Tree;
+import com.google.gwt.user.client.ui.VerticalPanel;
 
 public class FolderTreeView extends Composite implements TreeView {
 
@@ -123,15 +129,12 @@ public class FolderTreeView extends Composite implements TreeView {
         @Source("gr/grnet/pithos/resources/home22.png")
         ImageResource home();
 
-        @Source("gr/grnet/pithos/resources/folder22.png")
+        @Source("gr/grnet/pithos/resources/2folder22.png")
         public ImageResource folderYellow();
 
         @Source("gr/grnet/pithos/resources/mimetypes/document.png")
         ImageResource document();
 
-        @Source("gr/grnet/pithos/resources/othersshared.png")
-        ImageResource othersShared();
-
         @Source("gr/grnet/pithos/resources/myshared22.png")
         ImageResource myShared();
 
@@ -155,20 +158,28 @@ public class FolderTreeView extends Composite implements TreeView {
     }
 
     interface Resources extends gr.grnet.pithos.web.client.PithosDisclosurePanel.Resources {
-       @Override
+               @Override
                @Source("gr/grnet/pithos/resources/home22.png")
        ImageResource icon();
     }
 
     private FolderTreeViewModel model;
     
-    private CellTree tree;
+    CellTree tree;
+    
+    private HTML usedBytes;
+    
+    private HTML totalBytes;
+    
+    private HTML usedPercent;
 
     public FolderTreeView(FolderTreeViewModel viewModel) {
         this.model = viewModel;
 
-        PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), "My Files", true);
+        PithosDisclosurePanel panel = new PithosDisclosurePanel((Resources) GWT.create(Resources.class), "My Files", false, true);
 
+        VerticalPanel content = new VerticalPanel();
+        
         /*
          * Create the tree using the model. We use <code>null</code> as the default
          * value of the root node. The default value will be passed to
@@ -177,8 +188,25 @@ public class FolderTreeView extends Composite implements TreeView {
         CellTree.Resources res = GWT.create(BasicResources.class);
         tree = new CellTree(model, null, res);
         tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
-
-        panel.add(tree);
+        tree.setDefaultNodeSize(5000);
+        content.add(tree);
+
+        HorizontalPanel statistics = new HorizontalPanel();
+           statistics.addStyleName(Pithos.resources.pithosCss().statistics());
+           statistics.add(new HTML("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(")"));
+           content.add(statistics);
+           content.setCellHorizontalAlignment(statistics, HasHorizontalAlignment.ALIGN_CENTER);
+
+        panel.setContent(content);
         initWidget(panel);
     }
 
@@ -191,4 +219,11 @@ public class FolderTreeView extends Composite implements TreeView {
     public void updateFolder(Folder folder, boolean showfiles, Command callback, final boolean openParent) {
         model.updateFolder(folder, showfiles, callback, openParent);
     }
+    
+       public void showStatistics(AccountResource account) {
+       usedBytes.setHTML(String.valueOf(account.getFileSizeAsString()));
+       totalBytes.setHTML(String.valueOf(account.getQuotaAsString()));
+       NumberFormat nf = NumberFormat.getPercentFormat();
+       usedPercent.setHTML(nf.format(account.getUsedPercentage()));
+       }
 }