Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 12 | 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;
13 ddelon 33
import com.google.gwt.user.client.ui.SourcesTableEvents;
34
import com.google.gwt.user.client.ui.TableListener;
11 ddelon 35
import com.google.gwt.user.client.ui.VerticalPanel;
36
import com.google.gwt.user.client.ui.DockPanel;
37
import com.google.gwt.user.client.ui.Button;
38
import com.google.gwt.user.client.ui.CheckBox;
39
import com.google.gwt.user.client.ui.Widget;
40
import com.google.gwt.user.client.ui.ClickListener;
41
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
42
import com.google.gwt.user.client.ui.HasVerticalAlignment;
43
 
44
/*
45
 * Le retour de getUser appelle updateCount qui appelle update pour veiller à une
46
 * initialisation correcte
47
 *
48
 */
49
 
50
public class InventoryItemList extends Composite implements
51
		AutoCompleteAsyncTextBoxListener {
52
 
53
	// Barre de navigation
54
 
55
	private class NavBar extends Composite implements ClickListener {
56
 
57
		public final DockPanel bar = new DockPanel();
58
 
59
		public final Button gotoFirst = new Button("<<", this);
60
 
61
		public final Button gotoNext = new Button(">", this);
62
 
63
		public final Button gotoPrev = new Button("<", this);
64
 
65
		public final Button gotoEnd = new Button(">>", this);
12 ddelon 66
 
67
 
11 ddelon 68
		public final HTML status = new HTML();
69
 
70
 
71
		public NavBar() {
12 ddelon 72
 
73
 
11 ddelon 74
			initWidget(bar);
75
			bar.setStyleName("navbar");
76
			status.setStyleName("status");
77
 
78
			HorizontalPanel buttons = new HorizontalPanel();
79
 
80
			buttons.add(status);
81
			buttons.setCellHorizontalAlignment(status,
82
					HasHorizontalAlignment.ALIGN_RIGHT);
83
			buttons.setCellVerticalAlignment(status,
84
					HasVerticalAlignment.ALIGN_MIDDLE);
85
			buttons.setCellWidth(status, "100%");
86
 
87
 
88
			buttons.add(gotoFirst);
89
			buttons.add(gotoPrev);
90
			buttons.add(gotoNext);
91
			buttons.add(gotoEnd);
92
			bar.add(buttons, DockPanel.EAST);
93
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
94
 
95
 
96
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_LEFT);
97
 
98
			bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
99
 
100
 
101
		}
12 ddelon 102
 
103
 
11 ddelon 104
 
105
		public void onClick(Widget sender) {
106
			if (sender == gotoNext) {
107
				// Move forward a page.
108
				startIndex += VISIBLE_TAXON_COUNT;
109
				if (startIndex >= count)
110
					startIndex -= VISIBLE_TAXON_COUNT;
111
			} else {
112
				if (sender == gotoPrev) {
113
					// Move back a page.
114
					startIndex -= VISIBLE_TAXON_COUNT;
115
					if (startIndex < 0)
116
						startIndex = 0;
117
				} else {
118
					if (sender == gotoEnd) {
119
						gotoEnd();
120
					} else {
121
						if (sender == gotoFirst) {
122
							startIndex = 0;
123
						}
124
					}
125
				}
126
			}
127
			update();
128
		}
129
 
130
	}
131
 
132
	private void setStatusText(String text) {
133
		navBar.status.setText(text);
134
	}
135
 
136
	private static final int VISIBLE_TAXON_COUNT = 15;
137
 
13 ddelon 138
	private Grid header = new Grid(1, 3);
11 ddelon 139
 
140
	private FlexTable table = new FlexTable();
141
 
142
	private VerticalPanel panel = new VerticalPanel();
143
 
144
	private int startIndex = 0;
145
 
146
	private String serviceBaseUrl = null;
147
 
148
	private int count = 65000;
149
 
150
	private String user;
151
 
152
	private NavBar navBar=null;
153
 
154
	private Mediator mediator = null;
155
 
13 ddelon 156
	private int  selectedRow = -1;
157
 
11 ddelon 158
	private String location = "all";
