Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 9 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9 Rev 10
Line 16... Line 16...
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
Line 17... Line 17...
17
 
17
 
18
import java.util.Iterator;
18
import java.util.Iterator;
Line 19... Line -...
19
import java.util.Vector;
-
 
20
 
19
import java.util.Vector;
21
import com.google.gwt.i18n.client.Dictionary;
20
 
22
import com.google.gwt.json.client.JSONArray;
21
import com.google.gwt.json.client.JSONArray;
23
import com.google.gwt.json.client.JSONNumber;
22
import com.google.gwt.json.client.JSONNumber;
24
import com.google.gwt.json.client.JSONParser;
23
import com.google.gwt.json.client.JSONParser;
Line 40... Line 39...
40
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
39
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
41
import com.google.gwt.user.client.ui.HasVerticalAlignment;
40
import com.google.gwt.user.client.ui.HasVerticalAlignment;
42
import com.google.gwt.user.client.ui.Label;
41
import com.google.gwt.user.client.ui.Label;
Line 43... Line 42...
43
 
42
 
44
/*
43
/*
45
 * Le retour de getUser appelle getCount qui appelle update pour veiller à une
44
 * Le retour de getUser appelle updateCount qui appelle update pour veiller à une
46
 * initialisation correcte
45
 * initialisation correcte
47
 * 
46
 * 
Line 48... Line 47...
48
 */
47
 */
Line 191... Line 190...
191
							startIndex = 0;
190
							startIndex = 0;
192
						}
191
						}
193
					}
192
					}
194
				}
193
				}
195
			}
194
			}
196
			update(true);
195
			update();
197
		}
196
		}
Line 198... Line 197...
198
 
197
 
Line 199... Line 198...
199
	}
198
	}
Line 210... Line 209...
210
 
209
 
Line 211... Line 210...
211
	private VerticalPanel panel = new VerticalPanel();
210
	private VerticalPanel panel = new VerticalPanel();
Line 212... Line 211...
212
 
211
 
Line 213... Line 212...
213
	private int startIndex = 0;
212
	private int startIndex = 0;
Line 214... Line 213...
214
 
213
 
Line 215... Line 214...
215
	private String serviceBaseUrl = getServiceBaseUrl();
214
	private String serviceBaseUrl = null;
Line -... Line 215...
-
 
215
 
-
 
216
	private int count = 65000;
-
 
217
 
216
 
218
	private String user;
217
	private int count = 65000;
219
 
Line 218... Line -...
218
 
-
 
Line -... Line 220...
-
 
220
	private NavBar navBar=null;
-
 
221
	
-
 
222
	private Mediator mediator = null;
-
 
223
	
-
 
224
	// Optimization
-
 
225
	int sizeChecked=0;
-
 
226
	int itemDeleted=0;
-
 
227
	
-
 
228
	
-
 
229
	// Data provider 
-
 
230
	private NameAssistant nameProvider=null;
-
 
231
	private LocationAssistant locationProvider=null;
-
 
232
	
-
 
233
	
-
 
234
	// Data from provider
-
 
235
	
-
 
236
 	private String nameText=null;
-
 
237
 	private String nameValue=null;
-
 
238
 	private String locationText=null;
-
 
239
 	private String locationValue=null;
-
 
240
 
-
 
241
	private String location = "all";
-
 
242
	
-
 
