Subversion Repositories eFlore/Archives.cel-v1

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 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
import java.util.Iterator;
19
import java.util.Vector;
20
 
21
import com.google.gwt.json.client.JSONArray;
22
import com.google.gwt.json.client.JSONNumber;
23
import com.google.gwt.json.client.JSONParser;
24
import com.google.gwt.json.client.JSONString;
25
import com.google.gwt.json.client.JSONValue;
26
import com.google.gwt.user.client.HTTPRequest;
27
import com.google.gwt.user.client.ResponseTextHandler;
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.HorizontalPanel;
14 ddelon 33
import com.google.gwt.user.client.ui.Image;
13 ddelon 34
import com.google.gwt.user.client.ui.SourcesTableEvents;
35
import com.google.gwt.user.client.ui.TableListener;
11 ddelon 36
import com.google.gwt.user.client.ui.VerticalPanel;
37
import com.google.gwt.user.client.ui.DockPanel;
38
import com.google.gwt.user.client.ui.Button;
39
import com.google.gwt.user.client.ui.CheckBox;
40
import com.google.gwt.user.client.ui.Widget;
41
import com.google.gwt.user.client.ui.ClickListener;
42
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
43
import com.google.gwt.user.client.ui.HasVerticalAlignment;
44
 
45
/*
46
 * Le retour de getUser appelle updateCount qui appelle update pour veiller à une
47
 * initialisation correcte
48
 *
49
 */
50
 
51
public class InventoryItemList extends Composite implements
52
		AutoCompleteAsyncTextBoxListener {
53
 
54
	// Barre de navigation
55
 
56
	private class NavBar extends Composite implements ClickListener {
57
 
58
		public final DockPanel bar = new DockPanel();
59
 
60
		public final Button gotoFirst = new Button("<<", this);
61
 
62
		public final Button gotoNext = new Button(">", this);
63
 
64
		public final Button gotoPrev = new Button("<", this);
65
 
66
		public final Button gotoEnd = new Button(">>", this);
12 ddelon 67
 
68
 
11 ddelon 69
		public final HTML status = new HTML();
70
 
71
 
72
		public NavBar() {
12 ddelon 73
 
74
 
11 ddelon 75
			initWidget(bar);
76
			bar.setStyleName("navbar");
77
			status.setStyleName("status");
78
 
79
			HorizontalPanel buttons = new HorizontalPanel();
80
 
81
			buttons.add(status);
82
			buttons.setCellHorizontalAlignment(status,
83
					HasHorizontalAlignment.ALIGN_RIGHT);
84
			buttons.setCellVerticalAlignment(status,
85
					HasVerticalAlignment.ALIGN_MIDDLE);
86
			buttons.setCellWidth(status, "100%");
87
 
88
 
89
			buttons.add(gotoFirst);
90
			buttons.add(gotoPrev);
91
			buttons.add(gotoNext);
92
			buttons.add(gotoEnd);
93
			bar.add(buttons, DockPanel.EAST);
94
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
95
 
96
 
97
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_LEFT);
98
 
99
			bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
100
 
101
 
102
		}
12 ddelon 103
 
104
 
11 ddelon 105
 
106
		public void onClick(Widget sender) {
107
			if (sender == gotoNext) {
108
				// Move forward a page.
109
				startIndex += VISIBLE_TAXON_COUNT;
110
				if (startIndex >= count)
111
					startIndex -= VISIBLE_TAXON_COUNT;
112
			} else {
113
				if (sender == gotoPrev) {
114
					// Move back a page.
115
					startIndex -= VISIBLE_TAXON_COUNT;
116
					if (startIndex < 0)
117
						startIndex = 0;
118
				} else {
119
					if (sender == gotoEnd) {
120
						gotoEnd();
121
					} else {
122
						if (sender == gotoFirst) {
123
							startIndex = 0;
124
						}
125
					}
126
				}
127
			}
128
			update();
129
		}
130
 
131
	}
132
 
133
	private void setStatusText(String text) {
134
		navBar.status.setText(text);
135
	}
136
 
137
	private static final int VISIBLE_TAXON_COUNT = 15;
138
 
13 ddelon 139
	private Grid header = new Grid(1, 3);
11 ddelon 140
 
141
	private FlexTable table = new FlexTable();
142
 
143
	private VerticalPanel panel = new VerticalPanel();