12 ddelon 159
	private String date = "all";
13 ddelon 160
	private String search = "all";
161
 
162
	private boolean add=false;
11 ddelon 163
 
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
 
213
				  if (table.getWidget(row, 0)!=null) {
214
				      selectRow(row);
215
				      // Numero d'ordre
216
				      mediator.onInventoryItemSelected(table.getText(row, 4));
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
					}
13 ddelon 427
					add=true;
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
 
457
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" +ordre + "/", "identifiant="
458
				+ user + "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
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) {
466
				add=false;
467
				update();
468
			}
469
		});
470
	}
471
 
472
 
473
	/**
11 ddelon 474
	 * Suppression d'un element lde l'inventaire, a partir de son numero d'ordre
475
	 *
476
	 */
477
 
478
	public void deleteElement() {
479
 
480
		setStatusDisabled();
481
		boolean checked = false;
482
		Vector parseChecked = new Vector();
483
 
12 ddelon 484
		// TODO : optimiser
11 ddelon 485
		// Lifo ...
486
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
12 ddelon 487
			 if (table.getWidget(i, 0)!=null) {
488
				 if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
489
					 checked = true;
490
					 // Numero ordre
13 ddelon 491
					 parseChecked.add(table.getText(i, 4));
12 ddelon 492
					 count--;
493
				 }
494
			 }
11 ddelon 495
		}
12 ddelon 496
		StringBuffer ids=new StringBuffer();
11 ddelon 497
		for (Iterator it = parseChecked.iterator(); it.hasNext();) {
12 ddelon 498
			ids.append((String)it.next());
499
			if (it.hasNext()) ids.append(",");
500
		}
501
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
502
						+ "/" + ids.toString(), "action=DELETE",
11 ddelon 503
 
504
						new ResponseTextHandler() {
505
							public void onCompletion(String str) {
506
										updateCount();
507
							}
508
						});
509
 
510
		if (!checked) {
511
			setStatusEnabled();
512
		}
513
	}
514
 
515
	/**
516
	 * Selection de l'ensemble des elements affichés
517
	 *
518
	 */
519
 
520
	public void selectAll() {
521
 
12 ddelon 522
		// TODO : optimiser ...
11 ddelon 523
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
12 ddelon 524
			 if (table.getWidget(i, 0)!=null)
11 ddelon 525
			 ((CheckBox) table.getWidget(i, 0)).setChecked(true);
526
		}
527
	}
528
 
529
	public void deselectAll() {
530
 
12 ddelon 531
		// TODO : optimiser ...
11 ddelon 532
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
12 ddelon 533
			 if (table.getWidget(i, 0)!=null)
11 ddelon 534
			((CheckBox) table.getWidget(i, 0)).setChecked(false);
535
		}
536
	}
537
 
538
 
539
 
540
	/**
541
	 * Recherche nombre d'enregistrement pour l'utilisateur et la localite en cours
542
	 *
543
	 */
13 ddelon 544
	public void updateCount	() {
11 ddelon 545
 
546
		setStatusDisabled();
12 ddelon 547
 
548
		String adate="all";
549
		if (date.compareTo("all")!=0) {
550
			adate=date.substring(6,10)+"-"+date.substring(3,5)+"-"+date.substring(0,2)+" 00:00:00";
551
		}
11 ddelon 552
 
13 ddelon 553
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + location + "/" + adate  + "/" + search,
11 ddelon 554
				new ResponseTextHandler() {
555
 
556
					public void onCompletion(String str) {
557
 
558
						JSONValue jsonValue = JSONParser.parse(str);
559
						JSONNumber jsonNumber;
560
						if ((jsonNumber = jsonValue.isNumber()) != null) {
561
							count = (int) jsonNumber.getValue();
562
							/*
563
							if (count==0) {
564
								location="all";
565
							}
566
							*/
567
							if (location.compareTo("")==0)
568
								location="000null";
569
							mediator.onInventoryItemUpdate(location);
570
							gotoEnd(); // Derniere page
571
							update();
572
						}
573
					}
574
				});
575
 
576
	}
13 ddelon 577
 
578
 
