root / src / gr / ebs / gss / client / StatusPanel.java @ 6b38387d
History | View | Annotate | Download (5.6 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
|
3 |
*
|
4 |
* This file is part of GSS.
|
5 |
*
|
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.
|
10 |
*
|
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.
|
15 |
*
|
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/>.
|
18 |
*/
|
19 |
package gr.ebs.gss.client; |
20 |
|
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; |
25 |
|
26 |
import com.google.gwt.core.client.GWT; |
27 |
import com.google.gwt.user.client.DeferredCommand; |
28 |
import com.google.gwt.user.client.IncrementalCommand; |
29 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
30 |
import com.google.gwt.user.client.ui.Composite; |
31 |
import com.google.gwt.user.client.ui.HTML; |
32 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
33 |
import com.google.gwt.user.client.ui.HorizontalPanel; |
34 |
import com.google.gwt.user.client.ui.ImageBundle; |
35 |
|
36 |
/**
|
37 |
* The panel that displays a status bar with quota information.
|
38 |
*/
|
39 |
public class StatusPanel extends Composite { |
40 |
public static final boolean DONE = false; |
41 |
private HTML fileCountLabel = new HTML(""); |
42 |
private HTML fileSizeLabel = new HTML(""); |
43 |
private HTML quotaIcon = new HTML(""); |
44 |
private HTML quotaLabel = new HTML(""); |
45 |
private HTML currentlyShowingLabel = new HTML(""); |
46 |
|
47 |
/**
|
48 |
* An image bundle for this widget's images.
|
49 |
*/
|
50 |
public interface Images extends ImageBundle { |
51 |
|
52 |
@Resource("gr/ebs/gss/resources/windowlist.png") |
53 |
AbstractImagePrototype totalFiles(); |
54 |
|
55 |
@Resource("gr/ebs/gss/resources/database.png") |
56 |
AbstractImagePrototype totalSize(); |
57 |
|
58 |
@Resource("gr/ebs/gss/resources/redled.png") |
59 |
AbstractImagePrototype redSize(); |
60 |
|
61 |
@Resource("gr/ebs/gss/resources/greenled.png") |
62 |
AbstractImagePrototype greenSize(); |
63 |
|
64 |
@Resource("gr/ebs/gss/resources/yellowled.png") |
65 |
AbstractImagePrototype yellowSize(); |
66 |
} |
67 |
|
68 |
private final Images images; |
69 |
|
70 |
/**
|
71 |
* The constructor of the status panel.
|
72 |
*
|
73 |
* @param theImages the supplied images
|
74 |
*/
|
75 |
public StatusPanel(Images theImages) {
|
76 |
images = theImages; |
77 |
HorizontalPanel outer = new HorizontalPanel();
|
78 |
outer.setWidth("100%");
|
79 |
outer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); |
80 |
|
81 |
HorizontalPanel left = new HorizontalPanel();
|
82 |
left.setSpacing(8);
|
83 |
HorizontalPanel right = new HorizontalPanel();
|
84 |
right.setSpacing(8);
|
85 |
outer.add(left); |
86 |
outer.add(right); |
87 |
left.add(new HTML("<b>Totals:</b> ")); |
88 |
left.add(images.totalFiles().createImage()); |
89 |
left.add(fileCountLabel); |
90 |
left.add(images.totalSize().createImage()); |
91 |
left.add(fileSizeLabel); |
92 |
quotaIcon.setHTML(images.greenSize().getHTML()); |
93 |
left.add(quotaIcon); |
94 |
left.add(quotaLabel); |
95 |
right.add(currentlyShowingLabel); |
96 |
outer.setStyleName("statusbar-inner");
|
97 |
left.setStyleName("statusbar-inner");
|
98 |
right.setStyleName("statusbar-inner");
|
99 |
outer.setCellHorizontalAlignment(right, HasHorizontalAlignment.ALIGN_RIGHT); |
100 |
|
101 |
initWidget(outer); |
102 |
|
103 |
// Initialize and display the quota information.
|
104 |
DeferredCommand.addCommand(new IncrementalCommand() {
|
105 |
public boolean execute() { |
106 |
GSS app = GSS.get(); |
107 |
UserResource user = app.getCurrentUserResource(); |
108 |
if (user == null || app.getFolders().getRootItem() == null) |
109 |
return !DONE;
|
110 |
displayStats(user.getQuota()); |
111 |
return DONE;
|
112 |
} |
113 |
}); |
114 |
} |
115 |
|
116 |
/**
|
117 |
* Refresh the widget with the provided statistics.
|
118 |
*/
|
119 |
private void displayStats(QuotaHolder stats) { |
120 |
if (stats.getFileCount() == 1) |
121 |
fileCountLabel.setHTML("1 file");
|
122 |
else
|
123 |
fileCountLabel.setHTML(stats.getFileCount() + " files");
|
124 |
fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
|
125 |
long pc = stats.percentOfFreeSpace();
|
126 |
if(pc<10) { |
127 |
quotaIcon.setHTML(images.redSize().getHTML()); |
128 |
quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
|
129 |
} else if(pc<20) { |
130 |
quotaIcon.setHTML(images.yellowSize().getHTML()); |
131 |
quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
|
132 |
} else {
|
133 |
quotaIcon.setHTML(images.greenSize().getHTML()); |
134 |
quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
|
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Requests updated quota information from the server and refreshes
|
140 |
* the display.
|
141 |
*/
|
142 |
public void updateStats() { |
143 |
final GSS app = GSS.get();
|
144 |
UserResource user = app.getCurrentUserResource(); |
145 |
GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri()){
|
146 |
@Override
|
147 |
public void onComplete() { |
148 |
displayStats(getResult().getQuota()); |
149 |
} |
150 |
|
151 |
@Override
|
152 |
public void onError(Throwable t) { |
153 |
if(t instanceof RestException) |
154 |
app.displayError("Unable to fetch quota:" +
|
155 |
((RestException)t).getHttpStatusText()); |
156 |
else
|
157 |
app.displayError("System error fetching quota:" +
|
158 |
t.getMessage()); |
159 |
GWT.log("ERR", t);
|
160 |
} |
161 |
}; |
162 |
DeferredCommand.addCommand(uc); |
163 |
} |
164 |
|
165 |
/**
|
166 |
* Displays the statistics for the current folder.
|
167 |
*
|
168 |
* @param text the statistics to display
|
169 |
*/
|
170 |
public void updateCurrentlyShowing(String text) { |
171 |
if (text == null) |
172 |
currentlyShowingLabel.setText("");
|
173 |
else
|
174 |
currentlyShowingLabel.setHTML(" <b>Showing:</b> " + text);
|
175 |
} |
176 |
|
177 |
} |