Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 202 Rev 263
Line 9... Line 9...
9
import org.tela_botanica.client.modeles.ListeEntiteGeographiqueObservation;
9
import org.tela_botanica.client.modeles.ListeEntiteGeographiqueObservation;
10
import org.tela_botanica.client.modeles.Observation;
10
import org.tela_botanica.client.modeles.Observation;
11
import org.tela_botanica.client.observation.ObservationMediateur;
11
import org.tela_botanica.client.observation.ObservationMediateur;
Line 12... Line 12...
12
 
12
 
-
 
13
import com.google.gwt.core.client.GWT;
13
import com.google.gwt.core.client.GWT;
14
import com.google.gwt.user.client.Window;
14
import com.gwtext.client.data.Node;
15
import com.gwtext.client.data.Node;
15
import com.gwtext.client.data.NodeTraversalCallback;
16
import com.gwtext.client.data.NodeTraversalCallback;
16
import com.gwtext.client.data.Tree;
17
import com.gwtext.client.data.Tree;
17
import com.gwtext.client.widgets.Component;
18
import com.gwtext.client.widgets.Component;
Line 153... Line 154...
153
				
154
				
154
				nomFiltre = "" ;
155
				nomFiltre = "" ;
155
				entitesGeographiquesEncours = "" ;
156
				entitesGeographiquesEncours = "" ;
156
				String nomPere = "" ;
157
				String nomPere = "" ;
-
 
158
				String nomGrandPere = "" ;
Line 157... Line 159...
157
				String nomGrandPere = "" ;
159
				String nomArriereGrandPere = "";
158
				
160
				
159
				switch(node.getDepth()) 
161
				switch(node.getDepth()) 
160
				{
162
				{
Line 166... Line 168...
166
						else 
168
						else 
167
						{
169
						{
168
							observationMediateur.obtenirNombreObservation() ;
170
							observationMediateur.obtenirNombreObservation() ;
169
						}
171
						}
170
						return ;
172
						return ;
-
 
173
					case 4: nomFiltre += "station,lieudit,location,id_location";
-
 
174
					nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
-
 
175
					nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[0] ;
-
 
176
					nomArriereGrandPere = ((String[])node.getParentNode().getParentNode().getParentNode().getUserObject())[0] ;
-
 
177
					entitesGeographiquesEncours += node.getText()+","+nomPere+","+nomGrandPere+","+nomArriereGrandPere ;
-
 
178
					break;
171
					case 3: nomFiltre += "lieudit,location,id_location";
179
					case 3: nomFiltre += "lieudit,location,id_location";
172
						nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
180
						nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
173
						nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[0] ;
181
						nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[0] ;
174
						entitesGeographiquesEncours += node.getText()+","+nomPere+","+nomGrandPere ;
182
						entitesGeographiquesEncours += node.getText()+","+nomPere+","+nomGrandPere ;
175
						break;
183
						break;
Line 208... Line 216...
208
	}
216
	}
Line 209... Line 217...
209
	
217
	
