Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 152 Rev 156
Line 1... Line 1...
1
package org.tela_botanica.client.observation;
1
package org.tela_botanica.client.observation;
Line 2... Line 2...
2
 
2
 
Line -... Line 3...
-
 
3
 
-
 
4
//TODO : normaliser les noms de methodes (obtenir, ajouter ...)
3
 
5
 
4
//TODO : normaliser les noms de methodes (obtenir, ajouter ...)
6
import java.util.HashMap;
5
 
7
import org.tela_botanica.client.interfaces.FournisseurListe;
-
 
8
import org.tela_botanica.client.interfaces.Rafraichissable;
-
 
9
import org.tela_botanica.client.modeles.Configuration;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
10
import org.tela_botanica.client.modeles.ExportObservationsDAO;
7
import org.tela_botanica.client.modeles.Configuration;
11
import org.tela_botanica.client.modeles.ImageAsynchroneDAO;
-
 
12
import org.tela_botanica.client.modeles.ImageCarnet;
8
import org.tela_botanica.client.modeles.ExportObservationsDAO;
13
import org.tela_botanica.client.modeles.ImageGeneriqueVueAsynchroneDAO;
9
import org.tela_botanica.client.modeles.ImageGeneriqueVueAsynchroneDAO;
14
import org.tela_botanica.client.modeles.ImageInformationRepartitionAsynchroneDAO;
10
import org.tela_botanica.client.modeles.ImageInformationRepartitionAsynchroneDAO;
15
import org.tela_botanica.client.modeles.ImportObservationAsynchroneDAO;
-
 
16
import org.tela_botanica.client.modeles.LienImageAsynchroneDAO;
11
import org.tela_botanica.client.modeles.LienImageAsynchroneDAO;
17
import org.tela_botanica.client.modeles.ListeDateObservationAsynchroneDAO;
12
import org.tela_botanica.client.modeles.ListeDateObservationAsynchroneDAO;
18
import org.tela_botanica.client.modeles.ListeEntiteGeographiqueObservationAsynchroneDAO;
13
import org.tela_botanica.client.modeles.ListeEntiteGeographiqueObservationAsynchroneDAO;
19
import org.tela_botanica.client.modeles.ListeObservation;
-
 
20
import org.tela_botanica.client.modeles.ListeObservationAsynchroneDAO;
14
import org.tela_botanica.client.modeles.ListeObservationAsynchroneDAO;
21
import org.tela_botanica.client.modeles.ListeReferentielCommuneAsynchroneDAO;
15
import org.tela_botanica.client.modeles.ListeReferentielCommuneAsynchroneDAO;
22
import org.tela_botanica.client.modeles.ListeReferentielNomAsynchroneDAO;
16
import org.tela_botanica.client.modeles.ListeReferentielNomAsynchroneDAO;
23
import org.tela_botanica.client.modeles.MotsClesAsynchroneDAO;
17
import org.tela_botanica.client.modeles.MotsClesObsAsynchronesDAO;
24
import org.tela_botanica.client.modeles.MotsClesObsAsynchronesDAO;
18
import org.tela_botanica.client.modeles.NomRetenuAsynchroneDao;
25
import org.tela_botanica.client.modeles.NomRetenuAsynchroneDao;
19
import org.tela_botanica.client.modeles.NombreObservationAsynchroneDAO;
26
import org.tela_botanica.client.modeles.NombreObservationAsynchroneDAO;
-
 
27
import org.tela_botanica.client.modeles.Observation;
-
 
28
import org.tela_botanica.client.modeles.ObservationAsynchroneDAO;
-
 
29
import org.tela_botanica.client.modeles.TransmissionObservationAsynchroneDAO;
-
 
30
import com.google.gwt.json.client.JSONArray;
-
 
