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.resources.client.ClientBundle;
\r
28 import com.google.gwt.resources.client.ImageResource;
\r
29 import com.google.gwt.user.client.DeferredCommand;
\r
30 import com.google.gwt.user.client.IncrementalCommand;
\r
31 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
32 import com.google.gwt.user.client.ui.Composite;
\r
33 import com.google.gwt.user.client.ui.HTML;
\r
34 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
35 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
38 * The panel that displays a status bar with quota information.
\r
40 public class StatusPanel extends Composite {
\r
41 public static final boolean DONE = false;
\r
42 private HTML fileCountLabel = new HTML("");
\r
43 private HTML fileSizeLabel = new HTML("");
\r
44 private HTML quotaIcon = new HTML("");
\r
45 private HTML quotaLabel = new HTML("");
\r
46 private HTML currentlyShowingLabel = new HTML("");
\r
49 * An image bundle for this widget's images.
\r
51 public interface Images extends ClientBundle {
\r
53 @Source("gr/ebs/gss/resources/windowlist.png")
\r
54 ImageResource totalFiles();
\r
56 @Source("gr/ebs/gss/resources/database.png")
\r
57 ImageResource totalSize();
\r
59 @Source("gr/ebs/gss/resources/redled.png")
\r
60 ImageResource redSize();
\r
62 @Source("gr/ebs/gss/resources/greenled.png")
\r
63 ImageResource greenSize();
\r
65 @Source("gr/ebs/gss/resources/yellowled.png")
\r
66 ImageResource yellowSize();
\r
69 private final Images images;
\r
72 * The constructor of the status panel.
\r
74 * @param theImages the supplied images
\r
76 public StatusPanel(Images theImages) {
\r
78 HorizontalPanel outer = new HorizontalPanel();
\r
79 outer.setWidth("100%");
\r
80 outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
\r
82 HorizontalPanel left = new HorizontalPanel();
\r
84 HorizontalPanel right = new HorizontalPanel();
\r
85 right.setSpacing(8);
\r
88 left.add(new HTML("<b>Totals:</b> "));
\r
89 left.add(AbstractImagePrototype.create(images.totalFiles()).createImage());
\r
90 left.add(fileCountLabel);
\r
91 left.add(AbstractImagePrototype.create(images.totalSize()).createImage());
\r
92 left.add(fileSizeLabel);
\r
93 quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
\r
94 left.add(quotaIcon);
\r
95 left.add(quotaLabel);
\r
96 right.add(currentlyShowingLabel);
\r
97 outer.setStyleName("statusbar-inner");
\r
98 left.setStyleName("statusbar-inner");
\r
99 right.setStyleName("statusbar-inner");
\r
100 outer.setCellHorizontalAlignment(right, HasHorizontalAlignment.ALIGN_RIGHT);
\r
104 // Initialize and display the quota information.
\r
105 DeferredCommand.addCommand(new IncrementalCommand() {
\r
106 public boolean execute() {
\r
107 GSS app = GSS.get();
\r
108 UserResource user = app.getCurrentUserResource();
\r
109 if (user == null || app.getFolders().getRootItem() == null)
\r
111 displayStats(user.getQuota());
\r
118 * Refresh the widget with the provided statistics.
\r
120 private void displayStats(QuotaHolder stats) {
\r
121 if (stats.getFileCount() == 1)
\r
122 fileCountLabel.setHTML("1 file");
\r
124 fileCountLabel.setHTML(stats.getFileCount() + " files");
\r
125 fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
\r
126 long pc = stats.percentOfFreeSpace();
\r
128 quotaIcon.setHTML(AbstractImagePrototype.create(images.redSize()).getHTML());
\r
129 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
\r
131 quotaIcon.setHTML(AbstractImagePrototype.create(images.yellowSize()).getHTML());
\r
132 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
\r
134 quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML());
\r
135 quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
\r
140 * Requests updated quota information from the server and refreshes
\r
143 public void updateStats() {
\r
144 final GSS app = GSS.get();
\r
145 UserResource user = app.getCurrentUserResource();
\r
146 GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri()){
\r
148 public void onComplete() {
\r
149 displayStats(getResult().getQuota());
\r
153 public void onError(Throwable t) {
\r
154 if(t instanceof RestException)
\r
155 app.displayError("Unable to fetch quota:" +
\r
156 ((RestException)t).getHttpStatusText());
\r
158 app.displayError("System error fetching quota:" +
\r
163 DeferredCommand.addCommand(uc);
\r
167 * Displays the statistics for the current folder.
\r
169 * @param text the statistics to display
\r
171 public void updateCurrentlyShowing(String text) {
\r
173 currentlyShowingLabel.setText("");
\r
175 currentlyShowingLabel.setHTML(" <b>Showing:</b> " + text);
\r