144
 
145
	private int startIndex = 0;
146
 
147
	private String serviceBaseUrl = null;
148
 
149
	private int count = 65000;
150
 
151
	private String user;
152
 
153
	private NavBar navBar=null;
154
 
155
	private Mediator mediator = null;
156
 
13 ddelon 157
	private int  selectedRow = -1;
158
 
11 ddelon 159
	private String location = "all";
12 ddelon 160
	private String date = "all";
13 ddelon 161
	private String search = "all";
14 ddelon 162
	private String station = "all";
13 ddelon 163
 
11 ddelon 164
	public InventoryItemList(Mediator med) {
165
 
166
		mediator=med;
167
 
168
	    mediator.registerInventoryItemList(this);
169
 
170
		user=mediator.getUser();
171
	    serviceBaseUrl = mediator.getServiceBaseUrl();
172
 
173
		navBar = new NavBar();
174
 
175
 
176
		// Information complementaire : un tableau associe au retour de
177
		// l'assistant de saisie
178
 
179
		// Mise en forme du header
180
 
181
		header.setCellSpacing(0);
182
		header.setCellPadding(2);
183
		header.setWidth("100%");
184
 
12 ddelon 185
		header.setStyleName("inventoryItem-ListHeader");
11 ddelon 186
 
13 ddelon 187
		header.setWidget(0, 2, navBar);
11 ddelon 188
 
189
		// Mise en forme de la table.
190
 
191
		table.setCellSpacing(0);
192
		table.setBorderWidth(0);
193
		table.setCellPadding(2);
194
		table.setWidth("100%");
13 ddelon 195
 
11 ddelon 196
 
197
		// Mise en forme barre navigation
198
 
199
		navBar.setWidth("100%");
200
 
12 ddelon 201
		table.setStyleName("inventoryItem-List");
11 ddelon 202
 
13 ddelon 203
		//panel.add(navBar);
11 ddelon 204
		panel.add(header);
205
		panel.add(table);
206
 
13 ddelon 207
 
208
		 // Hook up events.
209
	    table.addTableListener(new TableListener () {
210
 
211
			  public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
212
 
24 ddelon 213
				  if ((table.getWidget(row, 0)!=null) && (cell>0)){
13 ddelon 214
				      selectRow(row);
215
				      // Numero d'ordre
14 ddelon 216
				      mediator.onInventoryItemSelected(table.getText(row, 5));
13 ddelon 217
				  }
218
			  }
219
 
220
	    });
221
 
222
 
12 ddelon 223
		//updateCount();
11 ddelon 224
		// update()
225
 
226
 
227
		initWidget(panel);
228
 
229
 
230
	}
12 ddelon 231
 
232
 
13 ddelon 233
 
234
	  private void selectRow(int row) {
235
 
236
		    styleRow(selectedRow, false);
237
		    styleRow(row, true);
11 ddelon 238
 
13 ddelon 239
		    selectedRow = row;
240
 
241
		  }
242
 
243
 
244
		  private void styleRow(int row, boolean selected) {
245
			    if (row != -1) {
246
			      if (selected)
247
			        table.getRowFormatter().addStyleName(row, "inventoryItem-SelectedRow");
248
			      else
249
			    	if (row < table.getRowCount()) {
250
			    		table.getRowFormatter().removeStyleName(row, "inventoryItem-SelectedRow");
251
			    	}
252
			    }
253
			  }
254
 
255
 
12 ddelon 256
 
257
 
11 ddelon 258
	/**
259
	 * Action lancee par la selection d'un nom dans l'assistant de saisie. Lance
260
	 * la recherche d'informations complémentaires (famille, numero
261
	 * nomenclaturaux etc) et met a jour l'inventaire (addelement())
262
	 *
263
	 * @return void
264
	 */
265
	public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,
266
			  String str, String value) {
267
 
12 ddelon 268
 
269
	mediator.onAddInventoryItem();
11 ddelon 270
 
12 ddelon 271
	}
11 ddelon 272
 
13 ddelon 273
 
274
	// Action sur modification d'un element
12 ddelon 275
 
13 ddelon 276
 