31
import com.google.gwt.json.client.JSONObject;
Line 20... Line 32...
20
import org.tela_botanica.client.modeles.Observation;
32
import com.gwtext.client.data.Node;
Line 21... Line 33...
21
import org.tela_botanica.client.modeles.ObservationAsynchroneDAO;
33
import com.gwtext.client.data.Tree;
22
import org.tela_botanica.client.modeles.TransmissionObservationAsynchroneDAO;
34
import com.gwtext.client.widgets.tree.TreeNode;
Line 46... Line 58...
46
	 * Le médiateur associé au modèle
58
	 * Le médiateur associé au modèle
47
	 */
59
	 */
Line 48... Line 60...
48
	
60
	
Line -... Line 61...
-
 
61
	private ObservationMediateur observationMediateur = null ;
-
 
62
	
-
 
63
	/**
-
 
64
	 * La liste des mots clés en cours 
-
 
65
	 */
-
 
66
	private HashMap<String, String> motsCles = new HashMap<String, String>(0);
-
 
67
	
-
 
68
	private Tree arbreMotsCles = new Tree() ;
-
 
69
	
-
 
70
	/**
Line -... Line 71...
-
 
71
	 * La liste des observations affichées en cours (verifier utilité)
Line 49... Line 72...
49
	private ObservationMediateur observationMediateur = null ;
72
	 */
50
	
73
	
51
	
74
	private ListeObservation cacheObservation = new ListeObservation(0) ;
52
	
75
	
