Subversion Repositories eFlore/Applications.coel

Rev

Rev 1846 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.vues.personne;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.tela_botanica.client.ComposantClass;
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.composants.ChampMultiValeurs;
import org.tela_botanica.client.composants.ChampMultiValeursImage;
import org.tela_botanica.client.composants.ChampMultiValeursMultiTypes;
import org.tela_botanica.client.composants.ChampMultiValeursMultiTypesPaginable;
import org.tela_botanica.client.composants.HashMapComposants;
import org.tela_botanica.client.configuration.Configuration;
import org.tela_botanica.client.images.Images;
import org.tela_botanica.client.interfaces.Rafraichissable;

import org.tela_botanica.client.modeles.Information;
import org.tela_botanica.client.modeles.MenuApplicationId;
import org.tela_botanica.client.modeles.Valeur;
import org.tela_botanica.client.modeles.ValeurListe;
import org.tela_botanica.client.modeles.personne.Personne;
import org.tela_botanica.client.modeles.personne.PersonneAsyncDao;
import org.tela_botanica.client.modeles.personne.PersonneListe;
import org.tela_botanica.client.modeles.publication.Publication;
import org.tela_botanica.client.modeles.publication.PublicationAPersonneListe;
import org.tela_botanica.client.modeles.publication.PublicationListe;
import org.tela_botanica.client.synchronisation.Sequenceur;
import org.tela_botanica.client.util.Debug;
import org.tela_botanica.client.util.Pattern;
import org.tela_botanica.client.util.UtilDate;
import org.tela_botanica.client.util.UtilString;
import org.tela_botanica.client.vues.Formulaire;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.PagingLoadResult;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SortDir;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;

import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.binding.FormBinding;

import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.KeyListener;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.event.WidgetListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;

import com.extjs.gxt.ui.client.widget.ContentPanel;
import org.tela_botanica.client.composants.InfoLogger;
import org.tela_botanica.client.composants.pagination.Proxy;
import org.tela_botanica.client.composants.pagination.ProxyValeur;

import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.Text;

import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.Validator;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.client.Window;

public class PersonneForm extends Formulaire implements Rafraichissable {

        // VARIABLES
        private TabItem tiIdentite, tiAdresses, tiInfosNat;
        PersonneFormPublication tiPubli;
        private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
        protected Personne personneSelectionnee, personneSauvegarde = null;
        
        //hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite
        private HashMapComposants hmIdentite = new HashMapComposants();
        private HashMapComposants hmAdresse = new HashMapComposants();
        private HashMapComposants hmInfosNat = new HashMapComposants();
        private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
        private FormData fd100 = new FormData("95%");
        
        private Button enregistrer, enregistrerEtRevenir;
        
        private Personne personne = null;
        private String personneId = null;
        private FormBinding binding = null;
        
        //Gestion du mode synchrone
        private Sequenceur sequenceur;
        
        //Publi
        private ComboBox<Publication> cbPubli;
        private ListStore<Publication> storePubli;
        
        // Gestion de la vérification des doublons
        private boolean verificationDoublonEffectuee = false;
        
        // CONSTRUCTEUR  
        public PersonneForm(Mediateur mediateurCourrant, String personneId) {
                initialiserPersonneForm(mediateurCourrant, personneId);
        }
        
        public PersonneForm(Mediateur mediateurCourrant, String personneId, Rafraichissable vueARafraichirApresValidation) {
                vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
                initialiserPersonneForm(mediateurCourrant, personneId);         
        }
        