277
	public void updateElement() {
278
 
279
 
280
	if (mediator.inventoryItemIsValid()) {
281
 
282
		final InventoryItem inventoryItem=mediator.getInventoryItem();
283
 
284
		setStatusDisabled();
285
 
286
				if (inventoryItem.getNomenclaturalNumber() !=null) {
287
 
288
					HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + inventoryItem.getNomenclaturalNumber(),
289
							new ResponseTextHandler() {
290
 
291
								public void onCompletion(String strcomplete) {
292
 
293
									JSONValue jsonValue = JSONParser.parse(strcomplete);
294
									JSONArray jsonArray;
295
 
296
									if ((jsonArray = jsonValue.isArray()) != null) {
297
										// Nom retenu, Num Nomen nom retenu, Num Taxon,
298
										// Famille
299
										updateElement(inventoryItem.getOrdre(),inventoryItem.getName(), inventoryItem.getNomenclaturalNumber(),
300
												((JSONString) jsonArray.get(0))
301
														.stringValue(),
302
												((JSONString) jsonArray.get(1))
303
														.stringValue(),
304
												((JSONString) jsonArray.get(2))
305
														.stringValue(),
306
												((JSONString) jsonArray.get(3))
307
														.stringValue(),
308
														inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getComplementlocation(),inventoryItem.getComment());
309
									}
310
								}
311
 
312
							});
313
				}
314
				// Saisie libre
315
				else {
316
					updateElement(inventoryItem.getOrdre(),inventoryItem.getName(), " ", " ", " ", " ", " ",inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getComplementlocation(),inventoryItem.getComment());
317
				}
318
 
319
		}
320
	else {
321
		return;
322
	}
323
	}
324
 
325
 
326
 
327
	// Action sur ajout d'un element
328
 
329
 
12 ddelon 330
	public void addelement() {
331
 
332
 
333
	if (mediator.inventoryItemIsValid()) {
334
 
335
		final InventoryItem inventoryItem=mediator.getInventoryItem();
336
 
337
		setStatusDisabled();
11 ddelon 338
 
339
				// On met a jour rapidement l'affichage puis on lance la requete  ....
340
 
341
		/*		int row = table.insertRow(table.getRowCount());
342
				// Case a cocher
343
				table.setWidget(row, 0, new CheckBox());
344
				// Nom saisi
345
				table.setText(row, 1, nameText);
346
 
347
				table.getFlexCellFormatter().setWidth(row, 0, "2%");
348
				table.getFlexCellFormatter()
349
						.setWidth(row, 1, "31%");*/
350
 
351
				// Recherche complement d'information
352
 
12 ddelon 353
				if (inventoryItem.getNomenclaturalNumber() !=null) {
11 ddelon 354
 
12 ddelon 355
					HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + inventoryItem.getNomenclaturalNumber(),
11 ddelon 356
							new ResponseTextHandler() {
357
 
358
								public void onCompletion(String strcomplete) {
359
 
360
									JSONValue jsonValue = JSONParser.parse(strcomplete);
361
									JSONArray jsonArray;
362
 
363
									if ((jsonArray = jsonValue.isArray()) != null) {
364
										// Nom retenu, Num Nomen nom retenu, Num Taxon,
365
										// Famille
12 ddelon 366
										addElement(inventoryItem.getName(), inventoryItem.getNomenclaturalNumber(),
11 ddelon 367
												((JSONString) jsonArray.get(0))
368
														.stringValue(),
369
												((JSONString) jsonArray.get(1))
370
														.stringValue(),
371
												((JSONString) jsonArray.get(2))
372
														.stringValue(),
373
												((JSONString) jsonArray.get(3))
374
														.stringValue(),
12 ddelon 375
														inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getComplementlocation(),inventoryItem.getComment());
11 ddelon 376
									}
377
								}
378
 
379
							});
380
				}
381
				// Saisie libre
382
				else {
12 ddelon 383
					addElement(inventoryItem.getName(), " ", " ", " ", " ", " ",inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getComplementlocation(),inventoryItem.getComment());
11 ddelon 384
				}
385
 
12 ddelon 386
		}
387
	else {
388
		return;
11 ddelon 389
	}
12 ddelon 390
	}
11 ddelon 391
 
392
	/**
393
	 * Ajoute un element à l'inventaire
394
	 *
395
	 * @param nom_sel :
396
	 *            nom selectionne
397
	 * @param num_nom_sel :
398
	 *            numero nomenclatural nom selectionne
399
	 * @param nom_ret :
400
	 *            nom retenu
401
	 * @param num_nom_ret :
402
	 *            numero nomenclaturel nom retenu
403
	 * @param num_taxon :
404
	 *            numero taxonomique
405
	 * @param famille :
406
	 *            famille
407
	 */
