2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client;
21 import gr.ebs.gss.client.rest.GetCommand;
22 import gr.ebs.gss.client.rest.RestException;
23 import gr.ebs.gss.client.rest.resource.QuotaHolder;
24 import gr.ebs.gss.client.rest.resource.UserResource;
26 import com.google.gwt.core.client.GWT;
27 import com.google.gwt.i18n.client.DateTimeFormat;
28 import com.google.gwt.resources.client.ClientBundle;
29 import com.google.gwt.resources.client.ImageResource;
30 import com.google.gwt.user.client.DeferredCommand;
31 import com.google.gwt.user.client.IncrementalCommand;
32 import com.google.gwt.user.client.ui.AbstractImagePrototype;
33 import com.google.gwt.user.client.ui.Composite;
34 import com.google.gwt.user.client.ui.HTML;
35 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
36 import com.google.gwt.user.client.ui.HorizontalPanel;
39 * The panel that displays a status bar with quota information.
41 public class StatusPanel extends Composite {
42 public static final boolean DONE = false;
43 private HTML fileCountLabel = new HTML("");
44 private HTML fileSizeLabel = new HTML("");
45 private HTML quotaIcon = new HTML("");
46 private HTML quotaLabel = new HTML("");
47 private HTML lastLoginLabel = new HTML("");
48 private HTML currentlyShowingLabel = new HTML("");
51 * An image bundle for this widget's images.
53 public interface Images extends ClientBundle {
55 @Source("gr/ebs/gss/resources/windowlist.png")
56 ImageResource totalFiles();
58 @Source("gr/ebs/gss/resources/database.png")
59 ImageResource totalSize();
61 @Source("gr/ebs/gss/resources/redled.png")
62 ImageResource redSize();
64 @Source("gr/ebs/gss/resources/greenled.png")
65 ImageResource greenSize();
67 @Source("gr/ebs/gss/resources/yellowled.png")
68 ImageResource yellowSize();
70 @Source("gr/ebs/gss/resources/xclock.png")
71 ImageResource lastLogin();
74 private final Images images;
77 * The constructor of the status panel.
79 * @param theImages the supplied images
81 public StatusPanel(Images theImages) {
83 HorizontalPanel outer = new HorizontalPanel();
84 outer.setWidth("100%");
85 outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
87 HorizontalPanel left = new HorizontalPanel();
89 HorizontalPanel middle = new HorizontalPanel();
91 HorizontalPanel right = new HorizontalPanel();
96 left.add(new HTML("<b>Totals:</b> "));
97 left.add(AbstractImagePrototype.create(images.totalFiles()).createImage());
98 left.add(fileCountLabel);
99 left.add(AbstractImagePrototype.create(images.totalSize()).createImage());
100 left.add(fileSizeLabel);
101 quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
103 left.add(quotaLabel);
104 middle.add(AbstractImagePrototype.create(images.lastLogin()).createImage());
105 middle.add(new HTML("<b>Last login:</b> "));
106 middle.add(lastLoginLabel);
107 right.add(currentlyShowingLabel);
108 outer.setStyleName("statusbar-inner");
109 left.setStyleName("statusbar-inner");
110 middle.setStyleName("statusbar-inner");
111 right.setStyleName("statusbar-inner");
112 outer.setCellHorizontalAlignment(right, HasHorizontalAlignment.ALIGN_RIGHT);
116 // Initialize and display the quota information.
117 DeferredCommand.addCommand(new IncrementalCommand() {
119 public boolean execute() {
121 UserResource user = app.getCurrentUserResource();
122 if (user == null || app.getFolders().getRootItem() == null)
131 * Refresh the widget with the provided statistics.
133 private void displayStats(UserResource user) {
134 QuotaHolder stats = user.getQuota();
135 if (stats.getFileCount() == 1)
136 fileCountLabel.setHTML("1 file");
138 fileCountLabel.setHTML(stats.getFileCount() + " files");
139 fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
140 long pc = stats.percentOfFreeSpace();
142 quotaIcon.setHTML(AbstractImagePrototype.create(images.redSize()).getHTML());
143 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
145 quotaIcon.setHTML(AbstractImagePrototype.create(images.yellowSize()).getHTML());
146 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
148 quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
149 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
151 final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
152 lastLoginLabel.setHTML(formatter.format(user.getLastLogin()));
156 * Requests updated quota information from the server and refreshes
159 public void updateStats() {
160 final GSS app = GSS.get();
161 UserResource user = app.getCurrentUserResource();
162 GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri(), null){
164 public void onComplete() {
165 displayStats(getResult());
169 public void onError(Throwable t) {
170 if(t instanceof RestException)
171 app.displayError("Unable to fetch quota:" +
172 ((RestException)t).getHttpStatusText());
174 app.displayError("System error fetching quota:" +
179 DeferredCommand.addCommand(uc);
183 * Displays the statistics for the current folder.
185 * @param text the statistics to display
187 public void updateCurrentlyShowing(String text) {
189 currentlyShowingLabel.setText("");
191 currentlyShowingLabel.setHTML(" <b>Showing:</b> " + text);