Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 26 | 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(),
27 ddelon 294
												Util.toCelString(((JSONString) jsonArray.get(0))
295
														.toString()),
13 ddelon 296
												((JSONString) jsonArray.get(1))
297
														.stringValue(),
298
												((JSONString) jsonArray.get(2))
299
														.stringValue(),
27 ddelon 300
												Util.toCelString(((JSONString) jsonArray.get(3))
301
														.toString()),
302
														inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getMilieu(),inventoryItem.getComment());
13 ddelon 303
									}
304
								}
305
 
306
							});
307
				}
26 ddelon 308
				//  Modification d'un nom ne faisant pas parti du referentiel (saisie libre)
13 ddelon 309
				else {
27 ddelon 310
					updateElement(inventoryItem.getOrdre(),inventoryItem.getName(), " ", " ", " ", " ", " ",inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getMilieu(),inventoryItem.getComment());
13 ddelon 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(),
27 ddelon 352
												Util.toCelString(((JSONString) jsonArray.get(0))
353
														.toString()),
11 ddelon 354
												((JSONString) jsonArray.get(1))
355
														.stringValue(),
356
												((JSONString) jsonArray.get(2))
357
														.stringValue(),
27 ddelon 358
												Util.toCelString(((JSONString) jsonArray.get(3))
359
														.toString()),
360
														inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getMilieu(),inventoryItem.getComment());
11 ddelon 361
									}
362
								}
363
 
364
							});
365
				}
366
				// Saisie libre