Line 210... Line 218...
210
	public void initialiser() {
218
	public void initialiser() {
-
 
219
		
211
		
220
		arbreCharge = false ;
212
		arbreCharge = false ;
221
		entitesGeographiquesEncours = "";
213
		arbreEntitesGeographiques.collapseAll();
222
		arbreEntitesGeographiques.collapseAll();
214
		// on vide l'ancien arbre
223
		// on vide l'ancien arbre
Line 238... Line 247...
238
			boolean repandreRaffraichissement) {
247
			boolean repandreRaffraichissement) {
Line 239... Line 248...
239
 
248
 
Line 240... Line -...
240
		
-
 
241
		if (nouvelleDonnees instanceof ListeEntiteGeographiqueObservation) {
-
 
242
		
-
 
243
			String id_location=null;
-
 
244
			String location=null;
249
		
Line 245... Line 250...
245
			String lieuDit=null;
250
		if (nouvelleDonnees instanceof ListeEntiteGeographiqueObservation) {
246
			
251
		
247
			ListeEntiteGeographiqueObservation data = (ListeEntiteGeographiqueObservation) nouvelleDonnees ;
252
			ListeEntiteGeographiqueObservation data = (ListeEntiteGeographiqueObservation) nouvelleDonnees ;
248
		
253
		
249
				// on crée un arbre vide
254
				// on crée un arbre vide
250
				Tree nouvelArbre = new Tree() ;
255
				Tree nouvelArbre = new Tree() ;
251
				TreeNode root = new TreeNode();
256
				TreeNode root = new TreeNode();
252
				root.setId("racine_entite");
257
				root.setId("racine_entite");
253
				root.setText("Localités");
-
 
254
				String[] usObjRoot = { "Localités"};
-
 
255
				root.setUserObject(usObjRoot);
-
 
256
				nouvelArbre.setRootNode(root);
-
 
257
			
-
 
258
			// on la parse et on récupère les informations qui nous interessent
-
 
259
			for (Iterator<String> it= data.keySet().iterator(); it.hasNext();) {
-
 
260
				
-
 
261
				EntiteGeographiqueObservation ent=(EntiteGeographiqueObservation) data.get(it.next());
-
 
262
				
-
 
263
				id_location=ent.getIdLocation();
-
 
264
				id_location = id_location.replaceAll("\"", "");
-
 
265
				id_location = id_location.replace('\\',' ');
-
 
266
				id_location = id_location.trim();
-
 
267
				location=ent.getLocation();
-
 
268
				lieuDit=ent.getLieuDit();
-
 
269
				
-
 
270
				if(id_location.contains("000null") || id_location.equals(null) || (id_location.trim()).equals("")) {
-
 
271
					id_location="Inconnue" ;
-
 
272
				}
-
 
273
				
-
 
274
				if(location.contains("000null") || location.equals(null) || (location.trim().equals(""))) {
-
 
275
					location="Inconnue" ;
-
 
276
				}
-
 
277
				
-
 
278
				if(lieuDit.contains("000null") || lieuDit.equals(null) || (lieuDit.trim().equals(""))) {
-
 
Line 279... Line -...
279
					lieuDit="Inconnue" ;
-
 
280
				}
-
 
281
				
-
 
282
				Node noeudMemeId = nouvelArbre.getNodeById(""+id_location);
-
 
283
				
-
 
284
				// si la région existe déjà
-
 
285
					if(noeudMemeId != null)
-
 
286
					{
-
 
287
						// on teste si la localité existe
-
 
288
						Node noeudMemeLoc = nouvelArbre.getNodeById(""+(id_location+location));
-
 
289
						if(noeudMemeLoc != null)
-
 
290
						{
-
 
291
							// enfin on teste si le lieu dit existe
-
 
292
							Node noeudMemeLieu = nouvelArbre.getNodeById(""+(id_location+location+lieuDit));
-
 
293
							if(noeudMemeLieu != null)
-
 
294
							{
-
 
295
								// tous les noeuds existent déjà, normalement ça ne devrait pas arriver
-
 
296
							}
-
 
297
							else
-
 
298
							{
-
 
299
								// enfin on ne crée que le noeud du lieu dit
-
 
300
								TreeNode node_lieu = new TreeNode();
-
 
301
								node_lieu.setId(""+(id_location+location+lieuDit));
-
 
302
								node_lieu.setText(lieuDit);
-
 
303
								noeudMemeLoc.appendChild(node_lieu) ;
-
 
304
								String[] usObj = {lieuDit,id_location+location+lieuDit};
-
 
305
								node_lieu.setUserObject(usObj);
-
 
306
							}
-
 
307
						}
-
 
308
						else
-
 
309
						{
-
 
310
							//  on  crée  le noeud de la location
-
 
311
							TreeNode node_loc = new TreeNode();
-
 
312
							node_loc.setId(""+(id_location+location));
-
 
313
							node_loc.setText(location);
-
 
314
							noeudMemeId.appendChild(node_loc) ;
-
 
315
							String[] usObj = {location,id_location+location};
-
 
316
							node_loc.setUserObject(usObj);
-
 
317
							
-
 
318
							TreeNode node_lieu = new TreeNode();
-
 
319
							node_lieu.setId(""+(id_location+location+lieuDit));
-
 
320
							node_lieu.setText(lieuDit);
-
 
321
							node_loc.appendChild(node_lieu) ;
-
 
322
							String[] usObj2 = {lieuDit,id_location+location+lieuDit};
-
 
323
							node_lieu.setUserObject(usObj2);
-
 
324
							
-
 
325
						}
-
 
326
					}
-
 
327
					else
-
 
328
					{
-
 
329
						//  on  crée  le noeud de l'identifiant  location
-
 
330
						TreeNode node_id_loc = new TreeNode();
-
 
331
						node_id_loc.setId(""+id_location);
-
 
332
						node_id_loc.setText(id_location);
-
 
333
						root.appendChild(node_id_loc) ;
-
 
334
						String[] usObj = {id_location,id_location};
-
 
335
						node_id_loc.setUserObject(usObj);
-
 
336
						
-
 
337
						TreeNode node_loc = new TreeNode();
-
 
338
						node_loc.setId(""+(id_location+location));
-
 
339
						node_loc.setText(location);
-
 
340
						node_id_loc.appendChild(node_loc) ;
-
 
341
						String[] usObj2 = {location,id_location+location};
-
 
342
						node_loc.setUserObject(usObj2);
-
 
343
						
-
 
344
						TreeNode node_lieu = new TreeNode();
-
 
345
						node_lieu.setId(""+(id_location+location+lieuDit));
-
 
346
						node_lieu.setText(lieuDit);
-
 
347
						node_loc.appendChild(node_lieu) ;
-
 
348
						String[] usObj3 = {lieuDit,id_location+location+lieuDit};
-
 
349
						node_lieu.setUserObject(usObj3);
-
 
350
					}
-
 
351
					
-
 
352
					root.sort(comparerNoeuds()) ;
258
				root.setText("Localités");
353
					doLayout();
259
				String[] usObjRoot = { "Localités"};
Line 354... Line 260...
354
 
260
				root.setUserObject(usObjRoot);
355
				}
-
 
356
			
261
				nouvelArbre.setRootNode(root);
357
				// on vide tous les noeuds
262
				
358
				arbreEntitesGeographiques.getRootNode().eachChild(new NodeTraversalCallback() {
263
				// on vide tous les noeuds
359
	
-
 
360
					public boolean execute(Node node) {
264
				arbreEntitesGeographiques.getRootNode().eachChild(new NodeTraversalCallback() {
-
 
265
	
-
 
266
					public boolean execute(Node node) {
-
 
267
						node.remove();
Line -... Line 268...
-
 
268
						return true;
-
 
269
					}
-
 
270
				});
-
 
271
			
-
 
272
			// on la parse et on récupère les informations qui nous interessent
361
	
273
			for (Iterator<String> it= data.keySet().iterator(); it.hasNext();) {
-
 
274
				
Line 362... Line -...
362
						node.remove();
-
 
363
						return true;
275
					EntiteGeographiqueObservation ent=(EntiteGeographiqueObservation) data.get(it.next());
Line 364... Line 276...
364
					}
276
					creerHierarchieNoeud(nouvelArbre ,root, ent);
365
	
277
					doLayout();
366
				});
278
				}
Line 393... Line 305...
393
			if(!arbreCharge) {
305
			if(!arbreCharge) {
394
				return;
306
				return;
395
			}
307
			}
Line 396... Line 308...
396
			
308
			
-
 
309
			Observation obs = (Observation)nouvelleDonnees ;
Line 397... Line -...
397
			Observation obs = (Observation)nouvelleDonnees ;
-
 
398
			
-
 
399
			String id_location= obs.getIdentifiantLocalite();
-
 
400
			id_location = id_location.replaceAll("\"", "");
-
 
401
			id_location = id_location.replace('\\',' ');
-
 
402
			id_location = id_location.trim();
-
 
403
			
-
 
404
			String location=obs.getLocalite();
-
 
405
			String lieuDit=obs.getLieudit();
-
 
406
			
-
 
407
			Node root = arbreEntitesGeographiques.getRootNode() ;
-
 
408
			
-
 
409
			if(id_location.contains("000null") || id_location.equals(null) || (id_location.trim()).equals("")) {
-
 
410
				id_location="Inconnue" ;
-
 
411
			}
-
 
412
			
-
 
413
			if(location.contains("000null") || location.equals(null) || (location.trim().equals(""))) {
-
 
414
				location="Inconnue" ;
-
 
415
			}
-
 
416
			
-
 
417
			if(lieuDit.contains("000null") || lieuDit.equals(null) || (lieuDit.trim().equals(""))) {
-
 
418
				lieuDit="Inconnue" ;
-
 
419
			}
-
 
420
			
-
 
421
			Node noeudMemeId = arbreEntitesGeographiques.getNodeById(""+id_location);
-
 
422
			// si la région existe déjà
-
 
423
				if(noeudMemeId != null)
-
 
424
				{
-
 
425
					// on teste si la localité existe
-
 
426
					Node noeudMemeLoc = arbreEntitesGeographiques.getNodeById(""+(id_location+location));
-
 
427
					if(noeudMemeLoc != null)
-
 
428
					{
310
			EntiteGeographiqueObservation ent = new EntiteGeographiqueObservation(obs.getIdentifiantLocalite(),obs.getLocalite(),obs.getLieudit(),obs.getStation());
429
						// enfin on teste si le lieu dit existe
-
 
430
						Node noeudMemeLieu = arbreEntitesGeographiques.getNodeById(""+(id_location+location+lieuDit));
-
 
431
						if(noeudMemeLieu != null)
-
 
432
						{
-
 
433
							// tous les noeuds existent déjà, normalement ça ne devrait pas arriver
-
 
434
						}
-
 
435
						else
-
 
436
						{
-
 
437
							// enfin on ne crée que le noeud du lieu dit
-
 
438
							TreeNode node_lieu = new TreeNode();
-
 
439
							node_lieu.setId(""+(id_location+location+lieuDit));
-
 
440
							node_lieu.setText(lieuDit);
-
 
441
							String[] usObj = {lieuDit,id_location+location+lieuDit};
-
 
442
							node_lieu.setUserObject(usObj);
-
 
443
							noeudMemeLoc.appendChild(node_lieu) ;
-
 
444
							
-
 
445
							root.sort(comparerNoeuds()) ;
-
 
446
						}
-
 
447
					}
-
 
448
					else
-
 
449
					{
-
 
450
						//  on  crée  le noeud de la location
-
 
451
						TreeNode node_loc = new TreeNode();
-
 
452
						node_loc.setId(""+(id_location+location));
-
 
453
						node_loc.setText(location);
-
 
454
						String[] usObj = {location,id_location+location};
-
 
455
						node_loc.setUserObject(usObj);
-
 
456
						noeudMemeId.appendChild(node_loc) ;
-
 
457
						
-
 
458
						TreeNode node_lieu = new TreeNode();
-
 
459
						node_lieu.setId(""+(id_location+location+lieuDit));
-
 
460
						node_lieu.setText(lieuDit);
-
 
461
						String[] usObj2 = {lieuDit,id_location+location+lieuDit};
-
 
462
						node_lieu.setUserObject(usObj2);
-
 
463
						node_loc.appendChild(node_lieu) ;
-
 
Line 464... Line -...
464
						
-
 
465
						root.sort(comparerNoeuds()) ;
-
 
466
						
311
			
467
					}
-
 
468
			}
-
 
469
			else
-
 
470
			{
-
 
471
				// TODO: Pourquoi l'ajout ne marche que sur la racine ?
-
 
472
				
-
 
473
				//  on  crée  le noeud de l'id location
-
 
474
				
-
 
475
				TreeNode node_id_loc = new TreeNode();
-
 
476
				node_id_loc.setId(""+id_location);
-
 
477
				node_id_loc.setText(id_location);
-
 
478
				String[] usObj = {id_location,id_location};
-
 
479
				node_id_loc.setUserObject(usObj);
-
 
480
				root.appendChild(node_id_loc) ;
-
 
481
				
-
 
482
				TreeNode node_loc = new TreeNode();
-
 
483
				node_loc.setId(""+(id_location+location));
-
 
484
				node_loc.setText(location);
-
 
485
				String[] usObj2 = {location,id_location+location};
-
 
486
				node_loc.setUserObject(usObj2);
-
 
487
				node_id_loc.appendChild(node_loc) ;
-
 
488
				
-
 
489
				TreeNode node_lieu = new TreeNode();
-
 
490
				node_lieu.setId(""+(id_location+location+lieuDit));
-
 
491
				node_lieu.setText(lieuDit);
-
 
492
				String[] usObj3 = {lieuDit,id_location+location+lieuDit};
-
 
493
				node_lieu.setUserObject(usObj3);
-
 
494
				node_loc.appendChild(node_lieu) ;
-
 
495
				
-
 
496
				root.sort(comparerNoeuds()) ;
312
			creerHierarchieNoeud(arbreEntitesGeographiques.getTree(), arbreEntitesGeographiques.getRootNode(), ent);
497
				
313
						
498
			}	
314
			doLayout();				
Line 499... Line 315...
499
				arbreEntitesGeographiques.doLayout() ;
315
			arbreEntitesGeographiques.doLayout() ;
Line 614... Line 430...
614
					}
430
					}
Line 615... Line 431...
615
					
431
					
616
					return n1.compareTo(n2) ;
432
					return n1.compareTo(n2) ;
617
				}
433
				}
