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