Revision 5cd18037 web_client/src/gr/grnet/pithos/web/client/StatusPanel.java
b/web_client/src/gr/grnet/pithos/web/client/StatusPanel.java | ||
---|---|---|
3 | 3 |
*/ |
4 | 4 |
package gr.grnet.pithos.web.client; |
5 | 5 |
|
6 |
import com.google.gwt.core.client.Scheduler; |
|
7 |
import com.google.gwt.core.client.Scheduler.ScheduledCommand; |
|
8 |
import gr.grnet.pithos.web.client.foldertree.AccountResource; |
|
6 | 9 |
import gr.grnet.pithos.web.client.rest.GetCommand; |
10 |
import gr.grnet.pithos.web.client.rest.GetRequest; |
|
7 | 11 |
import gr.grnet.pithos.web.client.rest.RestException; |
8 | 12 |
import gr.grnet.pithos.web.client.rest.resource.QuotaHolder; |
9 | 13 |
import gr.grnet.pithos.web.client.rest.resource.UserResource; |
... | ... | |
12 | 16 |
import com.google.gwt.i18n.client.DateTimeFormat; |
13 | 17 |
import com.google.gwt.resources.client.ClientBundle; |
14 | 18 |
import com.google.gwt.resources.client.ImageResource; |
15 |
import com.google.gwt.user.client.DeferredCommand; |
|
16 |
import com.google.gwt.user.client.IncrementalCommand; |
|
17 | 19 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
18 | 20 |
import com.google.gwt.user.client.ui.Composite; |
19 | 21 |
import com.google.gwt.user.client.ui.HTML; |
... | ... | |
101 | 103 |
|
102 | 104 |
initWidget(outer); |
103 | 105 |
|
104 |
// Initialize and display the quota information. |
|
105 |
DeferredCommand.addCommand(new IncrementalCommand() { |
|
106 |
@Override |
|
107 |
public boolean execute() { |
|
108 |
GSS app = GSS.get(); |
|
109 |
UserResource user = app.getCurrentUserResource(); |
|
110 |
if (user == null || app.getTreeView().getMyFolders() == null) |
|
111 |
return !DONE; |
|
112 |
displayStats(user); |
|
113 |
return DONE; |
|
114 |
} |
|
115 |
}); |
|
106 |
Scheduler.get().scheduleDeferred(new ScheduledCommand() { |
|
107 |
@Override |
|
108 |
public void execute() { |
|
109 |
AccountResource account = GSS.get().getAccount(); |
|
110 |
displayStats(account); |
|
111 |
} |
|
112 |
}); |
|
116 | 113 |
} |
117 | 114 |
|
118 | 115 |
/** |
119 | 116 |
* Refresh the widget with the provided statistics. |
120 | 117 |
*/ |
121 |
private void displayStats(UserResource user) { |
|
122 |
QuotaHolder stats = user.getQuota(); |
|
123 |
if (stats.getFileCount() == 1) |
|
124 |
fileCountLabel.setHTML("1 file"); |
|
118 |
private void displayStats(AccountResource account) { |
|
119 |
if (account.getNumberOfObjects() == 1) |
|
120 |
fileCountLabel.setHTML("1 object"); |
|
125 | 121 |
else |
126 |
fileCountLabel.setHTML(stats.getFileCount() + " files");
|
|
127 |
fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
|
|
128 |
long pc = stats.percentOfFreeSpace();
|
|
129 |
if(pc<10) {
|
|
122 |
fileCountLabel.setHTML(account.getNumberOfObjects() + " objects");
|
|
123 |
fileSizeLabel.setHTML(account.getFileSizeAsString() + " used");
|
|
124 |
long pc = (long) ((double) account.getBytesRemaining()/(account.getBytesRemaining() + account.getBytesUsed()) + 0.5);
|
|
125 |
if (pc < 10) {
|
|
130 | 126 |
quotaIcon.setHTML(AbstractImagePrototype.create(images.redSize()).getHTML()); |
131 |
quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
|
|
127 |
quotaLabel.setHTML(account.getQuotaLeftAsString() + " free");
|
|
132 | 128 |
} else if(pc<20) { |
133 | 129 |
quotaIcon.setHTML(AbstractImagePrototype.create(images.yellowSize()).getHTML()); |
134 |
quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
|
|
130 |
quotaLabel.setHTML(account.getQuotaLeftAsString() +" free");
|
|
135 | 131 |
} else { |
136 | 132 |
quotaIcon.setHTML(AbstractImagePrototype.create(images.greenSize()).getHTML()); |
137 |
quotaLabel.setHTML(stats.getQuotaLeftAsString() +" free");
|
|
133 |
quotaLabel.setHTML(account.getQuotaLeftAsString() +" free");
|
|
138 | 134 |
} |
139 | 135 |
final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); |
140 |
lastLoginLabel.setHTML(formatter.format(user.getLastLogin()));
|
|
141 |
currentLoginLabel.setHTML(formatter.format(user.getCurrentLogin()));
|
|
136 |
lastLoginLabel.setHTML(formatter.format(account.getLastLogin()));
|
|
137 |
currentLoginLabel.setHTML(formatter.format(account.getCurrentLogin()));
|
|
142 | 138 |
} |
143 | 139 |
|
144 | 140 |
/** |
... | ... | |
147 | 143 |
*/ |
148 | 144 |
public void updateStats() { |
149 | 145 |
final GSS app = GSS.get(); |
150 |
UserResource user = app.getCurrentUserResource(); |
|
151 |
GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri(), null){ |
|
152 |
@Override |
|
153 |
public void onComplete() { |
|
154 |
displayStats(getResult()); |
|
155 |
} |
|
156 |
|
|
157 |
@Override |
|
158 |
public void onError(Throwable t) { |
|
159 |
if(t instanceof RestException) |
|
160 |
app.displayError("Unable to fetch quota:" + |
|
161 |
((RestException)t).getHttpStatusText()); |
|
162 |
else |
|
163 |
app.displayError("System error fetching quota:" + |
|
164 |
t.getMessage()); |
|
165 |
GWT.log("ERR", t); |
|
166 |
} |
|
167 |
}; |
|
168 |
DeferredCommand.addCommand(uc); |
|
146 |
String path = app.getApiPath() + app.getUsername(); |
|
147 |
GetRequest<AccountResource> getAccount = new GetRequest<AccountResource>(AccountResource.class, path) { |
|
148 |
@Override |
|
149 |
public void onSuccess(AccountResource result) { |
|
150 |
displayStats(result); |
|
151 |
} |
|
152 |
|
|
153 |
@Override |
|
154 |
public void onError(Throwable t) { |
|
155 |
if(t instanceof RestException) |
|
156 |
app.displayError("Unable to fetch quota:" + |
|
157 |
((RestException)t).getHttpStatusText()); |
|
158 |
else |
|
159 |
app.displayError("System error fetching quota:" + |
|
160 |
t.getMessage()); |
|
161 |
GWT.log("ERR", t); |
|
162 |
} |
|
163 |
}; |
|
164 |
|
|
165 |
Scheduler.get().scheduleDeferred(getAccount); |
|
169 | 166 |
} |
170 | 167 |
|
171 | 168 |
/** |
Also available in: Unified diff