408
 
12 ddelon 409
	private void addElement(String nom_sel, String num_nom_sel, String nom_ret,
410
			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String complementLocation, String comment) {
11 ddelon 411
 
412
 
413
		count++;
414
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
415
				+ user + "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
416
				+ "&nom_ret=" + nom_ret + "&num_nom_ret=" + num_nom_ret
12 ddelon 417
				+ "&num_taxon=" + num_taxon + "&famille=" + famille + "&location=" + loc + "&id_location=" + id_location + "&date_observation=" + dat
418
				+ "&station="+ complementLocation + "&commentaire="+ comment,
11 ddelon 419
 
420
		new ResponseTextHandler() {
421
 
422
			public void onCompletion(String str) {
423
					location=loc;
12 ddelon 424
					if (location.compareTo("")==0) {
425
						location="000null";
426
					}
14 ddelon 427
					mediator.onInventoryUpdated(location);
11 ddelon 428
					updateCount();
429
			}
430
		});
431
	}
432
 
13 ddelon 433
 
434
 
11 ddelon 435
	/**
13 ddelon 436
	 * Modifie un element de l'inventaire
437
	 *
438
	 * @param ordre : numero d'ordre
439
	 * @param nom_sel :
440
	 *            nom selectionne
441
	 * @param num_nom_sel :
442
	 *            numero nomenclatural nom selectionne
443
	 * @param nom_ret :
444
	 *            nom retenu
445
	 * @param num_nom_ret :
446
	 *            numero nomenclaturel nom retenu
447
	 * @param num_taxon :
448
	 *            numero taxonomique
449
	 * @param famille :
450
	 *            famille
451
	 */
452
 
453
	private void updateElement(String ordre, String nom_sel, String num_nom_sel, String nom_ret,
454
			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String complementLocation, String comment) {
455
 
456
 
14 ddelon 457
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user + "/" +ordre + "/",
458
				 "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
13 ddelon 459
				+ "&nom_ret=" + nom_ret + "&num_nom_ret=" + num_nom_ret
460
				+ "&num_taxon=" + num_taxon + "&famille=" + famille + "&location=" + loc + "&id_location=" + id_location + "&date_observation=" + dat
461
				+ "&station="+ complementLocation + "&commentaire="+ comment,
462
 
463
		new ResponseTextHandler() {
464
 
465
			public void onCompletion(String str) {
14 ddelon 466
				mediator.onInventoryUpdated(location);
13 ddelon 467
				update();
468
			}
469
		});
470
	}
471
 
14 ddelon 472
	/**
473
	 * Transmission de releve à Tela
474
	 *
475
	 */
476
 
13 ddelon 477
 
14 ddelon 478
 
479
	public void transmitElement() {
480
 
481
		setStatusDisabled();
482
		Vector parseChecked = new Vector();
483
 
484
		// TODO : optimiser
485
		// Lifo ...
486
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
487
			 if (table.getWidget(i, 0)!=null) {
488
				 if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
489
					 // Numero ordre
490
					 parseChecked.add(table.getText(i, 5));
491
				 }
492
			 }
493
		}
494
		StringBuffer ids=new StringBuffer();
495
		for (Iterator it = parseChecked.iterator(); it.hasNext();) {
496
			ids.append((String)it.next());
497
			if (it.hasNext()) ids.append(",");
498
		}
499
 
500
		if (ids.length()>0) {
501
 
502
			HTTPRequest.asyncPost(serviceBaseUrl + "/InventoryTransmit/" + user
503
							+ "/" + ids.toString(), "transmission=1",
504
 
505
							new ResponseTextHandler() {
506
								public void onCompletion(String str) {
507
											update();
508
								}
509
							});
510
		}
511
 
512
		setStatusEnabled();
513
 
514
 
515
	}
516
 
517
 
13 ddelon 518
	/**
11 ddelon 519
	 * Suppression d'un element lde l'inventaire, a partir de son numero d'ordre
520
	 *
521
	 */
522
 