243
	public TaxonList(Mediator med) {
-
 
244
 
-
 
245
		mediator=med;
-
 
246
		
-
 
247
	    mediator.registerTaxonList(this);
-
 
248
		
-
 
249
		user=mediator.getUser();
-
 
250
	    serviceBaseUrl = mediator.getServiceBaseUrl();
-
 
251
	
-
 
252
		navBar = new NavBar();
-
 
253
		
-
 
254
 
-
 
255
		// Information complementaire : un tableau associe au retour de
-
 
256
		// l'assistant de saisie
-
 
257
 
-
 
258
		// Mise en forme du header
-
 
259
 
-
 
260
		header.setCellSpacing(0);
-
 
261
		header.setCellPadding(2);
-
 
262
		header.setWidth("100%");
-
 
263
 
-
 
264
		header.setStyleName("taxon-ListHeader");
-
 
265
 
-
 
266
		header.setText(0, 0, "");
-
 
267
		header.setText(0, 1, "Nom saisi");
-
 
268
		header.setText(0, 2, "Nom retenu");
-
 
269
		header.setHTML(0, 3, "Code<br>Nomenclatural");
-
 
270
		header.setHTML(0, 4, "Code<br>Taxonomique");
-
 
271
		header.setText(0, 5, "Famille");
-
 
272
 
-
 
273
		header.getCellFormatter().setWidth(0, 0, "2%");
-
 
274
		header.getCellFormatter().setWidth(0, 1, "31%");
-
 
275
		header.getCellFormatter().setWidth(0, 2, "31%");
-
 
276
		header.getCellFormatter().setWidth(0, 3, "9%");
-
 
277
		header.getCellFormatter().setWidth(0, 4, "9%");
219
	private String user;
278
		header.getCellFormatter().setWidth(0, 5, "18%");
-
 
279
 
-
 
280
		// Mise en forme de la table.
-
 
281
 
-
 
282
		table.setCellSpacing(0);
-
 
283
		table.setBorderWidth(0);
-
 
284
		table.setCellPadding(2);
-
 
285
		table.setWidth("100%");
-
 
286
 
-
 
287
		// Mise en forme barre navigation
-
 
288
 
-
 
289
		navBar.setWidth("100%");
-
 
290
 
Line 220... Line 291...
220
 
291
		table.setStyleName("taxon-List");
Line 221... Line 292...
221
	private NavBar navBar=null;
292
 
Line 238... Line 309...
238
	 * nomenclaturaux etc) et met a jour l'inventaire (addelement())
309
	 * nomenclaturaux etc) et met a jour l'inventaire (addelement())
239
	 * 
310
	 * 
240
	 * @return void
311
	 * @return void
241
	 */
312
	 */
242
	public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,
313
	public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,
