Subversion Repositories eFlore/Archives.cel-v1

Rev

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