523
	public void deleteElement() {
524
 
525
		setStatusDisabled();
526
		Vector parseChecked = new Vector();
527
 
12 ddelon 528
		// TODO : optimiser
11 ddelon 529
		// Lifo ...
530
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
12 ddelon 531
			 if (table.getWidget(i, 0)!=null) {
532
				 if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
533
					 // Numero ordre
14 ddelon 534
					 parseChecked.add(table.getText(i, 5));
12 ddelon 535
					 count--;
536
				 }
537
			 }
11 ddelon 538
		}
12 ddelon 539
		StringBuffer ids=new StringBuffer();
11 ddelon 540
		for (Iterator it = parseChecked.iterator(); it.hasNext();) {
12 ddelon 541
			ids.append((String)it.next());
542
			if (it.hasNext()) ids.append(",");
543
		}
14 ddelon 544
		if (ids.length()>0) {
545
 
546
			HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
547
							+ "/" + ids.toString(), "action=DELETE",
548
 
549
							new ResponseTextHandler() {
550
								public void onCompletion(String str) {
551
											mediator.onInventoryUpdated("all");
552
											updateCount();
553
								}
554
							});
11 ddelon 555
		}
14 ddelon 556
 
557
		setStatusEnabled();
11 ddelon 558
	}
559
 
560
	/**
561
	 * Selection de l'ensemble des elements affichés
562
	 *
563
	 */
564
 
565
	public void selectAll() {
566
 
12 ddelon 567
		// TODO : optimiser ...
11 ddelon 568
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
12 ddelon 569
			 if (table.getWidget(i, 0)!=null)
11 ddelon 570
			 ((CheckBox) table.getWidget(i, 0)).setChecked(true);
571
		}
572
	}
573
 
574
	public void deselectAll() {
575
 
12 ddelon 576
		// TODO : optimiser ...
11 ddelon 577
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
12 ddelon 578
			 if (table.getWidget(i, 0)!=null)
11 ddelon 579
			((CheckBox) table.getWidget(i, 0)).setChecked(false);
580
		}
581
	}
582
 
583
 
584
 
585
	/**
586
	 * Recherche nombre d'enregistrement pour l'utilisateur et la localite en cours
587
	 *
588
	 */
13 ddelon 589
	public void updateCount	() {
11 ddelon 590
 
591
		setStatusDisabled();
12 ddelon 592
 
593
		String adate="all";
594
		if (date.compareTo("all")!=0) {
595
			adate=date.substring(6,10)+"-"+date.substring(3,5)+"-"+date.substring(0,2)+" 00:00:00";
596
		}
11 ddelon 597
 
14 ddelon 598
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + location + "/" + adate  + "/" + search +  "/" + station,
11 ddelon 599
				new ResponseTextHandler() {
600
 
601
					public void onCompletion(String str) {
602
 
603
						JSONValue jsonValue = JSONParser.parse(str);
604
						JSONNumber jsonNumber;
605
						if ((jsonNumber = jsonValue.isNumber()) != null) {
606
							count = (int) jsonNumber.getValue();
607
							/*
608
							if (count==0) {
609
								location="all";
610
							}
611
							*/
612
							if (location.compareTo("")==0)
613
								location="000null";
14 ddelon 614
						//	mediator.onInventoryItemUpdate(location);
11 ddelon 615
							gotoEnd(); // Derniere page
616
							update();
617
						}
618
					}
619
				});
620
 
621
	}
13 ddelon 622
 
623
 
624
	private String subLeft(String text, int length) {
625
		return (text.length() < length) ? text : text.substring(0, length)+ " ...";
626
	}
11 ddelon 627
 
628
	/**
629
	 * Mise a jour de l'affichage, à partir des données d'inventaire deja
630
	 * saisies. La valeur de this.startIndex permet de determiner quelles
631
	 * données seront affichées
632
	 *
633
	 *  @param deep : force une mise a jour totale
634
	 */
635
 