243
			 final String str,final String value) {
314
			  String str, String value) {
-
 
315
	
-
 
316
	// Le nom de plante est requis 
-
 
317
		
-
 
318
	 if (nameProvider.getText().compareTo("")==0) {
-
 
319
		 return;
-
 
320
	 }
-
 
321
	
-
 
322
		 nameText=nameProvider.getText();
-
 
323
		 nameValue=nameProvider.getValue();
-
 
324
		 locationValue=locationProvider.getValue();
-
 
325
		 locationText=locationProvider.getText();
-
 
326
		 
-
 
327
		 // Suppresion indication departementale (on pourrait faire mieux !!)
-
 
328
		 int pos=locationText.indexOf("(" );
-
 
329
		 if (pos>=0) {
-
 
330
			 locationText=locationText.substring(0,pos);
-
 
331
		 }
Line 244... Line 332...
244
 
332
	 
Line 245... Line 333...
245
		setStatusDisabled();
333
				setStatusDisabled();
Line 246... Line 334...
246
 
334
		
247
		// On met a jour rapidement l'affichage puis on lance la requete  ....
335
				// On met a jour rapidement l'affichage puis on lance la requete  ....
248
		
336
				
249
		int row = table.insertRow(table.getRowCount());
337
				int row = table.insertRow(table.getRowCount());
250
		// Case a cocher
338
				// Case a cocher
Line 251... Line 339...
251
		table.setWidget(row, 0, new CheckBox());
339
				table.setWidget(row, 0, new CheckBox());
252
		// Nom saisi
340
				// Nom saisi
253
		table.setText(row, 1, str);
341
				table.setText(row, 1, nameText);
Line 254... Line 342...
254
		
342
				
Line 255... Line 343...
255
		table.getFlexCellFormatter().setWidth(row, 0, "2%");
343
				table.getFlexCellFormatter().setWidth(row, 0, "2%");
256
		table.getFlexCellFormatter()
-
 
Line 257... Line 344...
257
				.setWidth(row, 1, "31%");
344
				table.getFlexCellFormatter()
258
		
345
						.setWidth(row, 1, "31%");
Line 259... Line 346...
259
		// Recherche complement d'information
346
				
Line 260... Line 347...
260
 
347
				// Recherche complement d'information
261
		if (value !=null) {
348
		
Line 262... Line 349...
262
 
349
				if (nameValue !=null) {
263
 
350
		
264
			HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + value,
351
					HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nameValue,
265
					new ResponseTextHandler() {
352
							new ResponseTextHandler() {
266
 
353
		
267
						public void onCompletion(String strcomplete) {
354
								public void onCompletion(String strcomplete) {
268
 
355
		
269
							JSONValue jsonValue = JSONParser.parse(strcomplete);
356
									JSONValue jsonValue = JSONParser.parse(strcomplete);
270
							JSONArray jsonArray;
357
									JSONArray jsonArray;
271
 
358
		
272
							if ((jsonArray = jsonValue.isArray()) != null) {
359
									if ((jsonArray = jsonValue.isArray()) != null) {
273
								// Nom retenu, Num Nomen nom retenu, Num Taxon,
360
										// Nom retenu, Num Nomen nom retenu, Num Taxon,
-
 
361
										// Famille
274
								// Famille
362
										addElement(nameText, nameValue,
275
								addElement(str, value,
363
												((JSONString) jsonArray.get(0))
Line 276... Line 364...
276
										((JSONString) jsonArray.get(0))
364
														.stringValue(),
277
												.stringValue(),
365
												((JSONString) jsonArray.get(1))
278
										((JSONString) jsonArray.get(1))
366
														.stringValue(),
279
												.stringValue(),
367
												((JSONString) jsonArray.get(2))
280
										((JSONString) jsonArray.get(2))
368
														.stringValue(),
281
												.stringValue(),
369
												((JSONString) jsonArray.get(3))
Line 282... Line -...
282
										((JSONString) jsonArray.get(3))
-
 
283
												.stringValue());
370
														.stringValue(),
Line 284... Line 371...
284
							}
371
														locationText,locationValue);
285
						}
372
									}
286
 
373
								}
Line 311... Line 398...
311
	 * @param famille :
398
	 * @param famille :
312
	 *            famille
399
	 *            famille
313
	 */
400
	 */
Line 314... Line 401...
314
 
401
 
315
	public void addElement(String nom_sel, String num_nom_sel, String nom_ret,
402
	public void addElement(String nom_sel, String num_nom_sel, String nom_ret,
Line 316... Line 403...
316
			String num_nom_ret, String num_taxon, String famille) {
403
			String num_nom_ret, String num_taxon, String famille,final String loc, String id_location) {
Line 317... Line 404...
317
 
404
 
318
		// Calcul du nouveau numéro d'ordre
405
		// Calcul du nouveau numéro d'ordre
Line 324... Line 411...
324
 
411
 
325
		count++;
412
		count++;
326
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
413
		HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
327
				+ user + "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
414
				+ user + "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
328
				+ "&nom_ret=" + nom_ret + "&num_nom_ret=" + num_nom_ret
415
				+ "&nom_ret=" + nom_ret + "&num_nom_ret=" + num_nom_ret
Line 329... Line 416...
329
				+ "&num_taxon=" + num_taxon + "&famille=" + famille,
416
				+ "&num_taxon=" + num_taxon + "&famille=" + famille + "&location=" + loc + "&id_location=" + id_location,
Line 330... Line 417...
330
 
417
 
331
		new ResponseTextHandler() {
-
 
332
 
-
 
333
			public void onCompletion(String str) {
-
 
334
				// (Optimisation) Si on reste sur la meme page  : ajout à la fin
-
 
335
				if (((count-2)/VISIBLE_TAXON_COUNT)==(count-1/VISIBLE_TAXON_COUNT)) {
-
 
336
					update(false);
418
		new ResponseTextHandler() {
337
				}
419
 
338
				else { 
-
 
339
					gotoEnd();
420
			public void onCompletion(String str) {
340
					update(true);
421
					location=loc;
341
				}
422
					updateCount();
Line 342... Line 423...
342
			}
423
			}
Line 358... Line 439...
358
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
439
		for (int i = table.getRowCount() - 1; i >= 0; i--) {
359
			if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
440
			if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
360
				checked = true;
441
				checked = true;
361
				parseChecked.add(table.getText(i, 6));
442
				parseChecked.add(table.getText(i, 6));
362
				count--;
443
				count--;
363
				
-
 
364
			}
444
			}
365
		}
445
		}
366
		sizeChecked=parseChecked.size();
446
		sizeChecked=parseChecked.size();
367
		itemDeleted=0;
447
		itemDeleted=0;
368
		for (Iterator it = parseChecked.iterator(); it.hasNext();) {
448
		for (Iterator it = parseChecked.iterator(); it.hasNext();) {
Line 370... Line 450...
370
			HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
450
			HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
371
						+ "/" + (String) it.next(), "action=DELETE",
451
						+ "/" + (String) it.next(), "action=DELETE",
Line 372... Line 452...
372
						
452
						
373
						new ResponseTextHandler() {
453
						new ResponseTextHandler() {
374
							public void onCompletion(String str) {
454
							public void onCompletion(String str) {
375
								// On ne lance la suppression qu'a la fin
455
								// Optimisation : on ne lance la suppression qu'a la fin
376
								    if (itemDeleted==sizeChecked) { 
-
 
377
										gotoEnd();
456
								    if (itemDeleted==sizeChecked) { 
378
										update(true);
457
										updateCount();
379
								    }
458
								    }
380
							}
459
							}
Line 381... Line 460...
381
						});
460
						});
Line 404... Line 483...
404
			((CheckBox) table.getWidget(i, 0)).setChecked(false); 
483
			((CheckBox) table.getWidget(i, 0)).setChecked(false); 
405
		}
484
		}
406
	}
485
	}
Line 407... Line -...
407
 
-
 
408
 
-
 
409
	/**
-
 
410
	 * 
-
 
411
	 * Lancement des initialisations dependantes de réponses asynchrones : le
-
 
412
	 * retour d'une demande d'initialisation declanche la demande
-
 
413
	 * d'initialisation suivantes user : resultat recherche nom d'utilisateur
-
 
414
	 * count : resultat nombre d'enregistrements d'inventaires affichage
-
 
415
	 * enregistrements trouvés
-
 
416
	 * 
-
 
417
	 */
-
 
418
	private void initAsync() {
-
 
419
 
-
 
420
		navBar = new NavBar();
-
 
421
		
-
 
422
 
-
 
423
		// Information complementaire : un tableau associe au retour de
-
 
424
		// l'assistant de saisie
-
 
425
 
-
 
426
		// Mise en forme du header
-
 
427
 
-
 
428
		header.setCellSpacing(0);
-
 
429
		header.setCellPadding(2);
-
 
430
		header.setWidth("100%");
-
 
431
 
-
 
432
		header.setStyleName("taxon-ListHeader");
-
 
433
 
-
 
434
		header.setText(0, 0, "");
-
 
435
		header.setText(0, 1, "Nom saisi");
-
 
436
		header.setText(0, 2, "Nom retenu");
-
 
437
		header.setHTML(0, 3, "Code<br>Nomenclatural");
-
 
438
		header.setHTML(0, 4, "Code<br>Taxonomique");
-
 
439
		header.setText(0, 5, "Famille");
-
 
440
 
-
 
441
		header.getCellFormatter().setWidth(0, 0, "2%");
-
 
442
		header.getCellFormatter().setWidth(0, 1, "31%");
-
 
443
		header.getCellFormatter().setWidth(0, 2, "31%");
-
 
444
		header.getCellFormatter().setWidth(0, 3, "9%");
-
 
445
		header.getCellFormatter().setWidth(0, 4, "9%");
-
 
446
		header.getCellFormatter().setWidth(0, 5, "18%");
-
 
447
 
-
 
448
		// Mise en forme de la table.
-
 
449
 
-
 
450
		table.setCellSpacing(0);
-
 
451
		table.setBorderWidth(0);
-
 
452
		table.setCellPadding(2);
-
 
453
		table.setWidth("100%");
-
 
454
 
-
 
455
		// Mise en forme barre navigation
-
 
456
 
-
 
457
		navBar.setWidth("100%");
-
 
458
 
-
 
459
		table.setStyleName("taxon-List");
-
 
460
 
-
 
461
		panel.add(navBar);
-
 
462
		panel.add(header);
-
 
463
		panel.add(table);
-
 
464
 
-
 
465
		getCount();
-
 
466
		// update()
-
 
467
 
-
 
468
	}
-
 
469
 
-
 
470
	/**
-
 
471
	 * Recherche utilisateur en cours
-
 
472
	 * 
-
 
473
	 */
-
 
474
	private void getUser() {
-
 
475
 
-
 
476
 
-
 
477
		HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
-
 
478
				new ResponseTextHandler() {
-
 
479
 
-
 
480
					public void onCompletion(String str) {
-
 
481
						JSONValue jsonValue = JSONParser.parse(str);
-
 
482
						JSONString jsonString;
-
 
483
						if ((jsonString = jsonValue.isString()) != null) {
-
 
484
							user = jsonString.stringValue();
-
 
485
						}
-
 
486
						initAsync();
-
 
487
					}
-
 
488
				});
-
 
Line 489... Line 486...
489
 
486
 
490
	}
487
 
491
 
488
 
492
	/**
489
	/**
493
	 * Recherche nombre d'enregistrement pour l'utilisateur en cours
490
	 * Recherche nombre d'enregistrement pour l'utilisateur et la localite en cours
Line 494... Line 491...
494
	 * 
491
	 * 
Line 495... Line 492...
495
	 */
492
	 */
496
	private void getCount() {
493
	public void updateCount() {
Line 497... Line 494...
497
		
494
		
Line 498... Line 495...
498
		setStatusDisabled();
495
		setStatusDisabled();
499
 
496
 
500
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/",
497
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryTaxonList/" + user + "/" + location,
501
				new ResponseTextHandler() {
498
				new ResponseTextHandler() {
502
 
499
 
-
 
500
					public void onCompletion(String str) {
-
 
501
 
-
 
502
						JSONValue jsonValue = JSONParser.parse(str);
-
 
503
						JSONNumber jsonNumber;
-
 
504
						if ((jsonNumber = jsonValue.isNumber()) != null) {
-
 
505
							count = (int) jsonNumber.getValue();
503
					public void onCompletion(String str) {
506
							gotoEnd(); // Derniere page
504
 
507
							if (count==0) {
505
						JSONValue jsonValue = JSONParser.parse(str);
508
								location="all";
506
						JSONNumber jsonNumber;
509
							}
Line 507... Line 510...
507
						if ((jsonNumber = jsonValue.isNumber()) != null) {
510
							if (location.compareTo("")==0)
Line 517... Line 520...
517
	/**
520
	/**
518
	 * Mise a jour de l'affichage, à partir des données d'inventaire deja
521
	 * Mise a jour de l'affichage, à partir des données d'inventaire deja
519
	 * saisies. La valeur de this.startIndex permet de determiner quelles
522
	 * saisies. La valeur de this.startIndex permet de determiner quelles
520
	 * données seront affichées
523
	 * données seront affichées
521
	 * 
524
	 * 
-
 
525
	 *  @param deep : force une mise a jour totale
522
	 */
526
	 */
Line 523... Line 527...
523
 
527
 
Line 524... Line 528...
524
	private void update(final boolean deep) {
528
	public void update() {
Line 525... Line 529...
525
 
529
 
526
		setStatusDisabled();
530
		setStatusDisabled();
Line 532... Line 536...
532
		// et inserer ou supprimer s'il le faut.
536
		// et inserer ou supprimer s'il le faut.
Line 533... Line 537...
533
 
537
 
534
		// TODO : ou alors prevoir un update pour les ajouts (forcemment à la fin) et un update pour les suppressions ...
538
		// TODO : ou alors prevoir un update pour les ajouts (forcemment à la fin) et un update pour les suppressions ...
Line 535... Line 539...
535
		// Sauf qu'il y a les chgts de pages ... : oui, la un fait un update normal ...
539
		// Sauf qu'il y a les chgts de pages ... : oui, la un fait un update normal ...
536
		
540
		
Line 537... Line 541...
537
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/"
541
		HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryTaxonList/" + user + "/" + location +"/"
Line 538... Line 542...
538
				+ startIndex + "/" + VISIBLE_TAXON_COUNT,
542
				+ startIndex + "/" + VISIBLE_TAXON_COUNT,
Line 539... Line 543...
539
 
543
 
540
		new ResponseTextHandler() {
544
		new ResponseTextHandler() {
541
 
545
 
Line 542... Line -...
542
			public void onCompletion(String str) {
-
 
543
 
-
 
544
				JSONValue jsonValue = JSONParser.parse(str);
546
			public void onCompletion(String str) {
545
				JSONArray jsonArray;
547
 
546
				JSONArray jsonArrayNested;
548
				JSONValue jsonValue = JSONParser.parse(str);
547
 
-
 
548
				// Lifo ...
-
 
549
				if (deep) {
-
 
550
					for (int i = table.getRowCount() - 1; i >= 0; i--) {
-
 
Line 551... Line 549...
551
						table.removeRow(i);
549
				JSONArray jsonArray;
552
					}
550
				JSONArray jsonArrayNested;
553
				}
551
 
554
				else {
-
 
555
					table.removeRow(table.getRowCount());
-
 
556
				}
-
 
557
					
552
				for (int i = table.getRowCount() - 1; i >= 0; i--) {
558
				if ((jsonArray = jsonValue.isArray()) != null) {
553
					table.removeRow(i);
559
					int arraySize = jsonArray.size();
554
				}
560
					for (int i = 0; i < arraySize; ++i) {
555
					
561
						if (!deep && i != arraySize -1) {
556
				if ((jsonArray = jsonValue.isArray()) != null) {
Line 604... Line 599...
604
			}
599
			}
605
		});
600
		});
Line 606... Line 601...
606
 
601
 
Line 607... Line -...
607
	}
-
 
608
 
-
 
609
	/**
-
 
610
	 * Recuperation du prefixe d'appel des services
-
 
611
	 */
-
 
612
 
-
 
613
	private String getServiceBaseUrl() {
-
 
614
 
-
 
615
		Dictionary theme = Dictionary.getDictionary("Parameters");
-
 
616
		return theme.get("serviceBaseUrl");
-
 
Line 617... Line 602...
617
 
602
	}
618
	}
603
 
619
 
604
 
620
	/**
605
	/**
Line 692... Line 677...
692
			startIndex = count - VISIBLE_TAXON_COUNT;
677
			startIndex = count - VISIBLE_TAXON_COUNT;
693
		}
678
		}
Line 694... Line 679...
694
 
679
 
Line -... Line 680...
-
 
680
	}
-
 
681
 
-
 
682
	public void setNameProvider(NameAssistant nameAssistant) {
-
 
683
		this.nameProvider = nameAssistant;
-
 
684
	}
-
 
685
 
-
 
686
	public void setLocationProvider(LocationAssistant locationAssistant) {
-
 
687
		this.locationProvider = locationAssistant;
-
 
688
	}
-
 
689
 
-
 
690
	public void setLocation(String location) {
-
 
691
		this.location = location;
-
 
692
	}
-
 
693
	
-
 
694
	
-
 
695
	
Line 695... Line 696...
695
	}
696