14 |
ddelon |
1 |
/*
|
|
|
2 |
* Copyright 2006 Google Inc.
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
5 |
* use this file except in compliance with the License. You may obtain a copy of
|
|
|
6 |
* the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
12 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
13 |
* License for the specific language governing permissions and limitations under
|
|
|
14 |
* the License.
|
|
|
15 |
*/
|
|
|
16 |
package org.tela_botanica.client;
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
import com.google.gwt.json.client.JSONArray;
|
|
|
20 |
import com.google.gwt.json.client.JSONNumber;
|
|
|
21 |
import com.google.gwt.json.client.JSONParser;
|
|
|
22 |
import com.google.gwt.json.client.JSONString;
|
|
|
23 |
import com.google.gwt.json.client.JSONValue;
|
|
|
24 |
import com.google.gwt.user.client.HTTPRequest;
|
|
|
25 |
import com.google.gwt.user.client.ResponseTextHandler;
|
|
|
26 |
import com.google.gwt.user.client.ui.Button;
|
|
|
27 |
import com.google.gwt.user.client.ui.ClickListener;
|
|
|
28 |
import com.google.gwt.user.client.ui.Composite;
|
|
|
29 |
import com.google.gwt.user.client.ui.DockPanel;
|
|
|
30 |
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
31 |
import com.google.gwt.user.client.ui.Grid;
|
|
|
32 |
import com.google.gwt.user.client.ui.HTML;
|
|
|
33 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
|
|
34 |
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
|
|
35 |
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
36 |
import com.google.gwt.user.client.ui.SourcesTableEvents;
|
|
|
37 |
import com.google.gwt.user.client.ui.TableListener;
|
|
|
38 |
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
39 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* A tree displaying a set of email folders.
|
|
|
43 |
*/
|
|
|
44 |
public class StationList extends Composite {
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
// Barre de navigation
|
|
|
49 |
|
|
|
50 |
private class NavBar extends Composite implements ClickListener {
|
|
|
51 |
|
|
|
52 |
public final DockPanel bar = new DockPanel();
|
|
|
53 |
|
|
|
54 |
public final Button gotoFirst = new Button("<<", this);
|
|
|
55 |
|
|
|
56 |
public final Button gotoNext = new Button(">", this);
|
|
|
57 |
|
|
|
58 |
public final Button gotoPrev = new Button("<", this);
|
|
|
59 |
|
|
|
60 |
public final Button gotoEnd = new Button(">>", this);
|
|
|
61 |
|
|
|
62 |
public final HTML status = new HTML();
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
public NavBar() {
|
|
|
66 |
initWidget(bar);
|
|
|
67 |
bar.setStyleName("navbar");
|
|
|
68 |
status.setStyleName("status");
|
|
|
69 |
status.setWordWrap(false);
|
|
|
70 |
|
|
|
71 |
HorizontalPanel buttons = new HorizontalPanel();
|
|
|
72 |
|
|
|
73 |
buttons.add(status);
|
|
|
74 |
buttons.setCellHorizontalAlignment(status,
|
|
|
75 |
HasHorizontalAlignment.ALIGN_RIGHT);
|
|
|
76 |
buttons.setCellVerticalAlignment(status,
|
|
|
77 |
HasVerticalAlignment.ALIGN_MIDDLE);
|
|
|
78 |
buttons.setCellWidth(status, "100%");
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
buttons.add(gotoFirst);
|
|
|
82 |
buttons.add(gotoPrev);
|
|
|
83 |
buttons.add(gotoNext);
|
|
|
84 |
buttons.add(gotoEnd);
|
|
|
85 |
bar.add(buttons, DockPanel.EAST);
|
|
|
86 |
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_LEFT);
|
|
|
90 |
|
|
|
91 |
bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
public void onClick(Widget sender) {
|
|
|
100 |
if (sender == gotoNext) {
|
|
|
101 |
// Move forward a page.
|
|
|
102 |
startIndex += VISIBLE_STATION_COUNT;
|
|
|
103 |
if (startIndex >= count)
|
|
|
104 |
startIndex -= VISIBLE_STATION_COUNT;
|
|
|
105 |
} else {
|
|
|
106 |
if (sender == gotoPrev) {
|
|
|
107 |
// Move back a page.
|
|
|
108 |
startIndex -= VISIBLE_STATION_COUNT;
|
|
|
109 |
if (startIndex < 0)
|
|
|
110 |
startIndex = 0;
|
|
|
111 |
} else {
|
|
|
112 |
if (sender == gotoEnd) {
|
|
|
113 |
gotoEnd();
|
|
|
114 |
} else {
|
|
|
115 |
if (sender == gotoFirst) {
|
|
|
116 |
startIndex = 0;
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
update();
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
private static final int VISIBLE_STATION_COUNT = 10;
|
|
|
127 |
private static final String VALUE_UNKNOWN = "Inconnues";
|
|
|
128 |
|
|
|
129 |
private Grid header = new Grid(1, 2);
|
|
|
130 |
|
|
|
131 |
private Grid selector = new Grid(1, 2);
|
|
|
132 |
|
|
|
133 |
private FlexTable table = new FlexTable();
|
|
|
134 |
|
|
|
135 |
private VerticalPanel outer = new VerticalPanel();
|
|
|
136 |
private VerticalPanel inner = new VerticalPanel();
|
|
|
137 |
|
|
|
138 |
private int startIndex = 0;
|
|
|
139 |
|
|
|
140 |
private String user;
|
|
|
141 |
|
|
|
142 |
private String serviceBaseUrl = null;
|
|
|
143 |
|
|
|
144 |
private String location = "all";
|
|
|
145 |
private String station = "all";
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
private NavBar navBar=null;
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
private int count = 65000;
|
|
|
152 |
|
|
|
153 |
// Tous selectionné
|
|
|
154 |
private int selectedRow = -1;
|
|
|
155 |
|
|
|
156 |
private Mediator mediator = null;
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
public StationList(Mediator med) {
|
|
|
160 |
|
|
|
161 |
mediator=med;
|
|
|
162 |
|
|
|
163 |
mediator.registerStationList(this);
|
|
|
164 |
|
|
|
165 |
user=mediator.getUser();
|
|
|
166 |
serviceBaseUrl = mediator.getServiceBaseUrl();
|
|
|
167 |
|
|
|
168 |
navBar = new NavBar();
|
|
|
169 |
|
|
|
170 |
// Mise en forme du header
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
header.setCellSpacing(0);
|
|
|
175 |
header.setCellPadding(2);
|
|
|
176 |
header.setWidth("100%");
|
|
|
177 |
|
|
|
178 |
header.setStyleName("station-ListHeader");
|
|
|
179 |
header.setWidget(0, 1,navBar);
|
|
|
180 |
|
|
|
181 |
selector.setCellSpacing(0);
|
|
|
182 |
selector.setCellPadding(0);
|
|
|
183 |
selector.setWidth("100%");
|
|
|
184 |
|
|
|
185 |
selector.setHTML(0, 0, "Toutes");
|
|
|
186 |
|
|
|
187 |
selector.getCellFormatter().setWidth(0, 0, "100%");
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
// Hook up events.
|
|
|
191 |
selector.addTableListener(new TableListener () {
|
|
|
192 |
|
|
|
193 |
public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
|
|
|
194 |
styleRow(selectedRow, false);
|
|
|
195 |
selector.getRowFormatter().addStyleName(0, "station-SelectedRow");
|
|
|
196 |
mediator.onStationSelected("all");
|
|
|
197 |
station="all";
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
});
|
|
|
201 |
|
|
|
202 |
selector.setStyleName("station-ListElement");
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
// Mise en forme du contenu
|
|
|
206 |
|
|
|
207 |
table.setCellSpacing(0);
|
|
|
208 |
table.setBorderWidth(0);
|
|
|
209 |
table.setCellPadding(2);
|
|
|
210 |
table.setWidth("100%");
|
|
|
211 |
|
|
|
212 |
table.setStyleName("station-ListElement");
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
outer.add(header);
|
|
|
216 |
inner.add(selector); // Toutes station
|
|
|
217 |
inner.add(table);
|
|
|
218 |
inner.setStyleName("station-List");
|
|
|
219 |
inner.setWidth("100%");
|
|
|
220 |
outer.setWidth("100%");
|
|
|
221 |
outer.add(inner);
|
|
|
222 |
|
|
|
223 |
// Hook up events.
|
|
|
224 |
table.addTableListener(new TableListener () {
|
|
|
225 |
|
|
|
226 |
public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
|
|
|
227 |
|
|
|
228 |
selectRow(row);
|
|
|
229 |
String astation=table.getText(row,cell);
|
|
|
230 |
|
|
|
231 |
if (astation.compareTo(VALUE_UNKNOWN)!=0) {
|
|
|
232 |
station=astation;
|
|
|
233 |
mediator.onStationSelected(astation);
|
|
|
234 |
}
|
|
|
235 |
else {
|
|
|
236 |
station="000null";
|
|
|
237 |
mediator.onStationSelected("000null");
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
});
|
|
|
244 |
|
|
|
245 |
styleRow(selectedRow, false);
|
|
|
246 |
selector.getRowFormatter().addStyleName(0, "station-SelectedRow");
|
|
|
247 |
|
|
|
248 |
initWidget(outer);
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
/**
|
|
|
254 |
* Recherche nombre d'enregistrement pour l'utilisateur en cours
|
|
|
255 |
*
|
|
|
256 |
*
|
|
|
257 |
*/
|
|
|
258 |
|
|
|
259 |
public void updateCount() {
|
|
|
260 |
|
|
|
261 |
setStatusDisabled();
|
|
|
262 |
|
|
|
263 |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryStationList/" + user + "/" + location ,
|
|
|
264 |
new ResponseTextHandler() {
|
|
|
265 |
|
|
|
266 |
public void onCompletion(String str) {
|
|
|
267 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
268 |
JSONNumber jsonNumber;
|
|
|
269 |
if ((jsonNumber = jsonValue.isNumber()) != null) {
|
|
|
270 |
count = (int) jsonNumber.getValue();
|
|
|
271 |
update();
|
|
|
272 |
}
|
|
|
273 |
}
|
|
|
274 |
});
|
|
|
275 |
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
private void selectRow(int row) {
|
|
|
280 |
|
|
|
281 |
styleRow(selectedRow, false);
|
|
|
282 |
styleRow(row, true);
|
|
|
283 |
|
|
|
284 |
selectedRow = row;
|
|
|
285 |
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
private void styleRow(int row, boolean selected) {
|
|
|
290 |
if (row != -1) {
|
|
|
291 |
selector.getRowFormatter().removeStyleName(0, "station-SelectedRow");
|
|
|
292 |
if (selected)
|
|
|
293 |
table.getRowFormatter().addStyleName(row, "station-SelectedRow");
|
|
|
294 |
else
|
|
|
295 |
if (row < table.getRowCount()) {
|
|
|
296 |
table.getRowFormatter().removeStyleName(row, "station-SelectedRow");
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
/**
|
|
|
303 |
*
|
|
|
304 |
* Mise a jour de l'affichage, à partir des données d'inventaire deja
|
|
|
305 |
* saisies. La valeur de this.startIndex permet de determiner quelles
|
|
|
306 |
* données seront affichées
|
|
|
307 |
*
|
|
|
308 |
*/
|
|
|
309 |
|
|
|
310 |
public void update() {
|
|
|
311 |
|
|
|
312 |
|
|
|
313 |
setStatusDisabled();
|
|
|
314 |
|
|
|
315 |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryStationList/" + user + "/" + location + "/"
|
|
|
316 |
+ startIndex + "/" + VISIBLE_STATION_COUNT,
|
|
|
317 |
|
|
|
318 |
new ResponseTextHandler() {
|
|
|
319 |
|
|
|
320 |
public void onCompletion(String str) {
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
JSONValue jsonValue = JSONParser.parse(str);
|
|
|
325 |
JSONArray jsonArray;
|
|
|
326 |
JSONArray jsonArrayNested;
|
|
|
327 |
|
|
|
328 |
int row=0;
|
|
|
329 |
int i=0;
|
|
|
330 |
|
|
|
331 |
if ((jsonArray = jsonValue.isArray()) != null) {
|
|
|
332 |
int arraySize = jsonArray.size();
|
|
|
333 |
for (i = 0; i < arraySize; ++i) {
|
|
|
334 |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
|
|
|
335 |
if (i>=table.getRowCount()) {
|
|
|
336 |
row = table.insertRow(table.getRowCount());
|
|
|
337 |
}
|
|
|
338 |
else {
|
|
|
339 |
row = i;
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
String astation=((JSONString)jsonArrayNested.get(0)).stringValue();
|
|
|
343 |
|
|
|
344 |
if (astation.compareTo("000null")!=0) {
|
|
|
345 |
table.setText(row, 0,astation);
|
|
|
346 |
}
|
|
|
347 |
else {
|
|
|
348 |
table.setText(row, 0,VALUE_UNKNOWN);
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
if (astation.compareTo(station)==0) {
|
|
|
352 |
styleRow(row, true);
|
|
|
353 |
}
|
|
|
354 |
else {
|
|
|
355 |
styleRow(row, false);
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
table.getFlexCellFormatter().setWidth(row, 0, "100%");
|
|
|
359 |
|
|
|
360 |
}
|
|
|
361 |
|
|
|
362 |
}
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
if (station.compareTo("all")==0) {
|
|
|
366 |
selector.getRowFormatter().addStyleName(0, "station-SelectedRow");
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
|
|
|
370 |
// Suppression fin ancien affichage
|
|
|
371 |
if (i<table.getRowCount()) {
|
|
|
372 |
for (int j = table.getRowCount() -1 ; j >= i; j--) {
|
|
|
373 |
table.removeRow(j);
|
|
|
374 |
}
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
setStatusEnabled();
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
}
|
|
|
381 |
});
|
|
|
382 |
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
public void setLocation(String location) {
|
|
|
386 |
this.location = location;
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
/*
|
|
|
392 |
* Positionnement index de parcours (this.startIndex) pour affichage de la
|
|
|
393 |
* dernière page
|
|
|
394 |
*
|
|
|
395 |
* @param
|
|
|
396 |
* @return void
|
|
|
397 |
*/
|
|
|
398 |
|
|
|
399 |
private void gotoEnd() {
|
|
|
400 |
|
|
|
401 |
if ((count == 0) || (count % VISIBLE_STATION_COUNT) > 0) {
|
|
|
402 |
startIndex = count - (count % VISIBLE_STATION_COUNT);
|
|
|
403 |
} else {
|
|
|
404 |
startIndex = count - VISIBLE_STATION_COUNT;
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
}
|
|
|
408 |
|
|
|
409 |
|
|
|
410 |
/**
|
|
|
411 |
* Affichage message d'attente et désactivation navigation
|
|
|
412 |
*
|
|
|
413 |
* @param
|
|
|
414 |
* @return void
|
|
|
415 |
*/
|
|
|
416 |
|
|
|
417 |
private void setStatusDisabled() {
|
|
|
418 |
|
|
|
419 |
navBar.gotoFirst.setEnabled(false);
|
|
|
420 |
navBar.gotoPrev.setEnabled(false);
|
|
|
421 |
navBar.gotoNext.setEnabled(false);
|
|
|
422 |
navBar.gotoEnd.setEnabled(false);
|
|
|
423 |
|
|
|
424 |
setStatusText("Patientez ...");
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
/**
|
|
|
428 |
* Affichage numero de page et gestion de la navigation
|
|
|
429 |
*
|
|
|
430 |
*/
|
|
|
431 |
|
|
|
432 |
private void setStatusEnabled() {
|
|
|
433 |
|
|
|
434 |
// Il y a forcemment un disabled avant d'arriver ici
|
|
|
435 |
|
|
|
436 |
if (count > 0) {
|
|
|
437 |
|
|
|
438 |
if (startIndex >= VISIBLE_STATION_COUNT) { // Au dela de la
|
|
|
439 |
// premiere page
|
|
|
440 |
navBar.gotoPrev.setEnabled(true);
|
|
|
441 |
navBar.gotoFirst.setEnabled(true);
|
|
|
442 |
if (startIndex < (count - VISIBLE_STATION_COUNT)) { // Pas la
|
|
|
443 |
// derniere
|
|
|
444 |
// page
|
|
|
445 |
navBar.gotoNext.setEnabled(true);
|
|
|
446 |
navBar.gotoEnd.setEnabled(true);
|
|
|
447 |
setStatusText((startIndex + 1) + " - "
|
|
|
448 |
+ (startIndex + VISIBLE_STATION_COUNT) + " sur " + count );
|
|
|
449 |
} else { // Derniere page
|
|
|
450 |
setStatusText((startIndex + 1) + " - " + count + " sur " + count );
|
|
|
451 |
}
|
|
|
452 |
} else { // Premiere page
|
|
|
453 |
if (count > VISIBLE_STATION_COUNT) { // Des pages derrieres
|
|
|
454 |
navBar.gotoNext.setEnabled(true);
|
|
|
455 |
navBar.gotoEnd.setEnabled(true);
|
|
|
456 |
setStatusText((startIndex + 1) + " - "
|
|
|
457 |
+ (startIndex + VISIBLE_STATION_COUNT) + " sur " + count);
|
|
|
458 |
} else {
|
|
|
459 |
setStatusText((startIndex + 1) + " - " + count + " sur " + count);
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
else { // Pas d'inventaire, pas de navigation
|
|
|
465 |
setStatusText("0 - 0 sur 0");
|
|
|
466 |
}
|
|
|
467 |
}
|
|
|
468 |
|
|
|
469 |
|
|
|
470 |
|
|
|
471 |
private void setStatusText(String text) {
|
|
|
472 |
navBar.status.setText(text);
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
public void setUser(String user) {
|
|
|
477 |
this.user = user;
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
|
|
|
481 |
|
|
|
482 |
public void setStation(String station) {
|
|
|
483 |
this.station = station;
|
|
|
484 |
}
|
|
|
485 |
|
|
|
486 |
|
|
|
487 |
}
|