636
	public void update() {
637
 
13 ddelon 638
 
639
//		table.setBorderWidth(1);
11 ddelon 640
		setStatusDisabled();
641
 
12 ddelon 642
		String adate="all";
643
		if (date.compareTo("all")!=0) {
644
			adate=date.substring(6,10)+"-"+date.substring(3,5)+"-"+date.substring(0,2)+" 00:00:00";
645
		}
13 ddelon 646
 
647
 
648
		String com;
649
		if (location.compareTo("all")==0) {
650
			com="Toutes communes";
651
		}
652
		else {
653
			if (location.compareTo("000null")==0) {
14 ddelon 654
				com="Communes non renseign&eacute;es";
13 ddelon 655
			}
656
			else {
657
			com="Commune de "+location;
658
			}
659
		}
660
 
661
 
662
		String dat;
663
 
664
		if (date.compareTo("all")==0) {
14 ddelon 665
			dat=", toutes p&eacute;riodes";
13 ddelon 666
		}
667
		else {
668
			if (date.compareTo("00/00/0000")==0) {
14 ddelon 669
				dat=", p&eacute;riodes non renseign&eacute;es";
13 ddelon 670
			}
671
			else {
672
				dat=", le "+ date;
673
			}
674
		}
14 ddelon 675
 
13 ddelon 676
 
14 ddelon 677
		String stat;
13 ddelon 678
 
14 ddelon 679
		if (station.compareTo("all")==0) {
680
			stat=", toutes stations";
681
		}
682
		else {
683
			if (station.compareTo("000null")==0) {
684
				stat=", stations non renseign&eacute;es";
685
			}
686
			else {
687
				stat=", station "+ station;
688
			}
689
		}
690
 
691
 
692
		header.setHTML(0, 0, com +  dat + stat );
693
 
694
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + location +"/" + adate + "/" + search + "/" + station + "/"
11 ddelon 695
				+ startIndex + "/" + VISIBLE_TAXON_COUNT,
696
 
697
		new ResponseTextHandler() {
698
 
699
			public void onCompletion(String str) {
700
 
701
				JSONValue jsonValue = JSONParser.parse(str);
702
				JSONArray jsonArray;
703
				JSONArray jsonArrayNested;
13 ddelon 704
 
705
				StringBuffer left=new StringBuffer();
706
				StringBuffer center=new StringBuffer();
707
				StringBuffer right=new StringBuffer();
14 ddelon 708
 
709
 
11 ddelon 710
 
12 ddelon 711
 
11 ddelon 712
				int row=0;
713
				int i=0;
714
				if ((jsonArray = jsonValue.isArray()) != null) {
715
					int arraySize = jsonArray.size();
716
					for (i = 0; i < arraySize; ++i) {
717
						if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
718
							if (i>=table.getRowCount()) {
719
								 row = table.insertRow(table.getRowCount());
720
							}
721
							else {
722
								row = i;
723
							}
12 ddelon 724
 
13 ddelon 725
							left=new StringBuffer();
726
							center=new StringBuffer();
727
							right=new StringBuffer();
728
 
11 ddelon 729
							// Case a cocher
730
							table.setWidget(row, 0, new CheckBox());
14 ddelon 731
 
732
 
733
							// Observation transmise
734
 
735
 
736
							String atransmit=((JSONString) jsonArrayNested .get(11)).stringValue();
737
 
738
							if (atransmit.compareTo("1")==0) {
739
								table.setWidget(row,1,new Image("tela.gif"));
740
							}
741
							else {
742
								table.setWidget(row,1,new HTML("&nbsp;"));
743
							}
744
 
13 ddelon 745
							left.append("<b>"+((JSONString) jsonArrayNested .get(0)).stringValue()+"</b>");
12 ddelon 746
 
11 ddelon 747
							// Nom retenu
12 ddelon 748
							String aname=((JSONString) jsonArrayNested .get(2)).stringValue();
749
 
750
							if (aname.compareTo("null")==0) {
751
							}
752
							else {
13 ddelon 753
								center.append(aname+", ");
12 ddelon 754
							}
755
 
11 ddelon 756
							// Num nomenclatural
12 ddelon 757
							String ann=((JSONString) jsonArrayNested .get(3)).stringValue();
758
 
13 ddelon 759
							if (ann.compareTo("0")!=0) {
760
								center.append(""+ann+"-");
12 ddelon 761
							}
762
							else {
13 ddelon 763
								center.append("0-");
12 ddelon 764
							}
765
 
766
 
11 ddelon 767
							// Num Taxonomique
12 ddelon 768
 
769
							String ant=((JSONString) jsonArrayNested .get(4)).stringValue();
770
 
13 ddelon 771
							if (ant.compareTo("0")!=0) {
772
								center.append(ant+", ");
12 ddelon 773
							}
774
							else {
13 ddelon 775
								center.append("0, ");
12 ddelon 776
							}
777
 
11 ddelon 778
							// Famille
12 ddelon 779
							String afamily=((JSONString) jsonArrayNested .get(5)).stringValue();
780
 
781
							if (afamily.compareTo("null")==0) {
13 ddelon 782
								//
12 ddelon 783
							}
784
							else {
13 ddelon 785
								center.append(afamily+", ");
12 ddelon 786
							}
11 ddelon 787
 
788
 
13 ddelon 789
							String aloc=((JSONString) jsonArrayNested .get(6)).stringValue();
790
//								Localisation - Lieu
791
 
792
								if (aloc.compareTo("000null")==0) {
793
									if (center.length()==0) {
794
										center.append("Commune absente");
795
									}
796
									else {
797
										center.append("commune absente");
798
									}
799
								}
800
								else {
801
									if (center.length()==0) {
802
										center.append("Commune de "+aloc);
803
									}
804
									else {
805
										center.append("commune de "+aloc);
806
									}
807
 
808
								}
12 ddelon 809
 
13 ddelon 810
 
811
								String alieudit=((JSONString) jsonArrayNested .get(9)).stringValue();
12 ddelon 812
 
13 ddelon 813
//								Localisation - Lieu dit
814
 
14 ddelon 815
								if (alieudit.compareTo("000null")!=0) {
13 ddelon 816
									center.append(", "+alieudit);
817
								}
12 ddelon 818
 
13 ddelon 819
								String acomment=((JSONString) jsonArrayNested .get(10)).stringValue();
820
//								Commentaire
821
 
822
								if (acomment.compareTo("null")!=0) {
823
									center.append(", "+acomment);
824
								}
825
 
11 ddelon 826
 
13 ddelon 827
								String adate=((JSONString) jsonArrayNested .get(8)).stringValue();
828
 
829
//								Date
830
								if (adate.compareTo("0000-00-00 00:00:00")!=0) {
831
									right.append("<b>"+adate+"</b>");
11 ddelon 832
								}
833
								else {
13 ddelon 834
//									right.append("<b>00/00/0000</b>");
11 ddelon 835
								}
836
 
12 ddelon 837
 
14 ddelon 838
							table.setHTML(row, 2, subLeft("&nbsp;"+left,40));
839
							table.setHTML(row, 3, subLeft("&nbsp;"+center,120));
840
							table.setHTML(row, 4, subLeft("&nbsp;"+right,25));
12 ddelon 841
 
13 ddelon 842
							table.getRowFormatter().removeStyleName(row, "inventoryItem-SelectedRow");
843
 
844
 
14 ddelon 845
							table.getCellFormatter().setWidth(row,0,"2%");
846
							table.getCellFormatter().setWidth(row,1,"2%");
13 ddelon 847
							table.getCellFormatter().setWordWrap(row,2,false);
14 ddelon 848
							table.getCellFormatter().setWidth(row,2,"10%");
13 ddelon 849
							table.getCellFormatter().setWordWrap(row,3,false);
14 ddelon 850
							table.getCellFormatter().setWordWrap(row,4,false);
851
							table.getCellFormatter().setWidth(row,4,"7%");
13 ddelon 852
 
853
 
854
							String aordre=((JSONString) jsonArrayNested.get(7)).stringValue();
855
 
11 ddelon 856
							// Numero d'ordre (caché)
14 ddelon 857
 
858
 
859
							table.setText(row, 5, aordre);
11 ddelon 860
 
24 ddelon 861
							/*
13 ddelon 862
							if (add){
863
								if (i ==(arraySize -1)) {
864
									selectRow(row);
865
									mediator.getEntryPanel().setOrdre(aordre);
866
								}
867
 
868
							}
869
							else {
870
								if ((mediator.getEntryPanel().getOrdre()!=null) && (mediator.getEntryPanel().getOrdre().compareTo(aordre)==0)) {
871
									selectRow(row);
872
								}
873
							}
24 ddelon 874
							*/
11 ddelon 875
 
14 ddelon 876
							table.getCellFormatter().setVisible(row, 5, false);
13 ddelon 877
 
11 ddelon 878
 
879
						}
880
 
881
					}
882
				}
12 ddelon 883
 
884
 
11 ddelon 885
				// Suppression fin ancien affichage
13 ddelon 886
				for (int j=i;j<VISIBLE_TAXON_COUNT;j++) {
887
						 table.setHTML(j,0,"&nbsp;");
888
						 table.setHTML(j,1,"&nbsp;");
889
						 table.setHTML(j,2,"&nbsp;");
890
						 table.setHTML(j,3,"&nbsp;");
891
						 table.setHTML(j,4,"&nbsp;");
14 ddelon 892
						 table.setHTML(j,5,"&nbsp;");
893
						table.getCellFormatter().setVisible(j, 5, false);
13 ddelon 894
						table.getRowFormatter().removeStyleName(j, "inventoryItem-SelectedRow");
11 ddelon 895
				}
896
 
897
				setStatusEnabled();
898
 
13 ddelon 899
 
11 ddelon 900
			}
901
		});
