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 currentLoginLabel = new HTML("");
49 private HTML currentlyShowingLabel = new HTML("");
52 * An image bundle for this widget's images.
54 public interface Images extends ClientBundle {
56 @Source("gr/ebs/gss/resources/windowlist.png")
57 ImageResource totalFiles();
59 @Source("gr/ebs/gss/resources/database.png")
60 ImageResource totalSize();
62 @Source("gr/ebs/gss/resources/redled.png")
63 ImageResource redSize();
65 @Source("gr/ebs/gss/resources/greenled.png")
66 ImageResource greenSize();
68 @Source("gr/ebs/gss/resources/yellowled.png")
69 ImageResource yellowSize();
71 @Source("gr/ebs/gss/resources/xclock.png")
72 ImageResource lastLogin();
75 private final Images images;
78 * The constructor of the status panel.
80 * @param theImages the supplied images
82 public StatusPanel(Images theImages) {
84 HorizontalPanel outer = new HorizontalPanel();
85 outer.setWidth("100%");
86 outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
88 HorizontalPanel left = new HorizontalPanel();
90 HorizontalPanel middle = new HorizontalPanel();
92 HorizontalPanel right = new HorizontalPanel();
97 left.add(new HTML("<b>Totals:</b> "));
98 left.add(AbstractImagePrototype.create(images.totalFiles()).createImage());
99 left.add(fileCountLabel);
100 left.add(AbstractImagePrototype.create(images.totalSize()).createImage());
101 left.add(fileSizeLabel);
102 quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
104 left.add(quotaLabel);
105 middle.add(AbstractImagePrototype.create(images.lastLogin()).createImage());
106 middle.add(new HTML("<b>Last login:</b> "));
107 middle.add(lastLoginLabel);
108 middle.add(new HTML("<b>\u0387 Current session login:</b> "));
109 middle.add(currentLoginLabel);
110 right.add(currentlyShowingLabel);
111 outer.setStyleName("statusbar-inner");
112 left.setStyleName("statusbar-inner");
113 middle.setStyleName("statusbar-inner");
114 right.setStyleName("statusbar-inner");
115 outer.setCellHorizontalAlignment(right, HasHorizontalAlignment.ALIGN_RIGHT);
119 // Initialize and display the quota information.
120 DeferredCommand.addCommand(new IncrementalCommand() {
122 public boolean execute() {
124 UserResource user = app.getCurrentUserResource();
125 if (user == null || app.getFolders().getRootItem() == null)
134 * Refresh the widget with the provided statistics.
136 private void displayStats(UserResource user) {
137 QuotaHolder stats = user.getQuota();
138 if (stats.getFileCount() == 1)
139 fileCountLabel.setHTML("1 file");
141 fileCountLabel.setHTML(stats.getFileCount() + " files");
142 fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
143 long pc = stats.percentOfFreeSpace();
145 quotaIcon.setHTML(AbstractImagePrototype.create(images.redSize()).getHTML());
146 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
148 quotaIcon.setHTML(AbstractImagePrototype.create(images.yellowSize()).getHTML());
149 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
151 quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
152 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
154 final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
155 lastLoginLabel.setHTML(formatter.format(user.getLastLogin()));
156 currentLoginLabel.setHTML(formatter.format(user.getCurrentLogin()));
160 * Requests updated quota information from the server and refreshes
163 public void updateStats() {
164 final GSS app = GSS.get();
165 UserResource user = app.getCurrentUserResource();
166 GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri(), null){
168 public void onComplete() {
169 displayStats(getResult());
173 public void onError(Throwable t) {
174 if(t instanceof RestException)
175 app.displayError("Unable to fetch quota:" +
176 ((RestException)t).getHttpStatusText());
178 app.displayError("System error fetching quota:" +
183 DeferredCommand.addCommand(uc);
187 * Displays the statistics for the current folder.
189 * @param text the statistics to display
191 public void updateCurrentlyShowing(String text) {
193 currentlyShowingLabel.setText("");
195 currentlyShowingLabel.setHTML(" <b>Showing:</b> " + text);