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