Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 25 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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