13 ddelon 902
 
11 ddelon 903
 
904
	}
905
 
906
 
907
	/**
908
	 * Affichage message d'attente et désactivation navigation
909
	 *
910
	 * @param
911
	 * @return void
912
	 */
913
 
914
	private void setStatusDisabled() {
915
 
916
		navBar.gotoFirst.setEnabled(false);
917
		navBar.gotoPrev.setEnabled(false);
918
		navBar.gotoNext.setEnabled(false);
919
		navBar.gotoEnd.setEnabled(false);
920
 
921
		setStatusText("Patientez ...");
922
	}
923
 
924
	/**
925
	 * Affichage numero de page et gestion de la navigation
926
	 *
927
	 */
928
 
929
	private void setStatusEnabled() {
930
 
931
		// Il y a forcemment un disabled avant d'arriver ici
932
 
933
		if (count > 0) {
934
 
935
			if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la
936
														// premiere page
937
				navBar.gotoPrev.setEnabled(true);
938
				navBar.gotoFirst.setEnabled(true);
939
				if (startIndex < (count - VISIBLE_TAXON_COUNT)) { // Pas la
940
																	// derniere
941
																	// page
942
					navBar.gotoNext.setEnabled(true);
943
					navBar.gotoEnd.setEnabled(true);
944
					setStatusText((startIndex + 1) + " - "
945
							+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count );
946
				} else { // Derniere page
947
					setStatusText((startIndex + 1) + " - " + count + " sur " + count );
948
				}
949
			} else { // Premiere page
950
				if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
951
					navBar.gotoNext.setEnabled(true);
952
					navBar.gotoEnd.setEnabled(true);
953
					setStatusText((startIndex + 1) + " - "
954
							+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count);
955
				} else {
956
					setStatusText((startIndex + 1) + " - " + count + " sur " + count);
957
				}
958
			}
