Automated merge with https://gss.googlecode.com/hg/
[pithos] / src / gr / ebs / gss / client / StatusPanel.java
index 079b9c6..949d4c0 100644 (file)
-/*\r
- * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.\r
- *\r
- * This file is part of GSS.\r
- *\r
- * GSS is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * GSS is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package gr.ebs.gss.client;\r
-\r
-import gr.ebs.gss.client.rest.GetCommand;\r
-import gr.ebs.gss.client.rest.RestException;\r
-import gr.ebs.gss.client.rest.resource.QuotaHolder;\r
-import gr.ebs.gss.client.rest.resource.UserResource;\r
-\r
-import com.google.gwt.core.client.GWT;\r
-import com.google.gwt.resources.client.ClientBundle;\r
-import com.google.gwt.resources.client.ImageResource;\r
-import com.google.gwt.user.client.DeferredCommand;\r
-import com.google.gwt.user.client.IncrementalCommand;\r
-import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
-import com.google.gwt.user.client.ui.Composite;\r
-import com.google.gwt.user.client.ui.HTML;\r
-import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
-import com.google.gwt.user.client.ui.HorizontalPanel;\r
-\r
-/**\r
- * The panel that displays a status bar with quota information.\r
- */\r
-public class StatusPanel extends Composite {\r
-       public static final boolean DONE = false;\r
-       private HTML fileCountLabel = new HTML("");\r
-       private HTML fileSizeLabel = new HTML("");\r
-       private HTML quotaIcon = new HTML("");\r
-       private HTML quotaLabel = new HTML("");\r
-       private HTML currentlyShowingLabel = new HTML("");\r
-\r
-       /**\r
-        * An image bundle for this widget's images.\r
-        */\r
-       public interface Images extends ClientBundle {\r
-\r
-               @Source("gr/ebs/gss/resources/windowlist.png")\r
-               ImageResource totalFiles();\r
-\r
-               @Source("gr/ebs/gss/resources/database.png")\r
-               ImageResource totalSize();\r
-\r
-               @Source("gr/ebs/gss/resources/redled.png")\r
-               ImageResource redSize();\r
-\r
-               @Source("gr/ebs/gss/resources/greenled.png")\r
-               ImageResource greenSize();\r
-\r
-               @Source("gr/ebs/gss/resources/yellowled.png")\r
-               ImageResource yellowSize();\r
-       }\r
-\r
-       private final Images images;\r
-\r
-       /**\r
-        * The constructor of the status panel.\r
-        *\r
-        * @param theImages the supplied images\r
-        */\r
-       public StatusPanel(Images theImages) {\r
-               images = theImages;\r
-               HorizontalPanel outer = new HorizontalPanel();\r
-               outer.setWidth("100%");\r
-               outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);\r
-\r
-               HorizontalPanel left = new HorizontalPanel();\r
-               left.setSpacing(8);\r
-               HorizontalPanel right = new HorizontalPanel();\r
-               right.setSpacing(8);\r
-               outer.add(left);\r
-               outer.add(right);\r
-               left.add(new HTML("<b>Totals:</b> "));\r
-               left.add(AbstractImagePrototype.create(images.totalFiles()).createImage());\r
-               left.add(fileCountLabel);\r
-               left.add(AbstractImagePrototype.create(images.totalSize()).createImage());\r
-               left.add(fileSizeLabel);\r
-               quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());\r
-               left.add(quotaIcon);\r
-               left.add(quotaLabel);\r
-               right.add(currentlyShowingLabel);\r
-               outer.setStyleName("statusbar-inner");\r
-               left.setStyleName("statusbar-inner");\r
-               right.setStyleName("statusbar-inner");\r
-               outer.setCellHorizontalAlignment(right, HasHorizontalAlignment.ALIGN_RIGHT);\r
-\r
-               initWidget(outer);\r
-\r
-               // Initialize and display the quota information.\r
-               DeferredCommand.addCommand(new IncrementalCommand() {\r
-                       public boolean execute() {\r
-                               GSS app = GSS.get();\r
-                               UserResource user = app.getCurrentUserResource();\r
-                               if (user == null || app.getFolders().getRootItem() == null)\r
-                                       return !DONE;\r
-                               displayStats(user.getQuota());\r
-                               return DONE;\r
-                       }\r
-               });\r
-       }\r
-\r
-       /**\r
-        * Refresh the widget with the provided statistics.\r
-        */\r
-       private void displayStats(QuotaHolder stats) {\r
-               if (stats.getFileCount() == 1)\r
-                       fileCountLabel.setHTML("1 file");\r
-               else\r
-                       fileCountLabel.setHTML(stats.getFileCount() + " files");\r
-               fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");\r
-               long pc = stats.percentOfFreeSpace();\r
-               if(pc<10) {\r
-                       quotaIcon.setHTML(AbstractImagePrototype.create(images.redSize()).getHTML());\r
-                       quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");\r
-               } else if(pc<20) {\r
-                       quotaIcon.setHTML(AbstractImagePrototype.create(images.yellowSize()).getHTML());\r
-                       quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");\r
-               } else {\r
-                       quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());\r
-                       quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Requests updated quota information from the server and refreshes\r
-        * the display.\r
-        */\r
-       public void updateStats() {\r
-               final GSS app = GSS.get();\r
-               UserResource user = app.getCurrentUserResource();\r
-               GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri()){\r
-                       @Override\r
-                       public void onComplete() {\r
-                               displayStats(getResult().getQuota());\r
-                       }\r
-\r
-                       @Override\r
-                       public void onError(Throwable t) {\r
-                               if(t instanceof RestException)\r
-                                       app.displayError("Unable to fetch quota:" +\r
-                                                               ((RestException)t).getHttpStatusText());\r
-                               else\r
-                                       app.displayError("System error fetching quota:" +\r
-                                                               t.getMessage());\r
-                               GWT.log("ERR", t);\r
-                       }\r
-               };\r
-               DeferredCommand.addCommand(uc);\r
-       }\r
-\r
-       /**\r
-        * Displays the statistics for the current folder.\r
-        *\r
-        * @param text the statistics to display\r
-        */\r
-       public void updateCurrentlyShowing(String text) {\r
-               if (text == null)\r
-                       currentlyShowingLabel.setText("");\r
-               else\r
-                       currentlyShowingLabel.setHTML(" <b>Showing:</b> " + text);\r
-       }\r
-\r
-}\r
+/*
+ * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
+ *
+ * This file is part of GSS.
+ *
+ * GSS is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GSS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package gr.ebs.gss.client;
+
+import gr.ebs.gss.client.rest.GetCommand;
+import gr.ebs.gss.client.rest.RestException;
+import gr.ebs.gss.client.rest.resource.QuotaHolder;
+import gr.ebs.gss.client.rest.resource.UserResource;
+
+import com.google.gwt.core.client.GWT;
+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.DeferredCommand;
+import com.google.gwt.user.client.IncrementalCommand;
+import com.google.gwt.user.client.ui.AbstractImagePrototype;
+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;
+
+/**
+ * The panel that displays a status bar with quota information.
+ */
+public class StatusPanel extends Composite {
+       public static final boolean DONE = false;
+       private HTML fileCountLabel = new HTML("");
+       private HTML fileSizeLabel = new HTML("");
+       private HTML quotaIcon = new HTML("");
+       private HTML quotaLabel = new HTML("");
+       private HTML lastLoginLabel = new HTML("");
+       private HTML currentLoginLabel = new HTML("");
+       private HTML currentlyShowingLabel = new HTML("");
+
+       /**
+        * An image bundle for this widget's images.
+        */
+       public interface Images extends ClientBundle {
+
+               @Source("gr/ebs/gss/resources/windowlist.png")
+               ImageResource totalFiles();
+
+               @Source("gr/ebs/gss/resources/database.png")
+               ImageResource totalSize();
+
+               @Source("gr/ebs/gss/resources/redled.png")
+               ImageResource redSize();
+
+               @Source("gr/ebs/gss/resources/greenled.png")
+               ImageResource greenSize();
+
+               @Source("gr/ebs/gss/resources/yellowled.png")
+               ImageResource yellowSize();
+
+               @Source("gr/ebs/gss/resources/xclock.png")
+               ImageResource lastLogin();              
+       }
+
+       private final Images images;
+
+       /**
+        * The constructor of the status panel.
+        *
+        * @param theImages the supplied images
+        */
+       public StatusPanel(Images theImages) {
+               images = theImages;
+               HorizontalPanel outer = new HorizontalPanel();
+               outer.setWidth("100%");
+               outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
+
+               HorizontalPanel left = new HorizontalPanel();
+               left.setSpacing(8);
+               HorizontalPanel middle = new HorizontalPanel();
+               middle.setSpacing(8);
+               HorizontalPanel right = new HorizontalPanel();
+               right.setSpacing(8);
+               outer.add(left);
+               outer.add(middle);
+               outer.add(right);
+               left.add(new HTML("<b>Totals:</b> "));
+               left.add(AbstractImagePrototype.create(images.totalFiles()).createImage());
+               left.add(fileCountLabel);
+               left.add(AbstractImagePrototype.create(images.totalSize()).createImage());
+               left.add(fileSizeLabel);
+               quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
+               left.add(quotaIcon);
+               left.add(quotaLabel);
+               middle.add(AbstractImagePrototype.create(images.lastLogin()).createImage());
+               middle.add(new HTML("<b>Last login:</b> "));
+               middle.add(lastLoginLabel);
+               middle.add(new HTML("<b>\u0387 Current session login:</b> "));
+               middle.add(currentLoginLabel);
+               right.add(currentlyShowingLabel);
+               outer.setStyleName("statusbar-inner");
+               left.setStyleName("statusbar-inner");
+               middle.setStyleName("statusbar-inner");
+               right.setStyleName("statusbar-inner");
+               outer.setCellHorizontalAlignment(right, HasHorizontalAlignment.ALIGN_RIGHT);
+
+               initWidget(outer);
+
+               // Initialize and display the quota information.
+               DeferredCommand.addCommand(new IncrementalCommand() {
+                       @Override
+                       public boolean execute() {
+                               GSS app = GSS.get();
+                               UserResource user = app.getCurrentUserResource();
+                               if (user == null || app.getTreeView().getMyFolders() == null)
+                                       return !DONE;
+                               displayStats(user);
+                               return DONE;
+                       }
+               });
+       }
+
+       /**
+        * Refresh the widget with the provided statistics.
+        */
+       private void displayStats(UserResource user) {
+               QuotaHolder stats = user.getQuota();
+               if (stats.getFileCount() == 1)
+                       fileCountLabel.setHTML("1 file");
+               else
+                       fileCountLabel.setHTML(stats.getFileCount() + " files");
+               fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
+               long pc = stats.percentOfFreeSpace();
+               if(pc<10) {
+                       quotaIcon.setHTML(AbstractImagePrototype.create(images.redSize()).getHTML());
+                       quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
+               } else if(pc<20) {
+                       quotaIcon.setHTML(AbstractImagePrototype.create(images.yellowSize()).getHTML());
+                       quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
+               } else {
+                       quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
+                       quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
+               }
+               final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
+               lastLoginLabel.setHTML(formatter.format(user.getLastLogin()));
+               currentLoginLabel.setHTML(formatter.format(user.getCurrentLogin()));
+       }
+
+       /**
+        * Requests updated quota information from the server and refreshes
+        * the display.
+        */
+       public void updateStats() {
+               final GSS app = GSS.get();
+               UserResource user = app.getCurrentUserResource();
+               GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri(), null){
+                       @Override
+                       public void onComplete() {
+                               displayStats(getResult());
+                       }
+
+                       @Override
+                       public void onError(Throwable t) {
+                               if(t instanceof RestException)
+                                       app.displayError("Unable to fetch quota:" +
+                                                               ((RestException)t).getHttpStatusText());
+                               else
+                                       app.displayError("System error fetching quota:" +
+                                                               t.getMessage());
+                               GWT.log("ERR", t);
+                       }
+               };
+               DeferredCommand.addCommand(uc);
+       }
+
+       /**
+        * Displays the statistics for the current folder.
+        *
+        * @param text the statistics to display
+        */
+       public void updateCurrentlyShowing(String text) {
+               if (text == null)
+                       currentlyShowingLabel.setText("");
+               else
+                       currentlyShowingLabel.setHTML(" <b>Showing:</b> " + text);
+       }
+
+}