618
				else
434
				else
619
				{	
435
				{
620
					String n1 = o1.getText() ;
436
					String n1 = o1.getId() ;
-
 
437
					String n2 = o2.getId() ;
Line 621... Line 438...
621
					String n2 = o2.getText() ;
438
									
622
				
439
				
623
					return n1.compareTo(n2) ;
440
					return  n1.compareToIgnoreCase(n2);
624
				}
441
				}
625
			}
442
			}
Line 626... Line 443...
626
		} ;
443
		} ;
627
	}
444
	}
628
 
445
 
629
	public void raz() {
446
	public void raz() {
630
			
447
		
Line 631... Line 448...
631
		arbreCharge = false ;
448
		arbreCharge = false ;
Line 650... Line 467...
650
				}
467
				}
651
			}
468
			}
Line 652... Line 469...
652
			
469
			
Line 653... Line 470...
653
		}) ;
470
		}) ;
-
 
471
		
-
 
472
		entitesGeographiquesEncours  = "";
-
 
473
		
-
 
474
	}
Line -... Line 475...
-
 
475
	
654
		
476
	private TreeNode creerNoeud(String id, String texte) {
-
 
477
		
-
 
478
		TreeNode nouveauNoeud = new TreeNode();
-
 
479
		nouveauNoeud.setId(""+(id));
Line -... Line 480...
-
 
480
		nouveauNoeud.setText(texte);
-
 
481
		String[] usObj = {texte,id+""};
-
 
482
		nouveauNoeud.setUserObject(usObj);
-
 
483
		
-
 
484
		return nouveauNoeud;
-
 
485
	}