579
	private String subLeft(String text, int length) {
580
		return (text.length() < length) ? text : text.substring(0, length)+ " ...";
581
	}
11 ddelon 582
 
583
	/**
584
	 * Mise a jour de l'affichage, à partir des données d'inventaire deja
585
	 * saisies. La valeur de this.startIndex permet de determiner quelles
586
	 * données seront affichées
587
	 *
588
	 *  @param deep : force une mise a jour totale
589
	 */
590
 
591
	public void update() {
592
 
13 ddelon 593
 
594
//		table.setBorderWidth(1);
11 ddelon 595
		setStatusDisabled();
596
 
12 ddelon 597
		String adate="all";
598
		if (date.compareTo("all")!=0) {
599
			adate=date.substring(6,10)+"-"+date.substring(3,5)+"-"+date.substring(0,2)+" 00:00:00";
600
		}
13 ddelon 601
 
602
 
603
		String com;
604
		if (location.compareTo("all")==0) {
605
			com="Toutes communes";
606
		}
607
		else {
608
			if (location.compareTo("000null")==0) {
609
				com="Communes non pr&eacute;cis&eacute;es";
610
			}
611
			else {
612
			com="Commune de "+location;
613
			}
614
		}
615
 
616
 
617
		String dat;
618
 
619
		if (date.compareTo("all")==0) {
620
			dat=", toute p&eacute;riode";
621
		}
622
		else {
623
			if (date.compareTo("00/00/0000")==0) {
624
				dat=", p&eacute;riode non pr&eacute;cis&eacute;";
625
			}
626
			else {
627
				dat=", le "+ date;
628
			}
629
		}
630
 
631
		header.setHTML(0, 0, com +  dat );
632
 
633
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + location +"/" + adate + "/" + search + "/" +
11 ddelon 634
				+ startIndex + "/" + VISIBLE_TAXON_COUNT,
635
 
636
		new ResponseTextHandler() {
637
 
638
			public void onCompletion(String str) {
639
 
640
				JSONValue jsonValue = JSONParser.parse(str);
641
				JSONArray jsonArray;
642
				JSONArray jsonArrayNested;
13 ddelon 643
 
644
				StringBuffer left=new StringBuffer();
645
				StringBuffer center=new StringBuffer();
646
				StringBuffer right=new StringBuffer();
11 ddelon 647
 
12 ddelon 648
 
11 ddelon 649
				int row=0;
650
				int i=0;
651
				if ((jsonArray = jsonValue.isArray()) != null) {
652
					int arraySize = jsonArray.size();
653
					for (i = 0; i < arraySize; ++i) {
654
						if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
655
							if (i>=table.getRowCount()) {
656
								 row = table.insertRow(table.getRowCount());
657
							}
658
							else {
659
								row = i;
660
							}
12 ddelon 661
 
13 ddelon 662
							left=new StringBuffer();
663
							center=new StringBuffer();
664
							right=new StringBuffer();
665
 
11 ddelon 666
							// Case a cocher
667
							table.setWidget(row, 0, new CheckBox());
668
							// Nom saisi
13 ddelon 669
 
670
							left.append("<b>"+((JSONString) jsonArrayNested .get(0)).stringValue()+"</b>");
12 ddelon 671
 
11 ddelon 672
							// Nom retenu
12 ddelon 673
							String aname=((JSONString) jsonArrayNested .get(2)).stringValue();
674
 
675
							if (aname.compareTo("null")==0) {
676
							}
677
							else {
13 ddelon 678
								center.append(aname+", ");
12 ddelon 679
							}
680
 
11 ddelon 681
							// Num nomenclatural
12 ddelon 682
							String ann=((JSONString) jsonArrayNested .get(3)).stringValue();
683
 
13 ddelon 684
							if (ann.compareTo("0")!=0) {
685
								center.append(""+ann+"-");
12 ddelon 686
							}
687
							else {
13 ddelon 688
								center.append("0-");
12 ddelon 689
							}
690
 
691
 
11 ddelon 692
							// Num Taxonomique
12 ddelon 693
 
694
							String ant=((JSONString) jsonArrayNested .get(4)).stringValue();
695
 
13 ddelon 696
							if (ant.compareTo("0")!=0) {
697
								center.append(ant+", ");
12 ddelon 698
							}
699
							else {
13 ddelon 700
								center.append("0, ");
12 ddelon 701
							}
702
 
11 ddelon 703
							// Famille
12 ddelon 704
							String afamily=((JSONString) jsonArrayNested .get(5)).stringValue();
705
 
706
							if (afamily.compareTo("null")==0) {
13 ddelon 707
								//
12 ddelon 708
							}
709
							else {
13 ddelon 710
								center.append(afamily+", ");
12 ddelon 711
							}
11 ddelon 712
 
713
 
13 ddelon 714
							String aloc=((JSONString) jsonArrayNested .get(6)).stringValue();
715
//								Localisation - Lieu
716
 
717
								if (aloc.compareTo("000null")==0) {
718
									if (center.length()==0) {
719
										center.append("Commune absente");
720
									}
721
									else {
722
										center.append("commune absente");
723
									}
724
								}
725
								else {
726
									if (center.length()==0) {
727
										center.append("Commune de "+aloc);
728
									}
729
									else {
730
										center.append("commune de "+aloc);
731
									}
732
 
733
								}
12 ddelon 734
 
13 ddelon 735
 
736
								String alieudit=((JSONString) jsonArrayNested .get(9)).stringValue();
12 ddelon 737
 
13 ddelon 738
//								Localisation - Lieu dit
739
 
740
								if (alieudit.compareTo("null")!=0) {
741
									center.append(", "+alieudit);
742
								}
12 ddelon 743
 
13 ddelon 744
								String acomment=((JSONString) jsonArrayNested .get(10)).stringValue();
745
//								Commentaire
746
 
747
								if (acomment.compareTo("null")!=0) {
748
									center.append(", "+acomment);
749
								}
12 ddelon 750
 
13 ddelon 751
 
11 ddelon 752
 
753
 
13 ddelon 754
 
755
								String adate=((JSONString) jsonArrayNested .get(8)).stringValue();
756
 
757
//								Date
758
								if (adate.compareTo("0000-00-00 00:00:00")!=0) {
759
									right.append("<b>"+adate+"</b>");
11 ddelon 760
								}
761
								else {
13 ddelon 762
//									right.append("<b>00/00/0000</b>");
11 ddelon 763
								}
764
 
12 ddelon 765
 
11 ddelon 766
 
12 ddelon 767
 
768
 
13 ddelon 769
 
770
							table.setHTML(row, 1, subLeft("&nbsp;"+left,40));
771
							table.setHTML(row, 2, subLeft("&nbsp;"+center,120));
772
							table.setHTML(row, 3, subLeft("&nbsp;"+right,25));
11 ddelon 773
 
13 ddelon 774
							table.getRowFormatter().removeStyleName(row, "inventoryItem-SelectedRow");
775
 
776
 
777
							table.getCellFormatter().setWordWrap(row,1,false);
778
							table.getCellFormatter().setWidth(row,1,"10%");
779
							table.getCellFormatter().setWordWrap(row,2,false);
780
							table.getCellFormatter().setWordWrap(row,3,false);
781
							table.getCellFormatter().setWidth(row,3,"7%");
782
 
783
 
784
							String aordre=((JSONString) jsonArrayNested.get(7)).stringValue();
785
 
11 ddelon 786
							// Numero d'ordre (caché)
13 ddelon 787
							table.setText(row, 4, aordre);
11 ddelon 788
 
13 ddelon 789
							if (add){
790
								if (i ==(arraySize -1)) {
791
									selectRow(row);
792
									mediator.getEntryPanel().setOrdre(aordre);
793
								}
794
 
795
							}
796
							else {
797
								if ((mediator.getEntryPanel().getOrdre()!=null) && (mediator.getEntryPanel().getOrdre().compareTo(aordre)==0)) {
798
									selectRow(row);
799
								}
800
							}
11 ddelon 801
 
13 ddelon 802
							table.getCellFormatter().setVisible(row, 4, false);
803
 
11 ddelon 804
 
805
						}
806
 
807
					}
808
				}
12 ddelon 809
 
810
 
11 ddelon 811
				// Suppression fin ancien affichage
13 ddelon 812
				for (int j=i;j<VISIBLE_TAXON_COUNT;j++) {
813
						 table.setHTML(j,0,"&nbsp;");
814
						 table.setHTML(j,1,"&nbsp;");
815
						 table.setHTML(j,2,"&nbsp;");
816
						 table.setHTML(j,3,"&nbsp;");
817
						 table.setHTML(j,4,"&nbsp;");
818
						table.getCellFormatter().setVisible(j, 4, false);
819
						table.getRowFormatter().removeStyleName(j, "inventoryItem-SelectedRow");
11 ddelon 820
				}
13 ddelon 821
 
822
				add=false;
11 ddelon 823
 
824
				setStatusEnabled();
825
 
13 ddelon 826
 
11 ddelon 827
			}
828
		});
