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.user.client.DeferredCommand;
\r
28 import com.google.gwt.user.client.IncrementalCommand;
\r
29 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
30 import com.google.gwt.user.client.ui.Composite;
\r
31 import com.google.gwt.user.client.ui.HTML;
\r
32 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
33 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
34 import com.google.gwt.user.client.ui.ImageBundle;
\r
37 * The panel that displays a status bar with quota information.
\r
39 public class StatusPanel extends Composite {
\r
40 public static final boolean DONE = false;
\r
41 private HTML fileCountLabel;
\r
42 private HTML fileSizeLabel;
\r
43 private HTML quotaLabel;
\r
44 private HTML currentlyShowingLabel;
\r
47 * An image bundle for this widget's images.
\r
49 public interface Images extends ImageBundle {
\r
51 @Resource("gr/ebs/gss/resources/windowlist.png")
\r
52 AbstractImagePrototype totalFiles();
\r
54 @Resource("gr/ebs/gss/resources/database.png")
\r
55 AbstractImagePrototype totalSize();
\r
57 @Resource("gr/ebs/gss/resources/redled.png")
\r
58 AbstractImagePrototype freeSize();
\r
60 @Resource("gr/ebs/gss/resources/greenled.png")
\r
61 AbstractImagePrototype greenSize();
\r
63 @Resource("gr/ebs/gss/resources/yellowled.png")
\r
64 AbstractImagePrototype yellowSize();
\r
67 private final Images images;
\r
70 * The constructor of the status panel.
\r
72 * @param theImages the supplied images
\r
74 public StatusPanel(Images theImages) {
\r
76 HorizontalPanel outer = new HorizontalPanel();
\r
77 outer.setWidth("100%");
\r
78 outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
\r
80 HorizontalPanel left = new HorizontalPanel();
\r
82 HorizontalPanel right = new HorizontalPanel();
\r
83 right.setSpacing(8);
\r
86 left.add(new HTML("<b>Totals:</b> "));
\r
87 left.add(images.totalFiles().createImage());
\r
88 left.add(fileCountLabel = new HTML(""));
\r
89 left.add(images.totalSize().createImage());
\r
90 left.add(fileSizeLabel = new HTML(""));
\r
91 left.add(quotaLabel = new HTML(""));
\r
92 right.add(currentlyShowingLabel = new HTML(""));
\r
93 outer.setStyleName("statusbar-inner");
\r
94 left.setStyleName("statusbar-inner");
\r
95 right.setStyleName("statusbar-inner");
\r
96 outer.setCellHorizontalAlignment(right, HasHorizontalAlignment.ALIGN_RIGHT);
\r
100 // Initialize and display the quota information.
\r
101 DeferredCommand.addCommand(new IncrementalCommand() {
\r
102 public boolean execute() {
\r
103 GSS app = GSS.get();
\r
104 UserResource user = app.getCurrentUserResource();
\r
105 if (user == null || app.getFolders().getRootItem() == null)
\r
107 displayStats(user.getQuota());
\r
114 * Refresh the widget with the provided statistics.
\r
116 private void displayStats(QuotaHolder stats) {
\r
117 if (stats.getFileCount() == 1)
\r
118 fileCountLabel.setHTML("1 file");
\r
120 fileCountLabel.setHTML(stats.getFileCount() + " files");
\r
121 fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
\r
122 long pc = stats.percentOfFreeSpace();
\r
124 quotaLabel.setHTML(images.freeSize().getHTML()+" "+stats.getQuotaLeftAsString() +" free");
\r
126 quotaLabel.setHTML(images.yellowSize().getHTML()+" "+stats.getQuotaLeftAsString() +" free");
\r
128 quotaLabel.setHTML(images.greenSize().getHTML()+" "+stats.getQuotaLeftAsString() +" free");
\r
132 * Requests updated quota information from the server and refreshes
\r
135 public void updateStats() {
\r
136 final GSS app = GSS.get();
\r
137 UserResource user = app.getCurrentUserResource();
\r
138 GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri()){
\r
140 public void onComplete() {
\r
141 displayStats(getResult().getQuota());
\r
145 public void onError(Throwable t) {
\r
146 if(t instanceof RestException)
\r
147 app.displayError("Unable to fetch quota:"+((RestException)t).getHttpStatusText());
\r
149 app.displayError("System error fetching quota:"+t.getMessage());
\r
153 DeferredCommand.addCommand(uc);
\r
157 * Displays the statistics for the current folder.
\r
159 * @param text the statistics to display
\r
161 public void updateCurrentlyShowing(String text) {
\r
163 currentlyShowingLabel.setText("");
\r
165 currentlyShowingLabel.setHTML(" <b>Showing:</b> " + text);
\r