-
 
486
	
-
 
487
	/**
-
 
488
	 * 
-
 
489
	 * @param arbre l'arbre dans lequel on recherche s'il faut créer les noeuds
-
 
490
	 * @param root le noeud racine auquel on concatène la hierarchie crée
-
 
491
	 * @param ent l'entité géographique qui doit être décomposée en arborescence
-
 
492
	 * @return
-
 
493
	 */
-
 
494
	private void creerHierarchieNoeud(Tree arbre, TreeNode root, EntiteGeographiqueObservation ent) {
-
 
495
		
-
 
496
		String idLocation=null;
-
 
497
		String location=null;
-
 
498
		String lieuDit=null;
-
 
499
		String station=null;
-
 
500
		
-
 
501
		
-
 
502
		idLocation=ent.getIdLocalite();
-
 
503
		idLocation = idLocation.replaceAll("\"", "");
-
 
504
		idLocation = idLocation.replace('\\',' ');
-
 
505
		idLocation = idLocation.trim();
-
 
506
		location=ent.getCommune();
-
 
507
		lieuDit=ent.getLieuDit();
-
 
508
		station=ent.getStation();
-
 
509
		
-
 
510
		if(idLocation.contains("000null") || idLocation.equals(null) || (idLocation.trim()).equals("")) {
-
 
511
			idLocation="Inconnue" ;
-
 
512
		}
-
 
513
		
-
 
514
		if(location.contains("000null") || location.equals(null) || (location.trim().equals(""))) {
-
 
515
			location="Inconnue" ;
-
 
516
		}
-
 
517
		
-
 
518
		if(lieuDit.contains("000null") || lieuDit.equals(null) || (lieuDit.trim().equals(""))) {
-
 
519
			lieuDit="Inconnue" ;
-
 
520
		}
-
 
521
		
-
 
522
		if(station.contains("000null") || station.equals(null) || (station.trim().equals(""))) {
-
 
523
			station="Inconnue" ;
-
 
524
		}
-
 
525
		
-
 
526
		Node noeudMemeId = arbre.getNodeById(""+idLocation);		
-
 
527
		if(noeudMemeId == null) {
-
 
528
			// on crée le noeud de l'identifiant location
-
 
529
			noeudMemeId = creerNoeud(""+idLocation,idLocation);
-
 
530
			root.appendChild(noeudMemeId) ;
-
 
531
		}
-
 
532
		
-
 
533
		// on teste si la localité existe
-
 
534
		Node noeudMemeLoc = arbre.getNodeById(""+(idLocation+location));
-
 
535
		if(noeudMemeLoc == null)
-
 
536
		{
-
 
537
			//  on crée le noeud de la location
-
 
538
			noeudMemeLoc = creerNoeud(""+idLocation+location, location);							
-
 
539
			noeudMemeId.appendChild(noeudMemeLoc) ;
-
 
540
		}
-
 
541
		
-
 
542
		// on teste si le lieu dit existe
-
 
543
		Node noeudMemeLieu = arbre.getNodeById(""+(idLocation+location+lieuDit));
-
 
544
		if(noeudMemeLieu == null)
-
 
545
		{
-
 
546
			// on crée le noeud du lieu dit
-
 
547
			noeudMemeLieu = creerNoeud(idLocation+location+lieuDit, lieuDit);	
-
 
548
			noeudMemeLoc.appendChild(noeudMemeLieu) ;
-
 
549
		}
-
 
550
		
-
 
551
		// on teste si la station existe
-
 
552
		Node noeudMemeStation = arbre.getNodeById(""+(idLocation+location+lieuDit+station));
-
 
553
		if(noeudMemeStation == null) {
-
 
554
			// on crée le noeud de la station
-
 
555
			noeudMemeStation = creerNoeud(idLocation+location+lieuDit+station,station);
655
		arbreCharge = false ;
556
			noeudMemeLieu.appendChild(noeudMemeStation);
Line 656... Line 557...
656
		
557
		}