13 ddelon 829
 
11 ddelon 830
 
831
	}
832
 
833
 
834
	/**
835
	 * Affichage message d'attente et désactivation navigation
836
	 *
837
	 * @param
838
	 * @return void
839
	 */
840
 
841
	private void setStatusDisabled() {
842
 
843
		navBar.gotoFirst.setEnabled(false);
844
		navBar.gotoPrev.setEnabled(false);
845
		navBar.gotoNext.setEnabled(false);
846
		navBar.gotoEnd.setEnabled(false);
847
 
848
		setStatusText("Patientez ...");
849
	}
850
 
851
	/**
852
	 * Affichage numero de page et gestion de la navigation
853
	 *
854
	 */
855
 
856
	private void setStatusEnabled() {
857
 
858
		// Il y a forcemment un disabled avant d'arriver ici
859
 
860
		if (count > 0) {
861
 
862
			if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la
863
														// premiere page
864
				navBar.gotoPrev.setEnabled(true);
865
				navBar.gotoFirst.setEnabled(true);
866
				if (startIndex < (count - VISIBLE_TAXON_COUNT)) { // Pas la
867
																	// derniere
868
																	// page
869
					navBar.gotoNext.setEnabled(true);
870
					navBar.gotoEnd.setEnabled(true);
871
					setStatusText((startIndex + 1) + " - "
872
							+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count );
873
				} else { // Derniere page
874
					setStatusText((startIndex + 1) + " - " + count + " sur " + count );
875
				}
876
			} else { // Premiere page
877
				if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
878
					navBar.gotoNext.setEnabled(true);
879
					navBar.gotoEnd.setEnabled(true);
880
					setStatusText((startIndex + 1) + " - "
881
							+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count);
882
				} else {
883
					setStatusText((startIndex + 1) + " - " + count + " sur " + count);
884
				}
885
			}