367
				else {
27 ddelon 368
					addElement(inventoryItem.getName(), " ", " ", " ", " ", " ",inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getMilieu(),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,
27 ddelon 398
			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String milieu, String comment) {
11 ddelon 399
 
400
 
401
		count++;
402
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
27 ddelon 403
				+ user + "&nom_sel=" + URL.encodeComponent(nom_sel) + "&num_nom_sel=" + num_nom_sel
404
				+ "&nom_ret=" + URL.encodeComponent(nom_ret) + "&num_nom_ret=" + num_nom_ret
405
				+ "&num_taxon=" + num_taxon + "&famille=" + URL.encodeComponent(famille) + "&location=" + URL.encodeComponent(loc) + "&id_location=" + id_location + "&date_observation=" + dat
406
				+ "&station="+ URL.encodeComponent(milieu) + "&commentaire="+ URL.encodeComponent(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,
27 ddelon 441
			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location,String dat, String milieu, String comment) {
13 ddelon 442
 
443
 
14 ddelon 444
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user + "/" +ordre + "/",
27 ddelon 445
				 "&nom_sel=" + URL.encodeComponent(nom_sel) + "&num_nom_sel=" + num_nom_sel
446
				+ "&nom_ret=" + URL.encodeComponent(nom_ret) + "&num_nom_ret=" + num_nom_ret
447
				+ "&num_taxon=" + num_taxon + "&famille=" + URL.encodeComponent(famille) + "&location=" + URL.encodeComponent(loc) + "&id_location=" + id_location + "&date_observation=" + dat
448
				+ "&station="+ URL.encodeComponent(milieu) + "&commentaire="+ URL.encodeComponent(comment),
13 ddelon 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
 
27 ddelon 634
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + URL.encodeComponent(location) +"/" + adate + "/" + URL.encodeComponent(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) {
27 ddelon 658
							// Optimisation
11 ddelon 659
							if (i>=table.getRowCount()) {
660
								 row = table.insertRow(table.getRowCount());
661
							}
662
							else {
663
								row = i;
664
							}
12 ddelon 665
 
13 ddelon 666
							left=new StringBuffer();
667
							center=new StringBuffer();
668
							right=new StringBuffer();
669
 
11 ddelon 670
							// Case a cocher
671
							table.setWidget(row, 0, new CheckBox());
14 ddelon 672
 
673
 
27 ddelon 674
							// Statut Observation transmise ?
14 ddelon 675
 
676
 
677
							String atransmit=((JSONString) jsonArrayNested .get(11)).stringValue();
678
 
679
							if (atransmit.compareTo("1")==0) {
680
								table.setWidget(row,1,new Image("tela.gif"));
681
							}
682
							else {
683
								table.setWidget(row,1,new HTML("&nbsp;"));
684
							}
27 ddelon 685
 
686
							// Nom saisi
14 ddelon 687
 
27 ddelon 688
							left.append("<b>"+Util.toCelString(((JSONString) jsonArrayNested .get(0)).toString())+"</b>");
12 ddelon 689
 
11 ddelon 690
							// Nom retenu
27 ddelon 691
							String aname=Util.toCelString(((JSONString) jsonArrayNested .get(2)).toString());
12 ddelon 692
 
693
							if (aname.compareTo("null")==0) {
694
							}
695
							else {
13 ddelon 696
								center.append(aname+", ");
12 ddelon 697
							}
698
 
11 ddelon 699
							// Num nomenclatural
12 ddelon 700
							String ann=((JSONString) jsonArrayNested .get(3)).stringValue();
701
 
13 ddelon 702
							if (ann.compareTo("0")!=0) {
703
								center.append(""+ann+"-");
12 ddelon 704
							}
705
							else {
13 ddelon 706
								center.append("0-");
12 ddelon 707
							}
708
 
709
 
11 ddelon 710
							// Num Taxonomique
12 ddelon 711
 
712
							String ant=((JSONString) jsonArrayNested .get(4)).stringValue();
713
 
13 ddelon 714
							if (ant.compareTo("0")!=0) {
715
								center.append(ant+", ");
12 ddelon 716
							}
717
							else {
13 ddelon 718
								center.append("0, ");
12 ddelon 719
							}
720
 
11 ddelon 721
							// Famille
27 ddelon 722
							String afamily=Util.toCelString(((JSONString) jsonArrayNested .get(5)).toString());
12 ddelon 723
 
724
							if (afamily.compareTo("null")==0) {
13 ddelon 725
								//
12 ddelon 726
							}
727
							else {
13 ddelon 728
								center.append(afamily+", ");
12 ddelon 729
							}
11 ddelon 730
 
731
 
27 ddelon 732
							String aloc=Util.toCelString(((JSONString) jsonArrayNested .get(6)).toString());
13 ddelon 733
//								Localisation - Lieu
734
 
735
								if (aloc.compareTo("000null")==0) {
736
									if (center.length()==0) {
737
										center.append("Commune absente");
738
									}
739
									else {
740
										center.append("commune absente");
741
									}
742
								}
743
								else {
744
									if (center.length()==0) {
745
										center.append("Commune de "+aloc);
746
									}
747
									else {
748
										center.append("commune de "+aloc);
749
									}
750
 
751
								}
12 ddelon 752
 
13 ddelon 753
 
27 ddelon 754
								String alieudit=Util.toCelString(((JSONString) jsonArrayNested .get(9)).toString());
12 ddelon 755
 
13 ddelon 756
//								Localisation - Lieu dit
757
 
14 ddelon 758
								if (alieudit.compareTo("000null")!=0) {
13 ddelon 759
									center.append(", "+alieudit);
760
								}
12 ddelon 761
 
27 ddelon 762
								String acomment=Util.toCelString(((JSONString) jsonArrayNested .get(10)).toString());
13 ddelon 763
//								Commentaire
764
 
765
								if (acomment.compareTo("null")!=0) {
766
									center.append(", "+acomment);
767
								}
768
 
11 ddelon 769
 
13 ddelon 770
								String adate=((JSONString) jsonArrayNested .get(8)).stringValue();
771
 
772
//								Date
773
								if (adate.compareTo("0000-00-00 00:00:00")!=0) {
774
									right.append("<b>"+adate+"</b>");
11 ddelon 775
								}
776
								else {
13 ddelon 777
//									right.append("<b>00/00/0000</b>");
11 ddelon 778
								}
779
 
12 ddelon 780
 
14 ddelon 781
							table.setHTML(row, 2, subLeft("&nbsp;"+left,40));
782
							table.setHTML(row, 3, subLeft("&nbsp;"+center,120));
783
							table.setHTML(row, 4, subLeft("&nbsp;"+right,25));
12 ddelon 784
 
13 ddelon 785
							table.getRowFormatter().removeStyleName(row, "inventoryItem-SelectedRow");
786
 
787
 
14 ddelon 788
							table.getCellFormatter().setWidth(row,0,"2%");
789
							table.getCellFormatter().setWidth(row,1,"2%");
13 ddelon 790
							table.getCellFormatter().setWordWrap(row,2,false);
14 ddelon 791
							table.getCellFormatter().setWidth(row,2,"10%");
13 ddelon 792
							table.getCellFormatter().setWordWrap(row,3,false);
14 ddelon 793
							table.getCellFormatter().setWordWrap(row,4,false);
794
							table.getCellFormatter().setWidth(row,4,"7%");
13 ddelon 795
 
796
 
797
							String aordre=((JSONString) jsonArrayNested.get(7)).stringValue();
798
 
26 ddelon 799
							// Numero d'ordre (cache)
14 ddelon 800
 
801
 
802
							table.setText(row, 5, aordre);
803
							table.getCellFormatter().setVisible(row, 5, false);
13 ddelon 804
 
11 ddelon 805
 
806
						}
807
 
808
					}
809
				}
12 ddelon 810
 
811
 
11 ddelon 812
				// Suppression fin ancien affichage
13 ddelon 813
				for (int j=i;j<VISIBLE_TAXON_COUNT;j++) {
814
						 table.setHTML(j,0,"&nbsp;");
815
						 table.setHTML(j,1,"&nbsp;");
816
						 table.setHTML(j,2,"&nbsp;");
817
						 table.setHTML(j,3,"&nbsp;");
818
						 table.setHTML(j,4,"&nbsp;");
14 ddelon 819
						 table.setHTML(j,5,"&nbsp;");
820
						table.getCellFormatter().setVisible(j, 5, false);
13 ddelon 821
						table.getRowFormatter().removeStyleName(j, "inventoryItem-SelectedRow");
11 ddelon 822
				}
823
 
824
				setStatusEnabled();
825
 
13 ddelon 826
 
11 ddelon 827
			}