Line 373... Line 396...
373
	public void importerObservations() {
396
	public void importerObservations() {
374
		ImportObservationAsynchroneDAO ioDAO = new ImportObservationAsynchroneDAO(this);
397
		ImportObservationAsynchroneDAO ioDAO = new ImportObservationAsynchroneDAO(this);
375
		ioDAO.importerObservations();
398
		ioDAO.importerObservations();
Line 376... Line 399...
376
		
399
		
-
 
400
	}
-
 
401
 
-
 
402
 
-
 
403
 
-
 
404
	public void obtenirArbreMotsCles(Rafraichissable r) {
-
 
405
		
-
 
406
		MotsClesAsynchroneDAO mcoDAO = new MotsClesAsynchroneDAO(this);
-
 
407
		mcoDAO.obtenirListeMotsCles(this);
-
 
408
		
-
 
409
	}
-
 
410
 
-
 
411
	public void rafraichir(Object nouvelleDonnees,
-
 
412
			boolean repandreRaffraichissement) {
-
 
413
		
-
 
414
		if(nouvelleDonnees instanceof JSONArray) {
-
 
415
			// alors on a reçu les informations sur les mots clés
-
 
416
			JSONArray reponse = (JSONArray) nouvelleDonnees;
-
 
417
 
-
 
418
			final int taillemax = reponse.size();
-
 
419
 
-
 
420
			// si le tableau est vide
-
 
421
			if (taillemax == 0) {
-
 
422
				// on crée un arbre vide
-
 
423
				TreeNode root = new TreeNode();
-
 
424
				root.setId("racine");
-
 
425
				root.setText("Tags");
-
 
426
				String[] usObj = { "Tags", "racine" };
-
 
427
				root.setUserObject(usObj);
-
 
428
				arbreMotsCles.setRootNode(root);
-
 
429
			}
-
 
430
 
-
 
431
			// pour chacun des élements du tableau
-
 
432
			for (int j = 0; j < taillemax; j++) {
-
 
433
				// on extrait les élements du tableau
-
 
434
				if (reponse.get(j).isObject() != null) {
-
 
435
					JSONObject noeud = (JSONObject) reponse.get(j);
-
 
436
 
-
 
437
					String id_noeud = noeud.get("cmc_id_mot_cle_utilisateur")
-
 
438
							.isString().stringValue();
-
 
439
					String mot_cle = noeud.get("cmc_mot_cle").isString()
-
 
440
							.stringValue();
-
 
441
					String parent = noeud.get("cmc_id_parent").isString()
-
 
442
							.stringValue();
-
 
443
 
-
 
444
					String[] usObj = { mot_cle, id_noeud };
-
 
445
 
-
 
446
					// et on construit l'arbre à partir de la racine (qui est
-
 
447
					// toujoursl e premier élément)
-
 
448
					if (id_noeud.equals("racine")) {
-
 
449
						TreeNode root = new TreeNode();
-
 
450
						root.setId(id_noeud);
-
 
451
						root.setText(mot_cle);
-
 
452
						root.setUserObject(usObj);
-
 
453
						arbreMotsCles.setRootNode(root);
-
 
454
					} else {
-
 
455
						// et en ajoutant les noeuds un à un (qui sont renvoyé
-
 
456
						// dans l'ordre hierarchique de leur niveau
-
 
457
						// ce qui permet de les traiter séquentiellement)
-
 
458
						TreeNode node = new TreeNode();
-
 
459
						node.setId(id_noeud);
-
 
460
						node.setText(mot_cle);
-
 
461
						node.setChecked(false);
-
 
462
						Node parentNode = arbreMotsCles.getNodeById(parent);
-
 
463
						node.setUserObject(usObj);
-
 
464
						parentNode.appendChild(node);
-
 
465
					}
-
 
466
				}
-
 
467
			}
-
 
468
			// enfin on met à jour l'arbre des mots clés contenu dans le modèle
-
 
469
			rafraichirArbreMotsCles(arbreMotsCles);
-
 
470
			// et on notifie le médiateur de la mise à jour en lui passant une
-
 
471
			// copie des données
-
 
472
			observationMediateur.rafraichirArbreMotsCles(arbreMotsCles);
-
 
473
		}
-
 
474
		
-
 
475
	}
-
 
476
 
-
 
477
	/**
-
 
478
	 * Met à jour l'arbre des mots clés à partir d'un objet
-
 
479
	 * 
-
 
480
	 * @param o
-
 
481
	 *            le nouvel arbre de mots clés
-
 
482
	 */
-
 
483
	public void rafraichirArbreMotsCles(Object o) {
-
 
484
		observationMediateur.transmettreDonnees(o);
-
 
485
		arbreMotsCles = (com.gwtext.client.data.Tree) o;
-
 
486
	}
-
 
487
 
-
 
488
	/**
-
 
489
	 * Met à jour la table de correspondance mots clés / ids à partir d'un objet
-
 
490
	 * 
-
 
491
	 * @param o
-
 
492
	 *            la nouvelle table des mots clés
-
 
493
	 */
-
 
494
	@SuppressWarnings("unchecked")
-
 
495
	public void rafraichirMotsCles(Object o) {
-
 
496
		if (o instanceof HashMap) {
-
 
497
			motsCles = (HashMap<String, String>) o;
-
 
498
		}
-
 
499
	}
-
 
500
	
-
 
501
	/**
-
 
502
	 * Va chercher les mots clés associés à une image dans la liste des images
-
 
503
	 * chargée dans le modèle
-
 
504
	 * 
-
 
505
	 * @param r
-
 
506
	 *            le rafraichissable auquel on enverra les informations
-
 
507
	 * @param id
-
 
508
	 *            l'identifiant de l'image
-
 
509
	 */
-
 
510
	public void obtenirMotsClesId(Rafraichissable r, String id) {
-
 
511
		Observation o = cacheObservation.get(id);
-
 
512
		String motsClesId = o.getMotsCles();
-
 
513
		String[] motsClesIdTab = motsClesId.split(",");
-
 
514
		r.rafraichir(motsClesIdTab, false);
-
 
515
	}
-
 
516
	
-
 
517
	/**
-
 
518
	 * Met à jour les mots clés associés à une image et appelle le DAO pour
-
 
519
	 * synchroniser la base de données
-
 
520
	 * 
-
 
521
	 * @param ids
-
 
522
	 *            les identifiants des images selectionnées
-
 
523
	 * @param motsClesEnCours
-
 
524
	 *            les mots clés à appliquer aux images
-
 
525
	 * @param arbreMC
-
 
526
	 *            l'arbre de mots clés en cours
-
 
527
	 */
-
 
528
	public void mettreAjourMotsCles(String[] ids, String motsClesEnCours,
-
 
529
			com.gwtext.client.data.Tree arbreMC) {
-
 
530
		for (int i = 0; i < ids.length; i++) {
-
 
531
			if (cacheObservation.containsKey(ids[i])) {
-
 
532
				Observation o = (Observation) cacheObservation.get(ids[i]);
-
 
533
				o.setMotsCles(motsClesEnCours);
-
 
534
 
-
 
535
				ObservationAsynchroneDAO oDao = new ObservationAsynchroneDAO(this);
-
 
536
				oDao.modifier(this,observationMediateur.getIdentifiant(),o);
-
 
537
			}
-
 
538
		}
-
 
539
 
-
 
540
		rafraichirArbreMotsCles(arbreMC);
-
 
541
	}
-
 
542
	
-
 
543
	/**
-
 
544
	 * Ajoute un mot clé à l'arbre des mots clés local et appelle le DAO qui
-
 
545
	 * fait la mise à jour de l'arbre des mots clés dans la base
-
 
546
	 * 
-
 
547
	 * @param n
-
 
548
	 *            le nouveau noeud contenant le mot clé
-
 
549
	 * @param arbreMC
-
 
550
	 *            l'arbre des mots cles en cours
-
 
551
	 */
-
 
552
	public void ajouterMotCleDansArbre(TreeNode n,
-
 
553
			com.gwtext.client.data.Tree arbreMC) {
-
 
554
		MotsClesAsynchroneDAO MCDao = new MotsClesAsynchroneDAO(this);
-
 
555
 
-
 
556
		String[] usObj = (String[]) n.getUserObject();
-
 
557
		String motCle = usObj[0];
-
 
558
		String id = usObj[1];
-
 
559
		String parentId = "";
-
 
560
 
-
 
561
		if (!id.equals("racine")) {
-
 
562
			String[] parentUsObj = (String[]) n.getParentNode().getUserObject();
-
 
563
			parentId = parentUsObj[1];
-
 
564
		} else {
-
 
565
			parentId = "racine";
-
 
566
		}
-
 
567
 
-
 
568
		rafraichirArbreMotsCles(arbreMC);
-
 
569
 
-
 
570
		String nouveauMotCle = "&identifiant=" + getIdentifiant() + "&motcle="
-
 
571
				+ motCle + "&id=" + id + "&parent=" + parentId;
-
 
572
		MCDao.ajouterBaseDeDonnees(nouveauMotCle);
-
 
573
	}
-
 
574
 
-
 
575
	/**
-
 
576
	 * Supprime un noeud de l'arbre des mots clés et appelle le DAO qui va
-
 
577
	 * supprimer les mots clés associés dans la base
-
 
578
	 * 
-
 
579
	 * @param n
-
 
580
	 *            le noeud à supprimer
-
 
581
	 * @param arbreMC
-
 
582
	 *            l'arbre des mots clés en cours
-
 
583
	 */
-
 
584
	public void supprimerMotCleDansArbre(TreeNode n, Tree arbreMC) {
-
 
585
 
-
 
586
		MotsClesAsynchroneDAO MCDao = new MotsClesAsynchroneDAO(this);
-
 
587
 
-
 
588
		String[] usObj = (String[]) n.getUserObject();
-
 
589
		String id = usObj[1];
-
 
590
 
-
 
591
		MCDao.supprimerBaseDeDonnees(id);
-
 
592
 
-
 
593
	}
-
 
594
 
-
 
595
	/**
-
 
596
	 * Modifie le noeud donné dans l'arbre des mots clés en cours et appelle le
-
 
597
	 * DAO qui synchronise la modification dans la base de données
-
 
598
	 * 
-
 
599
	 * @param n
-
 
600
	 *            le noeud modifié
-
 
601
	 * @param arbreMC
-
 
602
	 *            l'arbre des mots clés en cours
-
 
603
	 */
-
 
604
	public void modifierMotCleDansArbre(TreeNode n, Tree arbreMC) {
-
 
605
 
-
 
606
		MotsClesAsynchroneDAO MCDao = new MotsClesAsynchroneDAO(this);
-
 
607
 
-
 
608
		String[] usObj = (String[]) n.getUserObject();
-
 
609
		String motCle = usObj[0];
-
 
610
		String id = usObj[1];
-
 
611
		String parentId = "";
-
 
612
 
-
 
613
		if (!id.equals("racine")) {
-
 
614
			String[] parentUsObj = (String[]) n.getParentNode().getUserObject();
-
 
615
			parentId = parentUsObj[1];
-
 
616
		} else {
-
 
617
			parentId = "racine";
-
 
618
		}
-
 
619
 
-
 
620
		rafraichirArbreMotsCles(arbreMC);
-
 
621
 
-
 
622
		String motCleModifie = "&motcle=" + motCle + "&id=" + id + "&parent="
-
 
623
				+ parentId;
-
 
624
		MCDao.modifierBaseDeDonnees(motCleModifie);
-
 
625
 
-
 
626
	}
-
 
627
 
-
 
628
	/**
-
 
629
	 * Deplace un noeud dans l'arbre des mots cles et appelle le DAO qui
-
 
630
	 * reorganise l'arbre dans la base de donnees suivant le changement
-
 
631
	 * 
-
 
632
	 * @param n
-
 
633
	 *            le noeud deplace (et son sous arbre associe)
-
 
634
	 * @param arbreMC
-
 
635
	 *            l'arbre des mots cles en cours
-
 
636
	 */
-
 
637
	public void deplacerMotCleDansArbre(TreeNode n, Tree arbreMC) {
-
 
638
		MotsClesAsynchroneDAO MCDao = new MotsClesAsynchroneDAO(this);
-
 
639
 
-
 
640
		String[] usObj = (String[]) n.getUserObject();
-
 
641
		String motCle = usObj[0];
-
 
642
		String id = usObj[1];
-
 
643
		String parentId = "";
-
 
644
		if (!id.equals("racine")) {
-
 
645
			String[] parentUsObj = (String[]) n.getParentNode().getUserObject();
-
 
646
			parentId = parentUsObj[1];
-
 
647
		} else {
-
 
648
			parentId = "racine";
-
 
649
		}
-
 
650
 
-
 
651
		rafraichirArbreMotsCles(arbreMC);
-
 
652
 
-
 
653
		String motCleModifie = "&motcle=" + motCle + "&id=" + id + "&parent="
-
 
654
				+ parentId;
-
 
655
		MCDao.deplacerBaseDeDonnees(motCleModifie);
-
 
656
	}
-
 
657
	
-
 
658
	/**
-
 
659
	 * Ajoute un nouveau mot clés à la liste des mots clés locale
-
 
660
	 * 
-
 
661
	 * @param text
-
 
662
	 *            le mot clé
-
 
663
	 * @param id
-
 
664
	 *            l'identifiant du mot clé
-
 
665
	 */
-
 
666
	public void mettreAjourMotsClesId(String text, String id) {
-
 
667
		motsCles.put(id, text);
-
 
668
	}
-
 
669
	
-
 
670
	public void rafraichirCacheObservation(ListeObservation li) {
-
 
671
		cacheObservation = li ;
-
 
672
	}
-
 
673
 
-
 
674
	public ListeObservation getCacheObservation() {
-
 
675
		return cacheObservation ;
-
 
676
	}
-
 
677
 
Line 377... Line 678...
377
	}
678