Revision 328edf07

b/gss/src/gr/ebs/gss/client/StatusPanel.java
97 97

  
98 98
		initWidget(outer);
99 99

  
100
		// Initialize and display the quota information.
100 101
		DeferredCommand.addCommand(new IncrementalCommand() {
101 102
			public boolean execute() {
102
				return updateStats();
103
				GSS app = GSS.get();
104
				UserResource user = app.getCurrentUserResource();
105
				if (user == null || app.getFolders().getRootItem() == null)
106
					return !DONE;
107
				displayStats(user.getQuota());
108
				return DONE;
103 109
			}
104 110
		});
105 111
	}
106 112

  
107
	public boolean updateStats() {
108
		UserResource userResource = GSS.get().getCurrentUserResource();
109
		if (userResource == null || GSS.get().getFolders().getRootItem() == null) return !DONE;
110
		GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, userResource.getUri()){
113
	/**
114
	 * Refresh the widget with the provided statistics.
115
	 */
116
	private void displayStats(QuotaHolder stats) {
117
		if (stats.getFileCount() == 1)
118
			fileCountLabel.setHTML("1 file");
119
		else
120
			fileCountLabel.setHTML(stats.getFileCount() + " files");
121
		fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
122
		long pc = stats.percentOfFreeSpace();
123
		if(pc<10)
124
			quotaLabel.setHTML(images.freeSize().getHTML()+"&nbsp;"+stats.getQuotaLeftAsString() +" free");
125
		else if(pc<20)
126
			quotaLabel.setHTML(images.yellowSize().getHTML()+"&nbsp;"+stats.getQuotaLeftAsString() +" free");
127
		else
128
			quotaLabel.setHTML(images.greenSize().getHTML()+"&nbsp;"+stats.getQuotaLeftAsString() +" free");
129
	}
130

  
131
	/**
132
	 * Requests updated quota information from the server and refreshes
133
	 * the display.
134
	 */
135
	public void updateStats() {
136
		final GSS app = GSS.get();
137
		UserResource user = app.getCurrentUserResource();
138
		GetCommand<UserResource> uc = new GetCommand<UserResource>(UserResource.class, user.getUri()){
111 139
			@Override
112 140
			public void onComplete() {
113
				final QuotaHolder stats = getResult().getQuota();
114
				if (stats.getFileCount() == 1)
115
					fileCountLabel.setHTML("1 file");
116
				else
117
					fileCountLabel.setHTML(stats.getFileCount() + " files");
118
				fileSizeLabel.setHTML(stats.getFileSizeAsString() + " used");
119
				long pc = stats.percentOfFreeSpace();
120
				if(pc<10)
121
					quotaLabel.setHTML(images.freeSize().getHTML()+"&nbsp;"+stats.getQuotaLeftAsString() +" free");
122
				else if(pc<20)
123
					quotaLabel.setHTML(images.yellowSize().getHTML()+"&nbsp;"+stats.getQuotaLeftAsString() +" free");
124
				else
125
					quotaLabel.setHTML(images.greenSize().getHTML()+"&nbsp;"+stats.getQuotaLeftAsString() +" free");
141
				displayStats(getResult().getQuota());
126 142
			}
127 143

  
128 144
			@Override
129 145
			public void onError(Throwable t) {
130 146
				if(t instanceof RestException)
131
					GSS.get().displayError("Unable to fetch quota:"+((RestException)t).getHttpStatusText());
147
					app.displayError("Unable to fetch quota:"+((RestException)t).getHttpStatusText());
132 148
				else
133
					GSS.get().displayError("System error fetching quota:"+t.getMessage());
149
					app.displayError("System error fetching quota:"+t.getMessage());
134 150
				GWT.log("ERR", t);
135 151
			}
136 152
		};
137 153
		DeferredCommand.addCommand(uc);
138
		return DONE;
139 154
	}
140 155

  
156
	/**
157
	 * Displays the statistics for the current folder.
158
	 *
159
	 * @param text the statistics to display
160
	 */
141 161
	public void updateCurrentlyShowing(String text) {
142 162
		if (text == null)
143 163
			currentlyShowingLabel.setText("");

Also available in: Unified diff