828
		});
13 ddelon 829
 
11 ddelon 830
 
831
	}
832
 
833
 
834
	/**
26 ddelon 835
	 * Affichage message d'attente et desactivation navigation
11 ddelon 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
 
26 ddelon 848
		navBar.status.setText("Patientez ...");
11 ddelon 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);
26 ddelon 871
					navBar.status.setText((startIndex + 1) + " - "
11 ddelon 872
							+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count );
873
				} else { // Derniere page
26 ddelon 874
					navBar.status.setText((startIndex + 1) + " - " + count + " sur " + count );
11 ddelon 875
				}
876
			} else { // Premiere page
877
				if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
878
					navBar.gotoNext.setEnabled(true);
879
					navBar.gotoEnd.setEnabled(true);
26 ddelon 880
					navBar.status.setText((startIndex + 1) + " - "
11 ddelon 881
							+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count);
882
				} else {
26 ddelon 883
					navBar.status.setText((startIndex + 1) + " - " + count + " sur " + count);
11 ddelon 884
				}
885
			}
886
		}
887
 
888
		else { // Pas d'inventaire, pas de navigation
26 ddelon 889
			navBar.status.setText("0 - 0 sur 0");
11 ddelon 890
		}
891
	}
892
 
893
	/*
894
	 * Positionnement index de parcours (this.startIndex) pour affichage de la
26 ddelon 895
	 * derniere page
11 ddelon 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
	/*
11 ddelon 922
	 * Localite en cours
923
	 *
924
	 */