        private void initialiserPersonneForm(Mediateur mediateurCourrant, String personneIdCourrant) {
                
                //Initialisation du séquenceur
                sequenceur = new Sequenceur();
                personne = new Personne();
                personne.setId(personneIdCourrant);
                personneId = personneIdCourrant;
                
                String modeDeCreation = (UtilString.isEmpty(personneId) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
                initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.PERSONNE);

                initialiserComposants();
                genererTitreFormulaire();
                
                mediateur.obtenirListeValeurEtRafraichir(this, "relationPersonnePublication", sequenceur);
                mediateur.obtenirListeValeurEtRafraichir(this, "relationPersonnePublication", null);
                if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
                        mediateur.selectionnerPersonne(this, personne.getId(), sequenceur);
                }
        }
        
        private void genererTitreFormulaire() {
                String titre = i18nC.personneModeAjout();
                if (mode.equals(Formulaire.MODE_MODIFIER)) {
                         titre = i18nC.personneModeModifier()+" - "+i18nC.id()+": "+personneId;
                }
                panneauFormulaire.setHeadingHtml(titre);
        }
        
        public void initialiserComposants()     {
                personneSelectionnee = new Personne();
                personneSauvegarde = new Personne();
                
                initialiserOnglets();   
                
                creerComposantsIdentite();
                creerComposantsAdresse();
                creerComposantsInfosNat();
                //creerComposantsPubli();
                
                binderPersonne(personneSelectionnee);
        }
        
        /**
         * Crée les onglets identité, adresse et informations naturaliste
         * 
         * */
        public void initialiserOnglets()        {
                //TabPanel
                TabPanel formulaireOnglets = new TabPanel();
                
                //Tab 1 : identite
                tiIdentite = creerOnglet(i18nC.personneIdentite(), "tiIdentite");
                tiIdentite.setStyleAttribute("padding", "0");
                formulaireOnglets.add(tiIdentite);
                
                //Tab 2 : Adresse
                tiAdresses = creerOnglet(i18nC.adresse(), "tiAdresses");
                formulaireOnglets.add(tiAdresses);
                
                //Tab 3 : Infos Naturalistes
                tiInfosNat = creerOnglet(i18nC.personneInfoNat(), "tiInfosNat");
                formulaireOnglets.add(tiInfosNat);
                
                //Tab 4 : Publications
                tiPubli = new PersonneFormPublication(this);
                formulaireOnglets.add(tiPubli);
        
                getFormulaire().add(formulaireOnglets);
        }
        
        /**
         * Crée les widgets pour l'onglet identité
         * 
         * */
        
        
        public void creerComposantsIdentite()   {
                // Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite
                LayoutContainer left = new LayoutContainer();
                left.setLayout(new FormLayout());
                left.setStyleAttribute("padding", "15px");
                
                LayoutContainer right = new LayoutContainer();
                right.setLayout(new FormLayout());
                right.setStyleAttribute("padding", "15px");
                
                LayoutContainer main = new LayoutContainer();
                
                main.add(left, new ColumnData(.45));
                main.add(right, new ColumnData(.50));
                
                main.setLayout(new ColumnLayout());
                main.setHeight("100%");
                main.setScrollMode(Scroll.AUTO);
                
                // Création des champs
                FormLayout formLayout = new FormLayout();
                formLayout.setLabelAlign(LabelAlign.LEFT);
                        
                //+------------------------------------------------------------------------------------------------------------+
                // Fieldset NOM
                FieldSet fsNoms = new FieldSet();
                fsNoms.setHeadingHtml("Noms");
                fsNoms.setLayout(formLayout); 
                                        
                // Nom complet : Affiché que si valeurs saisies
                LabelField nomComplet = new LabelField();
                nomComplet.setFieldLabel(i18nC.personneNomComplet() +" :");
                nomComplet.hide();
                                
                fsNoms.add(nomComplet);
                hmIdentite.put("nomComplet", nomComplet);
                        
                //Préfixe
                ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
                ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
                cbPrefixe.setStore(storePrefixe);
                cbPrefixe.setDisplayField("nom");
                cbPrefixe.setEmptyText("Choisissez le préfixe:");
                cbPrefixe.setFieldLabel("Prefix");
                
                fsNoms.add(cbPrefixe);
                hmIdentite.put("cbPrefixe", cbPrefixe);
                
                mediateur.obtenirListeValeurEtRafraichir(this, "prefixe", sequenceur);

                //Prénom
                TextField<String> tfPrenom = new TextField<String>();
                tfPrenom.setFieldLabel("Prénom");
                tfPrenom.setName("prenom");

                fsNoms.add(tfPrenom, new FormData(300, 0));
                hmIdentite.put("tfPrenom", tfPrenom);
                
                tfPrenom.addListener(Events.Blur, creerEcouteurNomPrenomExistant());
                tfPrenom.addListener(Events.Change, new Listener<BaseEvent>() {
                        @Override
                        public void handleEvent(BaseEvent be) {
                                verificationDoublonEffectuee = false;   
                        }
                });

                //Nom
                TextField<String> tfNom = new TextField<String>();
                tfNom.setFieldLabel("Nom");
                tfNom.setAllowBlank(false);
                tfNom.setName("nom");
                tfNom.addStyleName(ComposantClass.OBLIGATOIRE);
                tfNom.addListener(Events.Valid, creerEcouteurChampObligatoire());
                
                tfNom.addListener(Events.Blur, creerEcouteurNomPrenomExistant());
                tfNom.addListener(Events.Change, new Listener<BaseEvent>() {
                        @Override
                        public void handleEvent(BaseEvent be) {
                                verificationDoublonEffectuee = false;   
                        }
                });
                
                fsNoms.add(tfNom, new FormData(300, 0));
                hmIdentite.put("tfNom", tfNom);
                
                //Suffixe
                ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
                ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
                cbSuffixe.setStore(storeSuffixe);
                cbSuffixe.setFieldLabel("Suffixe");
                cbSuffixe.setDisplayField("nom");
                cbSuffixe.setEmptyText("Choisissez un suffixe:");
                
                fsNoms.add(cbSuffixe);                  
                hmIdentite.put("cbSuffixe", cbSuffixe);
                
                mediateur.obtenirListeValeurEtRafraichir(this, "suffixes", sequenceur);

                TextField<String> tfAbreviation = new TextField<String>();
                tfAbreviation.setFieldLabel("Abréviation");
                tfAbreviation.setName("abreviation");
                
                fsNoms.add(tfAbreviation);
                hmIdentite.put("tfAbreviation", tfAbreviation);

                TableLayout layoutAutreNoms = new TableLayout(2);
                layoutAutreNoms.setCellVerticalAlign(VerticalAlignment.TOP);
                LayoutContainer autresNoms = new LayoutContainer(layoutAutreNoms);
                ChampMultiValeurs nomAutre = new ChampMultiValeurs("Autres noms",150);
                hmIdentite.put("nomAutre", nomAutre);
                autresNoms.add(nomAutre, new TableData("200px", "15px"));
                
                ChampMultiValeurs abreviationAutre = new ChampMultiValeurs("Autres abréviation",150);
                hmIdentite.put("abreviationAutre", abreviationAutre);
                autresNoms.add(abreviationAutre, new TableData("200px", "15px"));
                fsNoms.add(autresNoms);
                                                                                
                left.add(fsNoms);
                
                //+------------------------------------------------------------------------------------------------------------+
                // Fieldset NAISSANCE ET DÉCÈS
                FieldSet fsNaissanceEtDeces = new FieldSet();
                fsNaissanceEtDeces.setHeadingHtml("Naissance et Décès");
                fsNaissanceEtDeces.setLayout(new ColumnLayout()); 
                
                formLayout = new FormLayout();
                formLayout.setLabelAlign(LabelAlign.TOP);
                LayoutContainer containerNaissance = new LayoutContainer(formLayout);
                                
                //Remplacement du DateField par un champ texte
                TextField tfDateNaissance = new TextField();
                tfDateNaissance.setFieldLabel("Date de naissance");
                containerNaissance.add(tfDateNaissance);
                hmIdentite.put("tfDateNaissance", tfDateNaissance);
                
                // Lieu naissance
                TextField<String> tfLieuNaissance = new TextField<String>();
                tfLieuNaissance.setFieldLabel("Lieu de naissance");
                tfLieuNaissance.setName("naissance_lieu");
                
                containerNaissance.add(tfLieuNaissance);
                hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
                
                fsNaissanceEtDeces.add(containerNaissance, new ColumnData(.5));
                left.add(fsNaissanceEtDeces);
                
                formLayout = new FormLayout();
                formLayout.setLabelAlign(LabelAlign.TOP);
                LayoutContainer containerDeces = new LayoutContainer(formLayout);
                
                Radio rbEstDecedee = new Radio();
                rbEstDecedee.setId("ce_deces");
                
                rbEstDecedee.setBoxLabel("oui");
                rbEstDecedee.setValueAttribute("1");
                rbEstDecedee.setId("rbEstD");
                
                rbEstDecedee.addListener(Events.Change, new Listener<ComponentEvent>() {
                                                
                        public void handleEvent(ComponentEvent be) {
                                if(((Radio) be.getComponent()).getValue().equals(true)) {
                                        hmIdentite.getTextField("tfDateDeces").setVisible(true);
                                        hmIdentite.getTextField("tfLieuDeces").setVisible(true);
                                } else  {
                                        TextField tfDateDeces = hmIdentite.getTextField("tfDateDeces");
                                        tfDateDeces.setValue(null);
                                        tfDateDeces.setVisible(false);
                                        
                                        TextField tfLieuDeces = hmIdentite.getTextField("tfLieuDeces");
                                        tfLieuDeces.setValue(null);
                                        tfLieuDeces.setVisible(false);
                                }
                        }       
                });
                                        
                TextField tfDateDeces = new TextField();
                tfDateDeces.setFieldLabel("Date de décès");
                tfDateDeces.setVisible(false);

                containerDeces.add(tfDateDeces);
                hmIdentite.put("tfDateDeces", tfDateDeces);

                TextField<String> tfLieuDeces = new TextField<String>();
                tfLieuDeces.setFieldLabel("Lieu de décès");
                tfLieuDeces.setName("deces_lieu");
                tfLieuDeces.setVisible(false);
                
                containerDeces.add(tfLieuDeces);
                hmIdentite.put("tfLieuDeces", tfLieuDeces);
                hmIdentite.put("rbEstDecedee", rbEstDecedee);
                
                Radio rbNestPasDecedee = new Radio();
                rbNestPasDecedee.setValueAttribute("0");
                rbNestPasDecedee.setBoxLabel("non");
                rbNestPasDecedee.setValue(true);
                        
                RadioGroup rbgDeces = new RadioGroup();
                rbgDeces.setId("rbgDeces");
                                
                rbgDeces.setFieldLabel("Est décédée");
                rbgDeces.add(rbEstDecedee);
                rbgDeces.add(rbNestPasDecedee);
                hmIdentite.put("rbgDeces", rbgDeces);
                
                containerDeces.add(rbgDeces);
                
                fsNaissanceEtDeces.add(containerDeces, new ColumnData(.5));
                tiIdentite.add(main);
                
                //+------------------------------------------------------------------------------------------------------------+
                // Fieldset CONTACT
                FieldSet fsContact = new FieldSet();
                fsContact.setHeadingHtml("Contact");
                fsContact.setWidth("95%");
                fsContact.setLayout(new RowLayout());
                
                ChampMultiValeursMultiTypes telephones = new ChampMultiValeursMultiTypes("Téléphones", 180, 100);
                telephones.initialiserType("tel");
                fsContact.add(telephones, new FormData(450, 0));
                hmIdentite.put("telephones", telephones);
                
                ChampMultiValeurs courriels = new ChampMultiValeurs("Courriels", 280);
                courriels.setValidation(Pattern.email, "moi@domaine.fr");
                fsContact.add(courriels, new FormData(450, 0));
                hmIdentite.put("courriels", courriels);
                
                LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout());
                fsContact.add(lcCourrielContainer);
                hmIdentite.put("lcCourrielContainer", lcCourrielContainer);

                fsContact.add(new Text(""));
                
                ChampMultiValeurs sites = new ChampMultiValeurs("Sites web");
                sites.setWidth("95%");
                sites.setValeurParDefaut("http://");
                sites.setValidation(Pattern.url, "http://www.monsite.com");
                fsContact.add(sites);
                hmIdentite.put("sites", sites);
                
                right.add(fsContact);
                
                //+------------------------------------------------------------------------------------------------------------+
                // Fieldset AUTRES INFOS
                FieldSet fsAutresInfos = new FieldSet();
                fsAutresInfos.setHeadingHtml("Autres informations");
                fsAutresInfos.setWidth("95%");
        
                formLayout = new FormLayout();
                formLayout.setLabelAlign(LabelAlign.LEFT);
                fsAutresInfos.setLayout(formLayout); 
                        
                                
                formLayout = new FormLayout();
                formLayout.setLabelAlign(LabelAlign.TOP);
                LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout);
                                
                ListStore<Valeur> storeSexe = new ListStore<Valeur>();
                ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
                cbSexe.setStore(storeSexe);
                cbSexe.setFieldLabel("Sexe");
                cbSexe.setDisplayField("nom");
                cbSexe.setEmptyText("Choisissez le sexe:");
                cbSexe.setTypeAhead(true);
                cbSexe.setTriggerAction(TriggerAction.ALL);  
                
                FormData fd = new FormData();
                fd.setWidth(100);
                lcAutreInformations1.add(cbSexe, fd);                   
                hmIdentite.put("cbSexe", cbSexe);
        
                mediateur.obtenirListeValeurEtRafraichir(this, "sexe", sequenceur);                     
                
                //Description
                final TextArea taDescription = new TextArea();
                taDescription.setEmptyText("Saisissez une description");
                taDescription.setFieldLabel("Description");
                taDescription.setName("description");
                
                lcAutreInformations1.add(taDescription, new FormData(300, 200));
                hmIdentite.put("taDescription", taDescription);
                
                fsAutresInfos.add(lcAutreInformations1);
                                
                // Logo
                LayoutContainer lcLogoUrl = new LayoutContainer();
                hmIdentite.put("lcLogoUrl", lcLogoUrl);
                
                final ChampMultiValeursImage logo = new ChampMultiValeursImage(i18nC.personneLogos());
                logo.setImageHeight("150px");
                logo.setValeurParDefaut("http://");
                logo.setValidation(Pattern.url, "http://www.monsite.com/mon_image.jpg");
                logo.setValeurBoutonSupprimer("Supprimer");
                logo.setWidth("95%");
                hmIdentite.put("logos", logo);
                
                lcLogoUrl.add(logo);
                
                fsAutresInfos.add(logo);
                
                LayoutContainer lcAutreInformations2 = new LayoutContainer(new ColumnLayout());
                hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
                fsAutresInfos.add(lcAutreInformations2);
                        
                right.add(fsAutresInfos);
                
                //+------------------------------------------------------------------------------------------------------------+
                // Ajout des évènements saisi
                KeyListener klNoms = new KeyListener()  {
                        public void componentKeyUp(ComponentEvent ev)   {
                                rafraichir(null);       
                        }                               
                };
                
                SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
                        public void selectionChanged(SelectionChangedEvent se) {
                                rafraichir(null);
                        }
                };
                                                
                cbPrefixe.addSelectionChangedListener(selectionChange);
                cbPrefixe.addKeyListener(klNoms);
                tfPrenom.addKeyListener(klNoms);
                tfNom.addKeyListener(klNoms);
                cbSuffixe.addSelectionChangedListener(selectionChange);         
                        
        }
        
        public void creerComposantsAdresse()    {
                // Gauche
                LayoutContainer left = new LayoutContainer();
                left.setLayout(new FormLayout());
                left.setStyleAttribute("padding", "15px");
                // Droite
                LayoutContainer right = new LayoutContainer();
                right.setLayout(new FormLayout());
                
                // Principal
                LayoutContainer main = new LayoutContainer();
                main.setLayout(new TableLayout(2));
                
                // Ajout au principal
                main.add(left);
                main.add(right);        
                
                TextField<String> tfAdresse1 = new TextField();
                tfAdresse1.setFieldLabel("Adresse");
                tfAdresse1.setName("adresse_01");
                left.add(tfAdresse1, fd100);
                hmAdresse.put("tfAdresse1", tfAdresse1);
                
                ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
                cbPays.setFieldLabel("Pays");
                cbPays.setDisplayField("nom");
                cbPays.setEmptyText("Sélectionnez le pays:");
                
                ListStore<Valeur> storePays = new ListStore<Valeur>();
                cbPays.setStore(storePays);
                
                right.add(cbPays, fd100);
                hmAdresse.put("cbPays", cbPays);
                
                TextField<String> tfBoitePostale = new TextField<String>();
                tfBoitePostale.setFieldLabel("Boite postale");
                tfBoitePostale.setName("bp");
                
                left.add(tfBoitePostale, fd100);
                hmAdresse.put("tfBoitePostale", tfBoitePostale);
                
                TextField<Integer> tfCodePostal = new TextField<Integer>();
                tfCodePostal.setFieldLabel("Code postal");
                tfCodePostal.setName("code_postal");
                
                right.add(tfCodePostal, fd100);
                hmAdresse.put("tfCodePostal", tfCodePostal);
                
                TextField tfVille = new TextField();
                tfVille.setFieldLabel("Ville");
                tfVille.setName("ville");
                
                right.add(tfVille, fd100);
                hmAdresse.put("tfVille", tfVille);
                
                // MAJ ComboBox
                mediateur.obtenirListeValeurEtRafraichir(this, "pays", sequenceur);
                
                FieldSet fsAdresse = new FieldSet();
                fsAdresse.setHeadingHtml("Adresse personnelle");
                fsAdresse.add(main);
                
                tiAdresses.add(fsAdresse);
        }
        
        public void creerComposantsInfosNat()   {
                
                FormLayout fl = new FormLayout();
                fl.setLabelAlign(LabelAlign.TOP);
                FieldSet fsInfosNat = new FieldSet();
                fsInfosNat.setLayout(fl);
                fsInfosNat.setTitle("Informations Naturaliste");

                TextArea taBiographie = new TextArea();
                taBiographie.setFieldLabel("Vie et renommée de l'auteur");
                taBiographie.setWidth("400");
                taBiographie.setName("biographie");
                fsInfosNat.add(taBiographie, new FormData(800, 200));

                ChampMultiValeurs specialite = new ChampMultiValeurs(i18nC.personneSpecialite());
                fsInfosNat.add(specialite);
                hmInfosNat.put("specialite", specialite);

                ModelType typeTypes = new ModelType();
                typeTypes.setRoot("valeurs");
                typeTypes.setTotalName("nbElements");
                typeTypes.addField("cmlv_nom");
                typeTypes.addField("cmlv_id_valeur");
                typeTypes.addField("cmlv_abreviation");
                typeTypes.addField("cmlv_description");
                
                String displayNameTypes = "cmlv_nom";
                String nomListeTypes = "pays";
                ProxyValeur<ModelData> proxyTypes = new ProxyValeur<ModelData>(nomListeTypes, null);
                
                ChampMultiValeursMultiTypesPaginable recolte = new ChampMultiValeursMultiTypesPaginable(i18nC.personneRecolte(), 450, false, null, null, null, typeTypes, proxyTypes, displayNameTypes);
                
                hmInfosNat.put("recolte", recolte);
                fsInfosNat.add(recolte);
                tiInfosNat.add(fsInfosNat);
        }
        
        public void creerComposantsPubli(){
                //Création des composants de l'onglet publication

                ContentPanel cp = new ContentPanel();
                cp.setHeadingHtml("Publications dont la personne est le sujet");
                cp.setIcon(Images.ICONES.table());
                cp.setLayout(new FitLayout());
                cp.setFrame(true);
                
                ToolBar toolBar = new ToolBar();

                Button ajouterPubli = new Button("Ajouter");
                ajouterPubli.setIcon(Images.ICONES.vcardAjouter());
                ajouterPubli.addSelectionListener(new SelectionListener<ButtonEvent>() {  
                        @Override  
                        public void componentSelected(ButtonEvent ce) {  
                                /*StructureAPersonne membreDuPersonnel = new StructureAPersonne("", StructureAPersonne.ROLE_EQUIPE, StructureAPersonne.ETAT_AJOUTE);
                                ajouterMembreAGrillePersonnel(membreDuPersonnel);*/
                        }  
                });
                toolBar.add(ajouterPubli);
                
                toolBar.add(new SeparatorToolItem());
                
                Button supprimerPubli = new Button("Supprimer");
                supprimerPubli.setIcon(Images.ICONES.vcardSupprimer());
                supprimerPubli.addSelectionListener(new SelectionListener<ButtonEvent>() {  
                        @Override
                        public void componentSelected(ButtonEvent ce) {
                                /*StructureAPersonne personne = grillePersonnel.getSelectionModel().getSelectedItem();
                                if (personne != null) {
                                        // Ajout de la personne supprimée à la liste
                                        if (personne.getIdPersonne() != null && !personne.getIdPersonne().equals("")) {
                                                personnelSupprime.put(personne.getId(), personne);
                                        }
        
                                        // Suppression de l'enregistrement de la grille
                                        grillePersonnel.getStore().remove(personne);
                                        
                                        // Désactivation du bouton supprimer si la grille contient plus d'élément
                                        if (grillePersonnel.getStore().getCount() == 0) {  
                                                //TODO : check : Item -> component
                                                ce.getComponent().disable();  
                                        }
                                }*/
                                Window.alert("supprimer");
                        }   
                });
                toolBar.add(supprimerPubli);
                
                toolBar.add(new SeparatorToolItem());
                
                Button rafraichirPersonnelBtn = new Button("Rafraichir");
                rafraichirPersonnelBtn.setIcon(Images.ICONES.rafraichir());
                rafraichirPersonnelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {  
                        @Override
                        public void componentSelected(ButtonEvent ce) {
                                //rafraichirPersonnel();
                                Window.alert("rafraichir");
                        }   
                });
                toolBar.add(rafraichirPersonnelBtn);
                
                //Ajout d'une ComboBox
                storePubli = new ListStore<Publication>();
                storePubli.add(new ArrayList<Publication>());
                
                cbPubli = new ComboBox<Publication>();
                cbPubli.setWidth(200);
                cbPubli.setEmptyText("Chercher une publication existante...");
                cbPubli.setTriggerAction(TriggerAction.ALL);  
                cbPubli.setEditable(true);
                cbPubli.setDisplayField("fmt_nom_complet");
                cbPubli.setStore(storePubli);
                cbPubli.addKeyListener(new KeyListener() {
                        
                        public void componentKeyUp(ComponentEvent ce) {
                                if (!ce.isNavKeyPress() && cbPubli.getRawValue() != null && cbPubli.getRawValue().length() > 0) {
                                        rafraichirPublicationsExistante(cbPubli.getRawValue());
                                }
                        }
                        
                });
                
                toolBar.add(cbPubli);
                toolBar.add(new SeparatorToolItem());
                cp.setTopComponent(toolBar);  
                
                
                tiPubli.add(cp);
        }

        public void rafraichirPublicationsExistante(String nomPubli)    {               
                nomPubli +="%";
                mediateur.selectionnerPublicationParNomComplet(this, nomPubli);
        }
        
        /**
         * Ajouter le bouton annuler à la barre d'outils donnée
         * 
         * @param barreOutils la barre d'outils à modifier
         * */
        public static void ajouterBoutonAnnuler(ButtonBar barreOutils)  {
                
                // Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
                Button annuler = new Button("Revenir à la liste");
                annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {  
                        public void componentSelected(ButtonEvent ce) {  
                                ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
                        }  
                });
                annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
                barreOutils.add(annuler);
        }
        
        // RAFRAICHISSEMENT DU PANNEAU

        public void rafraichir(Object nouvellesDonnees) {
                
                if (nouvellesDonnees instanceof PublicationAPersonneListe)      {                                       
                        Information info = new Information();
                        info.setType("publication_liees");
                        info.setDonnee(0, (PublicationAPersonneListe) nouvellesDonnees);
                        tiPubli.rafraichir(info);
                        
                } else if (nouvellesDonnees instanceof ValeurListe) {
                        ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
                        // Créer une liste de valeurs
                        List<Valeur> liste = new ArrayList<Valeur>();
                        for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
                                liste.add(listeValeurs.get(it.next()));
                        }
                        if (listeValeurs.getId().equals(config.getListeId("relationPersonnePublication")))      {
                                tiPubli.rafraichir(nouvellesDonnees);                           
                        } else if (listeValeurs.getId().equals(config.getListeId("prefixe")))   {
                                remplirCombobox("cbPrefixe", liste, "hmIdentite");
                        } else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
                                remplirCombobox("cbSuffixe", liste, "hmIdentite");
                        } else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
                                
                                //Ajout de la valeur "Inconnu"
                                ComboBox<Valeur> cbSexe = hmAdresse.getComboBoxValeur("cbSexe");
                                Valeur inconnu = new Valeur();
                                inconnu.set("nom", "Inconnu");
                                inconnu.set("id", "0");
                                liste.add(0, inconnu);
                                
                                remplirCombobox("cbSexe", liste, "hmIdentite");
                                
                                /*List<Valeur> selection = new LinkedList<Valeur>();
                                selection.add(inconnu);
                                cbSexe.setSelection(s);*/
                                
                                
                        } else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
                                remplirCombobox("cbTelephone", liste, "hmIdentite");

                                //Préselection du tél
                                ComboBox<Valeur> cbTelephone = hmIdentite.getComboBoxValeur("cbTelephone");
                                cbTelephone.setValue(liste.get(1));
                        } else if (listeValeurs.getId().equals(config.getListeId("pays")))      {
                                remplirCombobox("cbPays", liste, "hmAdresse");
                        }
                } else if (nouvellesDonnees instanceof PublicationListe)        {
                        PublicationListe publicationListe = (PublicationListe) nouvellesDonnees;
                        List<Publication> liste = publicationListe.toList();
                        storePubli.removeAll();
                        storePubli.add(liste);
                        cbPubli.setStore(storePubli);
                } else if (nouvellesDonnees instanceof Information)     {                       
                        Information info = (Information) nouvellesDonnees;
                        if (info.getType().equals("ajout_personne"))    {
                                if (info.getDonnee(0) != null) {
                                        personneSelectionnee.setId(info.getDonnee(0).toString());
                                        GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
                                        this.personne = personneSelectionnee;
                                        this.personneId = personneSelectionnee.getId();
                                        InfoLogger.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
                                        repandreRafraichissement();
                                        if (clicBoutonvalidation)       {
                                                mediateur.clicMenu(menuIdCourant);
                                        } else {
                                                this.mode = MODE_MODIFIER;
                                        }
                                } else {
                                        InfoLogger.display("Enregistrement", info.getMessages().toString());
                                }
                        } else if (info.getType().equals("modification_personne"))      {
                                InfoLogger.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
                                repandreRafraichissement();
                                controlerFermeture();
                        } else if (info.getType().equals("maj_utilisateur"))    {
                                gererEtatActivationBouton();
                        } else if (info.getDonnee(0) instanceof PersonneListe)  {
                                
                                Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
                                Iterator itPersonneListe = colPersonneListe.iterator();
                                Personne personne = (Personne) itPersonneListe.next();
                                
                                //TODO : Je vois pas l'intérêt des lignes ci dessous..
                                personneSauvegarde = new Personne();
                                personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
                                
                                binderPersonne(personne);
                                
                                mettreAJourPersonne(personne);
                                
                                this.personne = personne;
                                this.personneId = personne.getId();
                                
                                tiPubli.rafraichirInformation(new Information("personne"));
                                
                                nouvellesDonnees = null;
                        } else {
                                InfoLogger.display("messages", info.getMessages().toString());
                        }
                }
                
                if (nouvellesDonnees == null) {                 
                        ComboBox<Valeur> cb= hmIdentite.getComboBoxValeur("cbPrefixe");
                        
                        //Met à jour le nom Complet du formulaire
                        String valeurRetour = "";
                        
                        // Prefixe
                        String prefixe = "";
                        Valeur valPrefixe = cb.getValue();
                        
                        if (valPrefixe != null) {
                                prefixe = valPrefixe.getNom();
                        } else  {
                                prefixe =  (String) cb.getRawValue();
                        }               
                        
                        // Prénom
                        String prenom = (String) hmIdentite.getTextField("tfPrenom").getValue();
                        
                        // Nom
                        String nom = (String) hmIdentite.getTextField("tfNom").getValue();
                        
                        // Suffixe
                        ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe");
                        
                        String suffixe = "";
                        Valeur valSuffixe = cbSuffixe.getValue();
                        
                        if (valSuffixe != null) {
                                suffixe = valSuffixe.getNom();
                        } else  {
                                suffixe =  (String) cbSuffixe.getRawValue();
                        }
                        
                        // Mettre à jour la valeur
                        valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
                        valeurRetour = valeurRetour.replaceAll("null", "");
                        
                        hmIdentite.getLabelField("nomComplet").setValue(valeurRetour);
                        
                        if (!valeurRetour.trim().equals(""))    {
                                hmIdentite.getLabelField("nomComplet").show();
                        } else {
                                hmIdentite.getLabelField("nomComplet").hide();
                        }
                }
                
                mediateur.masquerPopinChargement();
                
                if (this.mode.equals(MODE_AJOUTER))     {
                        gererEtatActivationBouton();
                }       
        }

        private void repandreRafraichissement() {               
                if (vueExterneARafraichirApresValidation != null) {
                        String type = "personne_modifiee";
                        if (mode.equals(Formulaire.MODE_AJOUTER)) {
                                type = "personne_ajoutee";
                        }
                        Information info = new Information(type);
                        info.setDonnee(0, personneSelectionnee);
                        vueExterneARafraichirApresValidation.rafraichir(info);
                }
        }
        
        private void mettreAJourPersonne(Personne personne)     {
                
                //Mise à jour de la personne
                
                //Prefixe
                String prefixe = personne.get("ce_truk_prefix");
                ComboBox<Valeur> cbPrefixe = hmIdentite.getComboBoxValeur("cbPrefixe");
                
                
                String prefixeCourant = personne.get("ce_truk_prefix");
                if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)        {
                        cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
                }       else    {
                        cbPrefixe.setRawValue(prefixeCourant);
                }
                
                hmIdentite.getTextField("tfPrenom").setValue(personne.get("prenom"));
                hmIdentite.getTextField("tfNom").setValue(personne.get("nom"));
                
                //Suffixe
                String suffixe = personne.get("ce_truk_suffixe");
                ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe");
                
                String suffixeCourant = personne.get("ce_truk_suffix");
                if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)        {
                        cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
                }       else    {
                        cbSuffixe.setRawValue(suffixeCourant);
                }
                
                hmIdentite.getChampMultiValeurs("nomAutre").peupler(personne.getString("truk_nom_autre"));
                hmIdentite.getTextField("tfAbreviation").setValue(personne.get("abreviation"));
                hmIdentite.getChampMultiValeurs("abreviationAutre").peupler(personne.getString("truk_abreviation_autre"));
                
                hmIdentite.getTextField("tfDateNaissance").setValue(personne.getAnneeOuDateNaiss());
                hmIdentite.getTextField("tfLieuNaissance").setValue(personne.get("naissance_lieu"));
                
                
                if (personne.estDecedee())      {
                        hmIdentite.getTextField("tfDateDeces").setValue(personne.getAnneeOuDateDeces());
                        hmIdentite.getTextField("tfLieuDeces").setValue(personne.get("deces_lieu"));
                        Radio rbEstDecede = hmIdentite.getRadio("rbEstDecedee");
                        rbEstDecede.setValue(true);
                }
                
                hmIdentite.getChampMultiValeurs("telephones").peupler(personne.getString("truk_telephone"));
                
                //Courriel
                hmIdentite.getChampMultiValeurs("courriels").peupler(personne.getCourriel());
                
                //Sites web
                hmIdentite.getChampMultiValeurs("sites").peupler(personne.getString("truk_url"));
                
                // Sexe
                String strSexe = personne.get("ce_sexe");
                ComboBox<Valeur> cbSexe = hmIdentite.getComboBoxValeur("cbSexe");

                if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)  {
                        cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
                }
                
                hmIdentite.getTextArea("taDescription").setRawValue((String) personne.get("description"));
                
                //Logo
                hmIdentite.getChampMultiValeurs("logos").peupler(personne.getString("truk_logo"));
                
                /*--------------------------------------------------
                                      Adresse
                 ---------------------------------------------------*/
                
                // Adresse
                hmAdresse.getTextField("tfAdresse1").setValue((String) personne.get("adresse_01"));
                
                //Boite postale
                hmAdresse.getTextField("tfBoitePostale").setValue((String) personne.get("bp"));
                
                //Pays
                String strPays = personne.get("ce_truk_pays");
                ComboBox<Valeur> cbPays = hmAdresse.getComboBoxValeur("cbPays");
                cbPays.getStore().sort("nom", SortDir.ASC);
                
                if (cbPays.getStore().findModel("id_valeur", strPays) != null)  {
                        cbPays.setValue(cbPays.getStore().findModel("id_valeur", strPays));
                        cbPays.fireEvent(Events.OnChange);
                }       else    {
                        cbPays.setRawValue(strPays);
                }
                
                //Cp
                hmAdresse.getTextField("tfCodePostal").setValue(personne.get("code_postal"));
                
                //Ville
                hmAdresse.getTextField("tfVille").setValue(personne.get("ville"));
                
                /*--------------------------------------------------------
                 *                                      Infos naturalistes
                 * -----------------------------------------------------*/
                
                hmInfosNat.getChampMultiValeurs("specialite").peupler(personne.getString("ce_truk_specialite"));
                String tr = personne.getString("truk_recolte");         
                hmInfosNat.getChampMultiValeursMultiTypesPaginable("recolte").peupler(tr);
                
                //Onglet publi  
                tiPubli.mettreAJourPersonne();
                gererEtatActivationBouton();
        }
 
        public void remplirCombobox(String idComboBox, List liste, String hashMapId)    {
                HashMap hm = null;
                if (hashMapId.equals("hmIdentite"))     {
                        hm = hmIdentite;
                } else if (hashMapId.equals("hmAdresse")){
                        hm = hmAdresse;
                } else {
                        hm = hmInfosNat;
                }
                
                ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
                
                store.removeAll();
                store.add(liste);
                ((ComboBox) hm.get(idComboBox)).setStore(store);
        }
        
        private void gererEtatActivationBouton()        {
        /*      if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)        {                       
                        enregistrer.setEnabled(false);
                        enregistrerEtRevenir.setEnabled(false);
                } else  {
                        enregistrer.setEnabled(true);
                        enregistrerEtRevenir.setEnabled(true);
                }*/
        }
        
        public void binderPersonne(Personne personne)   {
                binding = new FormBinding(getFormulaire());
                
                personneSelectionnee = personne;
                
                FieldBinding f = new FieldBinding((RadioGroup) hmIdentite.get("rbgDeces"), null);
                binding.autoBind();
                binding.removeFieldBinding(f);
                
                binding.bind(personneSelectionnee);
                layout();
        }

        private String obtenirValeurCombo(String strComboName)  {
                String strValeur = "";
                Valeur valeur;
                
                ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur(strComboName);
                if (combo == null)      {
                        combo = hmAdresse.getComboBoxValeur(strComboName);
                }
                strValeur = combo.getRawValue();
                valeur = combo.getValue();
                if (valeur != null)     {
                        strValeur = valeur.getId();
                }
                
                return strValeur;
        }

        public boolean soumettreFormulaire() {
                tiPubli.collecter();
                if (verifierFormulaire())       {
                        tiPubli.soumettre();
                        mediateur.enregistrerPersonne(this, personneSelectionnee);
                        return true;
                }
                else return false;
        }

        public boolean verifierFormulaire() {
                boolean success = true;
                LinkedList<String> lstMessageErreur = new LinkedList<String>();
                
                String strTfNom = (String) hmIdentite.getTextField("tfNom").getValue();
                if ((strTfNom == null)||(strTfNom.trim().equals("")))   {
                        lstMessageErreur.add("Le nom n'a pas été saisi");
                } else {
                        strTfNom = UtilString.ucFirst(strTfNom);
                        personneSelectionnee.set("nom", strTfNom);
                }
                
                String strTfPrenom = (String) hmIdentite.getTextField("tfPrenom").getValue();
                personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
                
                //Préparer les données
                ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur("cbSexe");
                Valeur valeur;
                String strValeur = "";
                
                valeur = combo.getValue();
                if (valeur!=null)       {
                        personneSelectionnee.set("ce_sexe", valeur.getId());
                }
                
                strValeur = obtenirValeurCombo("cbPrefixe");
                personneSelectionnee.set("ce_truk_prefix", strValeur);
                
                strValeur = obtenirValeurCombo("cbSuffixe"); 
                personneSelectionnee.set("ce_truk_suffix", strValeur);
                
                String nomAutre = hmIdentite.getChampMultiValeurs("nomAutre").getValeurs();
                personneSelectionnee.set("truk_nom_autre", nomAutre);
                
                String abreviationAutre = hmIdentite.getChampMultiValeurs("abreviationAutre").getValeurs();
                personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);
                
                personneSelectionnee.set("truk_courriel", hmIdentite.getChampMultiValeurs("courriels").getValeurs());
                
                
                //Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
                String strPrefixe = "";
                combo = hmIdentite.getComboBoxValeur("cbPrefixe");
                valeur = combo.getValue();
                if (valeur != null)     {
                        strPrefixe = valeur.getNom();
                } else {
                        strPrefixe = combo.getRawValue();
                }
                
                String strSuffixe = "";
                combo = hmIdentite.getComboBox("cbSuffixe");
                valeur = combo.getValue();
                if (valeur != null)     {
                        strSuffixe = valeur.getNom() + " ";
                } else {
                        strSuffixe = combo.getRawValue() +" ";
                }
                
                personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);

                /** NAISSANCE **/
                String valeurDateNaissance = (String) hmIdentite.getTextField("tfDateNaissance").getValue();
                traiterDate("naissance", valeurDateNaissance, personneSelectionnee, lstMessageErreur);
                
                /** DECES **/
                Radio rbEstDecedee = hmIdentite.getRadio("rbEstDecedee");
                if (rbEstDecedee.getValue() == true) {
                        // date
                        String valeurDateDeces = (String) hmIdentite.getTextField("tfDateDeces").getValue();    
                        traiterDate("décès", valeurDateDeces, personneSelectionnee, lstMessageErreur);
                        // lieu
                        String decesLieu = (String) hmIdentite.getTextField("tfLieuDeces").getValue();
                        personneSelectionnee.setDecesLieu(decesLieu);
                } else {
                        personneSelectionnee.setNonDecedee();
                }
                
                strValeur = obtenirValeurCombo("cbPays");               
                personneSelectionnee.set("ce_truk_pays", strValeur);
                
                success = hmIdentite.getChampMultiValeursMultiTypes("telephones").estValide(true);
                personneSelectionnee.set("truk_telephone", hmIdentite.getChampMultiValeursMultiTypes("telephones").getValeurs());
                
                String logoUrls = hmIdentite.getChampMultiValeursImage("logos").getValeurs();
                personneSelectionnee.set("truk_logo", logoUrls);
                
                personneSelectionnee.set("truk_url", hmIdentite.getChampMultiValeurs("sites").getValeurs());
                
                //Infos Naturalistes
                String recolte = ((ChampMultiValeursMultiTypesPaginable) hmInfosNat.get("recolte")).getValeurs();
                personneSelectionnee.set("truk_recolte", recolte);
                
                String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();
                personneSelectionnee.set("ce_truk_specialite", specialite);
                
                lstMessageErreur.addAll(tiPubli.verifier());
                
                if (lstMessageErreur.size() != 0)       {
                        String strMessagesErreur = "<span><br />";
                        Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
                        while (itMessagesErreur.hasNext())      {
                                strMessagesErreur += "<br /> - " + itMessagesErreur.next();
                        }
                        strMessagesErreur += "</span>";
                        
                        MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
                        success = false;
                }
                
                return success;
        }
        
        private void traiterDate(String typeDate, String date, Personne personneSelectionnee, LinkedList<String> lstMessageErreur) {
                
                String valeurDate = date;
                
                if (!UtilString.isEmpty(valeurDate)){
                        String jour = "";
                        String mois = "";
                        String annee = "";
                        String dateComplete = "";
                        String messageErreur = null;
                        
                        /**  JJ/MM/AAAA  **/
                        if (valeurDate.matches("\\d{2}/\\d{2}/\\d{4}")) {
                                jour = valeurDate.substring(0,2);
                                mois = valeurDate.substring(3,5);
                                annee = valeurDate.substring(6,10);
                                if (jour.equals("00") || mois.equals("00") || annee.equals("0000")) {
                                        messageErreur = "La date de "+typeDate+" n'est pas au format JJ/MM/AAAA ou MM/AAAA ou AAAA.";
                                } else {
                                        dateComplete = annee+"-"+mois+"-"+jour;
                                }
                                
                                
                        /**  MM/AAAA  **/
                        } else if (valeurDate.matches("\\d{2}/\\d{4}")) {
                                jour = "00";
                                mois = valeurDate.substring(0,2);
                                annee = valeurDate.substring(3,7);
                                if (mois.equals("00") || annee.equals("0000")) {
                                        messageErreur = "La date de "+typeDate+" n'est pas au format JJ/MM/AAAA ou MM/AAAA ou AAAA.";
                                } else {
                                        dateComplete = annee+"-"+mois+"-"+jour;
                                }
                                
                        }
                        
                        /**  AAAA  **/
                        else if (valeurDate.matches("\\d{4}"))  {
                                if (valeurDate.equals("0000")) {
                                        messageErreur = "La date de "+typeDate+" n'est pas au format JJ/MM/AAAA ou MM/AAAA ou AAAA.";
                                }
                                else {
                                        dateComplete = valeurDate + "-00-00";
                                        
                                }
                        }
                        else {
                                lstMessageErreur.add("La date de "+typeDate+" n'est pas au format JJ/MM/AAAA ou MM/AAAA ou AAAA.");
                        }
                        if (messageErreur == null) {
                                if (typeDate=="naissance") personneSelectionnee.set("naissance_date", dateComplete);
                                else if (typeDate=="décès") {
                                        personneSelectionnee.set("deces_date", dateComplete);
                                        personneSelectionnee.set("ce_deces", personneSelectionnee.ETRE_DECEDE);
                                }
                        } else {
                                lstMessageErreur.add(messageErreur);
                        }
                        
                        if(typeDate.equals("décès")) {                                
                                String valeurDateDeces = hmIdentite.getTextField("tfDateDeces").getRawValue();
                                String valeurDateNaissance = hmIdentite.getTextField("tfDateNaissance").getRawValue();
                                
                                if(valeurDateDeces != null && valeurDateNaissance != null &&
                                                !valeurDateDeces.isEmpty() && !valeurDateNaissance.isEmpty()) {
                                        Date dateNaissance = parserDate(valeurDateNaissance);
                                        Date dateDeces = parserDate(valeurDateDeces);
                                        
                                        if(dateDeces.compareTo(dateNaissance) < 0) {
                                                lstMessageErreur.add("La date de décès ne peut pas précéder la date de naissance");
                                        }
                                }
                        }
                /** Date vide **/
                } else {
                        if (typeDate=="naissance") {
                                personneSelectionnee.setNaissanceDate(null);
                        } else if (typeDate=="décès") {
                                personneSelectionnee.setDecesDate(null);
                                personneSelectionnee.set("ce_deces", personneSelectionnee.ETRE_DECEDE);
                        }
                }
                
        }
        
        private Date parserDate(String valeurDate) {    
                Date dateParsee = new Date();
                String[] composantsDate = valeurDate.split("/");
                // Attention : la fonction setYear ajoute 1900 à l'année
                int annee = Integer.parseInt(composantsDate[(composantsDate.length-1)]) - 1900;
                // Attention : les mois commencent à 0, donc janvier = 0, février = 1
                int mois = (composantsDate.length > 1) ? Integer.parseInt(composantsDate[(composantsDate.length-2)]) - 1 : 0;
                int jour = (composantsDate.length > 2) ? Integer.parseInt(composantsDate[0]) : 1;
                
                dateParsee.setYear(annee);      
                dateParsee.setMonth(mois);      
                dateParsee.setDate(jour);
                                        
                return dateParsee;
        }
        
        public Personne getPersonne() {
                return this.personne;
        }
        
        public String getPersonneId() {
                return this.personneId;
        }
        
        private Listener<BaseEvent> creerEcouteurNomPrenomExistant() {
                return new Listener<BaseEvent>() {
                        public void handleEvent(BaseEvent be) {
                                if(mode.equals(MODE_AJOUTER) && !verificationDoublonEffectuee) {
                                        
                                        TextField<String> nom = (TextField<String>) hmIdentite.get("tfNom");
                                        TextField<String> prenom = (TextField<String>) hmIdentite.get("tfPrenom");
                                        LabelField nomComplet = (LabelField) hmIdentite.get("nomComplet");
                                        
                                        if(nom.getValue() != null && !nom.getValue().isEmpty()) {
                                                PersonneAsyncDao dao = new PersonneAsyncDao(PersonneForm.this);
                                                // Suppression d'éventuels doubles espaces (ou plus) et ajout d'un joker devant
                                                // (pour gérer la recherche lorsqu'on a qu'un nom de famille)
                                                String nomCompletStr = "%"+nomComplet.getValue().toString().trim().replaceAll(" +", " ");
                                                
                                                if(prenom.getValue() != null && !prenom.getValue().isEmpty()) {
                                                        // Ajouter un % derrière le prénom permet de gérer facilement le cas de l'initiale
                                                        // et également de rechercher des noms potentiels si l'on a saisi qu'une initiale
                                                        nomCompletStr = nomCompletStr.replaceAll(prenom+" ", prenom+"%");
                                                }
                                                
                                                dao.testerExistencePersonne(nomCompletStr, new Callback<JSONObject, String>() {                         
                                                        @Override
                                                        public void onSuccess(JSONObject objet) {
                                                                
                                                                String message = formaterMessageAvertissementDoublon(objet);
                                                                verificationDoublonEffectuee = true;
                                                                
                                                                if(!message.isEmpty()) {
                                                                        Window.alert(message);
                                                                }
                                                        }
                                                        
                                                        @Override
                                                        public void onFailure(String reason) {
                                                                // TODO Auto-generated method stub
                                                        }
                                                });
                                        }
                                }
                        }
                };
        }
        
        private String formaterMessageAvertissementDoublon(JSONObject objet) {
                
                double nbPers = objet.get("nbElements").isNumber().getValue();
                JSONArray personnes = objet.isObject().get("personnes").isArray();
                String message = "";
                if(nbPers > 0) {
                        String pers = nbPers == 1 ? "personne" : "personnes";
                        String exist = nbPers == 1 ? "existe" : "existent";
                        message = "Attention : "+(int)nbPers+" "+pers+" portant ce nom "+exist+" déjà"+"\n";
                        for(int i = 0; i < personnes.size(); i++) {
                                message += "- "+personnes.get(i).isObject().get("cp_fmt_nom_complet").isString().stringValue();
                                if(personnes.get(i).isObject().get("cp_ville") != null && personnes.get(i).isObject().get("cp_ville").isString() != null) {
                                        message += " à "+personnes.get(i).isObject().get("cp_ville").isString().stringValue();
                                }
                                
                                if(personnes.get(i).isObject().get("cp_naissance_date") != null 
                                        && personnes.get(i).isObject().get("cp_naissance_date").isString()!= null
                                        && !personnes.get(i).isObject().get("cp_naissance_date").isString().stringValue().equals("0000-00-00")) {
                                        String dateChaine = personnes.get(i).isObject().get("cp_naissance_date").isString().stringValue();
                                        
                                        String dateNaissance = "";
                                        // Quelque fois on ne possède que l'année de naissance de la personne,
                                        // dans ce cas là la date est de la forme XXXX-00-00
                                        if(dateChaine.endsWith("-00-00")) {
                                                dateNaissance = dateChaine.substring(0, 4);
                                        } else {
                                                dateNaissance = UtilDate.formaterEnStringFormatFr(UtilString.formaterEnDate(dateChaine));
                                        }

                                        message += ", date de naissance : "+dateNaissance;
                                }
                                message += "\n";
                        }
                }
                
                return message;
        }
}