959
		}
960
 
961
		else { // Pas d'inventaire, pas de navigation
962
			setStatusText("0 - 0 sur 0");
963
		}
964
	}
965
 
966
	/*
967
	 * Positionnement index de parcours (this.startIndex) pour affichage de la
968
	 * dernière page
969
	 *
970
	 * @param
971
	 * @return void
972
	 */
973
 
974
	private void gotoEnd() {
975
 
976
		if ((count == 0) || (count % VISIBLE_TAXON_COUNT) > 0) {
977
			startIndex = count - (count % VISIBLE_TAXON_COUNT);
978
		} else {
979
			startIndex = count - VISIBLE_TAXON_COUNT;
980
		}
981
 
982
	}
983
 
984
	/*
13 ddelon 985
	 * Recherche en cours
986
	 *
987
	 */
988
 
989
	public void setSearch(String search) {
990
		this.search = search;
991
	}
992
 
993
 
994
 
995
	/*
11 ddelon 996
	 * Localite en cours
997
	 *
998
	 */
999
 
1000
	public void setLocation(String location) {
1001
		this.location = location;
1002
	}
12 ddelon 1003
 
1004
 
1005
 
1006
	public void setDate(String date) {
1007
		this.date = date;
1008
	}
14 ddelon 1009
 
1010
 
1011
	public void setUser(String user) {
1012
		this.user = user;
1013
	}
11 ddelon 1014
 
14 ddelon 1015
 
1016
	public void setStation(String station) {
1017
		this.station = station;
1018
	}
1019
 
1020
 
11 ddelon 1021
 
1022
 
1023
 
1024
 
1025
 
1026
}