886
		}
887
 
888
		else { // Pas d'inventaire, pas de navigation
889
			setStatusText("0 - 0 sur 0");
890
		}
891
	}
892
 
893
	/*
894
	 * Positionnement index de parcours (this.startIndex) pour affichage de la
895
	 * dernière page
896
	 *
897
	 * @param
898
	 * @return void
899
	 */
900
 
901
	private void gotoEnd() {
902
 
903
		if ((count == 0) || (count % VISIBLE_TAXON_COUNT) > 0) {
904
			startIndex = count - (count % VISIBLE_TAXON_COUNT);
905
		} else {
906
			startIndex = count - VISIBLE_TAXON_COUNT;
907
		}
908
 
909
	}
910
 
911
	/*
13 ddelon 912
	 * Recherche en cours
913
	 *
914
	 */
915
 
916
	public void setSearch(String search) {
917
		this.search = search;
918
	}
919
 
920
 
921
 
922
	/*
11 ddelon 923
	 * Localite en cours
924
	 *
925
	 */
926
 
927
	public void setLocation(String location) {
928
		this.location = location;
929
	}
12 ddelon 930
 
931
 
932
 
933
	public void setDate(String date) {
934
		this.date = date;
935
	}
11 ddelon 936
 
937
 
938
 
939
 
940
 
941
 
942
}