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