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