925
 
926
	public void setLocation(String location) {
927
		this.location = location;
928
	}
12 ddelon 929
 
930
 
26 ddelon 931
 
932
	/*
933
	 * Station en cours
934
	 *
935
	 */
12 ddelon 936
 
26 ddelon 937
	public void setStation(String station) {
938
		this.station = station;
939
	}
940
 
941
 
942
 
943
 
944
	/*
945
	 * Date en cours
946
	 *
947
	 */
948
 
949
 
12 ddelon 950
	public void setDate(String date) {
951
		this.date = date;
952
	}
14 ddelon 953
 
26 ddelon 954
 
955
	/*
956
	 * Utilisateur en cours
957
	 *
958
	 */
959
 
14 ddelon 960
 
26 ddelon 961
 
14 ddelon 962
	public void setUser(String user) {
963
		this.user = user;
964
	}
26 ddelon 965
 
966
 
967
	public String getDate() {
968
		return date;
969
	}
970
 
971
 
972
	public String getLocation() {
973
		return location;
974
	}
975
 
976
 
977
	public String getSearch() {
978
		return search;
979
	}
980
 
981
 
982
	public String getStation() {
983
		return station;
984
	}
985
 
986
 
987
	public Grid getHeader() {
988
		return header;
989
	}
11 ddelon 990
 
14 ddelon 991
 
26 ddelon 992
	public void displayFilter() {
993
 
994
	// Mise a jour boutton export feuille de calcul
995
 
996
	mediator.getActionPanel().getExportButton().setHTML("<a href=\""+mediator.getServiceBaseUrl()+"/InventoryExport/"
997
			+  user + "/"
998
			+ URL.encodeComponent(location) + "/"
999
			+ URL.encodeComponent(station)+ "/"
1000
			+ URL.encodeComponent(search) + "/"
1001
			+ date +
1002
			"\">"+"Export&nbsp;tableur</a>");
1003
 
1004
	// Mise a jour ligne de selection
1005
 
1006
 
1007
 
1008
 
1009
	String com;
1010
	if (location.compareTo("all")==0) {
1011
		com="Toutes communes";
14 ddelon 1012
	}
26 ddelon 1013
	else {
1014
		if (location.compareTo("000null")==0) {
1015
			com="Communes non renseign&eacute;es";
1016
		}
1017
		else {
1018
		com="Commune de "+location;
1019
		}
1020
	}
14 ddelon 1021
 
26 ddelon 1022
 
1023
	String dat;
1024
 
1025
	if (date.compareTo("all")==0) {
1026
		dat=", toutes p&eacute;riodes";
1027
	}
1028
	else {
1029
		if (date.compareTo("00/00/0000")==0) {
1030
			dat=", p&eacute;riodes non renseign&eacute;es";
1031
		}
1032
		else {
1033
			dat=", le "+ date;
1034
		}
1035
	}
14 ddelon 1036
 
26 ddelon 1037
 
1038
	String stat;
1039
 
1040
	if (station.compareTo("all")==0) {
1041
		stat=", toutes stations";
1042
	}
1043
	else {
1044
		if (station.compareTo("000null")==0) {
1045
			stat=", stations non renseign&eacute;es";
1046
		}
1047
		else {
1048
			stat=", station "+ station;
1049
		}
1050
	}
11 ddelon 1051
 
26 ddelon 1052
 
1053
	header.setHTML(0, 0, com +  dat + stat );
11 ddelon 1054
 
26 ddelon 1055
 
1056
 
1057
}
25 ddelon 1058
 
26 ddelon 1059
 
11 ddelon 1060
}
26 ddelon 1061
 
1062
/* +--Fin du code ---------------------------------------------------------------------------------------+
27 ddelon 1063
* $Log$
1064
* Revision 1.7  2007-09-17 19:25:34  ddelon
1065
* Documentation
1066
*
26 ddelon 1067
*/