Rev 857 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;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.images.Images;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.Configuration;import org.tela_botanica.client.modeles.Information;import org.tela_botanica.client.modeles.MenuApplicationId;import org.tela_botanica.client.modeles.Personne;import org.tela_botanica.client.modeles.PersonneListe;import org.tela_botanica.client.modeles.Projet;import org.tela_botanica.client.modeles.ProjetListe;import org.tela_botanica.client.modeles.Publication;import org.tela_botanica.client.modeles.Utilisateur;import org.tela_botanica.client.modeles.Valeur;import org.tela_botanica.client.modeles.ValeurListe;import org.tela_botanica.client.util.Pattern;import org.tela_botanica.client.util.UtilString;import com.extjs.gxt.ui.client.event.Events;import com.extjs.gxt.ui.client.Registry;import com.extjs.gxt.ui.client.Style.HorizontalAlignment;import com.extjs.gxt.ui.client.Style.IconAlign;import com.extjs.gxt.ui.client.Style.Scroll;import com.extjs.gxt.ui.client.Style.VerticalAlignment;import com.extjs.gxt.ui.client.binding.FormBinding;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.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.Info;import com.extjs.gxt.ui.client.widget.TabItem;import com.extjs.gxt.ui.client.widget.TabPanel;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.FieldSet;import com.extjs.gxt.ui.client.widget.form.FormPanel;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.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.ToolBar;import com.google.gwt.core.client.GWT;import com.google.gwt.i18n.client.DateTimeFormat;import com.google.gwt.user.client.ui.Widget;public class PersonneForm extends Formulaire implements Rafraichissable {// VARIABLESprivate TabItem tiIdentite, tiAdresses, tiInfosNat;private Mediateur mediateur;private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);private Personne personneSelectionnee, personneSauvegarde = null;protected String mode = "";//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identiteprivate HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();private HashMap<String, Widget>hmAdresse = new HashMap<String, Widget>();private HashMap<String, Widget>hmInfosNat = new HashMap<String, Widget>();private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();private FormData fd100 = new FormData("95%");private Button enregistrer, enregistrerEtRevenir;public static final String MODE_AJOUTER = "AJOUT";public static final String MODE_MODIFIER = "MODIF";private Personne personne = null;private String personneId = null;private FormBinding binding = null;// CONSTRUCTEURpublic PersonneForm(Mediateur mediateurCourrant, String mode, 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) {personne = new Personne();personne.setId(personneIdCourrant);personneId = personneIdCourrant;String modeDeCreation = (personneId.isEmpty() ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.PERSONNE);initialiserComposants();genererTitreFormulaire();if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {mediateur.selectionnerPersonne(this, personne, null);}}private void genererTitreFormulaire() {String titre = i18nC.personneModeAjout();if (mode.equals(Formulaire.MODE_MODIFIER)) {titre = i18nC.personneModeModifier()+" - "+i18nC.id()+": "+personneId;}panneauFormulaire.setHeading(titre);}public void initialiserComposants() {personneSelectionnee = new Personne();personneSauvegarde = new Personne();initialiserOnglets();creerComposantsIdentite();creerComposantsAdresse();creerComposantsInfosNat();binderPersonne(personneSelectionnee);}/*** Crée les onglets identité, adresse et informations naturaliste** */public void initialiserOnglets() {//TabPanelTabPanel formulaireOnglets = new TabPanel();//Tab 1 : identitetiIdentite = new TabItem(i18nC.personneIdentite());tiIdentite.setLayout(new FormLayout());tiIdentite.setScrollMode(Scroll.AUTO);formulaireOnglets.add(tiIdentite);hmIdentite.put("tiIdentite", tiIdentite);//Tab 2 : AdressetiAdresses = new TabItem(i18nC.adresse());tiAdresses.setLayout(new FormLayout());tiAdresses.setScrollMode(Scroll.AUTO);formulaireOnglets.add(tiAdresses);//Tab 3 : Infos NaturalistestiInfosNat = new TabItem(i18nC.personneInfoNat());tiInfosNat.setLayout(new FormLayout());tiInfosNat.setScrollMode(Scroll.AUTO);formulaireOnglets.add(tiInfosNat);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 & droiteLayoutContainer 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(.45));main.setLayout(new ColumnLayout());main.setHeight("100%");main.setScrollMode(Scroll.AUTO);// Création des champsFormLayout formLayout = new FormLayout();formLayout.setLabelAlign(LabelAlign.LEFT);FieldSet fsProjet = new FieldSet();fsProjet.setHeading(i18nC.menuProjet());fsProjet.setLayout(new FormLayout());ListStore<Projet> storeProjets = new ListStore<Projet>();ComboBox cbProjets = new ComboBox<Projet>();cbProjets.setFieldLabel(i18nC.personneProjet()+ " :");cbProjets.setEmptyText(i18nC.txtListeProjetDefaut());cbProjets.setLabelSeparator("");cbProjets.setDisplayField("nom");cbProjets.setEditable(false);cbProjets.setTriggerAction(TriggerAction.ALL);cbProjets.setStore(storeProjets);cbProjets.setAllowBlank(false);fsProjet.add(cbProjets);hmIdentite.put("cbProjets", cbProjets);mediateur.selectionnerProjets(this);left.add(fsProjet);FieldSet fsNoms = new FieldSet();fsNoms.setHeading("Noms");fsNoms.setLayout(formLayout);// Nom complet : Affiché que si valeurs saisiesLabelField nomComplet = new LabelField();nomComplet.setFieldLabel(i18nC.personneNomComplet() +" :");nomComplet.hide();fsNoms.add(nomComplet);hmIdentite.put("nomComplet", nomComplet);//PréfixeListStore<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");//PrénomTextField<String> tfPrenom = new TextField<String>();tfPrenom.setFieldLabel("Prénom");tfPrenom.setName("prenom");fsNoms.add(tfPrenom);hmIdentite.put("tfPrenom", tfPrenom);//NomTextField<String> tfNom = new TextField<String>();tfNom.setFieldLabel("Nom");tfNom.setAllowBlank(false);tfNom.setName("nom");fsNoms.add(tfNom);hmIdentite.put("tfNom", tfNom);//SuffixeListStore<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");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);formLayout = new FormLayout();formLayout.setLabelAlign(LabelAlign.LEFT);FieldSet fsNaissance = new FieldSet();fsNaissance.setHeading("Naissance");fsNaissance.setLayout(formLayout);DateField dfDateNaissance = new DateField();dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));dfDateNaissance.setFieldLabel("Date");dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");fsNaissance.add(dfDateNaissance);hmIdentite.put("dfDateNaissance", dfDateNaissance);// Lieu naissanceTextField<String> tfLieuNaissance = new TextField<String>();tfLieuNaissance.setFieldLabel("Lieu");tfLieuNaissance.setName("naissance_lieu");fsNaissance.add(tfLieuNaissance);hmIdentite.put("tfLieuNaissance", tfLieuNaissance);left.add(fsNaissance);formLayout = new FormLayout();formLayout.setLabelAlign(LabelAlign.LEFT);FieldSet fsDeces = new FieldSet();fsDeces.setHeading("Décès");fsDeces.setLayout(formLayout);Radio rbEstDecedee = new Radio();rbEstDecedee.setBoxLabel("oui");rbEstDecedee.setValueAttribute("1");rbEstDecedee.addListener(Events.Change, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {if(((Radio) be.getComponent()).getValue().equals(true)) {((DateField) hmIdentite.get("dfDateDeces")).setVisible(true);((TextField) hmIdentite.get("tfLieuDeces")).setVisible(true);} else {DateField dfDateDeces = ((DateField) hmIdentite.get("dfDateDeces"));dfDateDeces.setValue(null);dfDateDeces.setVisible(false);TextField tfLieuDeces = ((TextField) hmIdentite.get("tfLieuDeces"));tfLieuDeces.setValue(null);tfLieuDeces.setVisible(false);}}});hmIdentite.put("rbEstDecedee", rbEstDecedee);Radio rbNestPasDecedee = new Radio();rbNestPasDecedee.setValueAttribute("0");rbNestPasDecedee.setBoxLabel("non");rbNestPasDecedee.setValue(true);/* Radio rbDecesInconnu = new Radio();rbDecesInconnu.setBoxLabel("Ne sais pas");rbDecesInconnu.setValue(true);*/RadioGroup rbgDeces = new RadioGroup();rbgDeces.setFieldLabel("Est décédée");rbgDeces.add(rbEstDecedee);rbgDeces.add(rbNestPasDecedee);fsDeces.add(rbgDeces);DateField dfDateDeces = new DateField();dfDateDeces.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));dfDateDeces.setFormatValue(true);dfDateDeces.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");dfDateDeces.setFieldLabel("Date");dfDateDeces.setVisible(false);fsDeces.add(dfDateDeces);hmIdentite.put("dfDateDeces", dfDateDeces);TextField<String> tfLieuDeces = new TextField<String>();tfLieuDeces.setFieldLabel("Lieu");tfLieuDeces.setName("deces_lieu");tfLieuDeces.setVisible(false);fsDeces.add(tfLieuDeces);hmIdentite.put("tfLieuDeces", tfLieuDeces);left.add(fsDeces);tiIdentite.add(main);FieldSet fsContactTel = new FieldSet();fsContactTel.setHeading("Contact - Téléphones");fsContactTel.setLayout(new RowLayout());ChampMultiValeursMultiTypes telephones = new ChampMultiValeursMultiTypes("Téléphones");hmIdentite.put("telephones", telephones);telephones.initialiserType("tel");fsContactTel.add(telephones);right.add(fsContactTel);hmIdentite.put("fsContactTel", fsContactTel);FieldSet fsContact = new FieldSet();fsContact.setHeading("Contact - Autres");fsContact.setId("fsContact");fsContact.setLayout(new RowLayout());right.add(fsContact);hmIdentite.put("fsContact", fsContact);ChampMultiValeurs courriels = new ChampMultiValeurs("Courriels");courriels.setValidation(Pattern.email, "moi@domaine.fr");fsContact.add(courriels);hmIdentite.put("courriels", courriels);LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout());fsContact.add(lcCourrielContainer);hmIdentite.put("lcCourrielContainer", lcCourrielContainer);ChampMultiValeurs sites = new ChampMultiValeurs("Sites web");sites.setValeurParDefaut("http://");sites.setValidation(Pattern.url, "http://www.monsite.com");fsContact.add(sites);hmIdentite.put("sites", sites);FieldSet fsAutresInfos = new FieldSet();fsAutresInfos.setHeading("Autres informations");formLayout = new FormLayout();formLayout.setLabelAlign(LabelAlign.LEFT);fsAutresInfos.setLayout(formLayout);formLayout = new FormLayout();formLayout.setLabelAlign(LabelAlign.TOP);LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout);//Civilité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:");lcAutreInformations1.add(cbSexe, fd100);hmIdentite.put("cbSexe", cbSexe);mediateur.obtenirListeValeurEtRafraichir(this, "sexe");//DescriptionTextArea taDescription = new TextArea();taDescription.setEmptyText("Saisissez une description");taDescription.setFieldLabel("Description");taDescription.setWidth("100%");taDescription.setName("description");lcAutreInformations1.add(taDescription, fd100);hmIdentite.put("taDescription", taDescription);fsAutresInfos.add(lcAutreInformations1);// LogoLayoutContainer lcLogoUrl = new LayoutContainer();hmIdentite.put("lcLogoUrl", lcLogoUrl);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");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 saisiKeyListener 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() {// GaucheLayoutContainer left = new LayoutContainer();left.setLayout(new FormLayout());left.setStyleAttribute("padding", "15px");// DroiteLayoutContainer right = new LayoutContainer();right.setLayout(new FormLayout());// PrincipalLayoutContainer main = new LayoutContainer();main.setLayout(new TableLayout(2));// Ajout au principalmain.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);TextField<String> tfAdresse2 = new TextField();tfAdresse2.setFieldLabel("Complément d'adresse");tfAdresse2.setName("adresse_02");left.add(tfAdresse2, fd100);hmAdresse.put("tfAdresse2", tfAdresse2);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);SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {public void selectionChanged(SelectionChangedEvent se) {// Rafraichir avec le pays sélectionnéobtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());}};cbPays.addSelectionChangedListener(selectionChange);ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();cbRegion.setFieldLabel("Region");cbRegion.setDisplayField("nom");cbRegion.setEmptyText("Sélectionnez la région:");cbRegion.setVisible(false);ListStore<Valeur> storeRegion = new ListStore<Valeur>();cbRegion.setStore(storeRegion);right.add(cbRegion, fd100);hmAdresse.put("cbRegion", cbRegion);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 ComboBoxmediateur.obtenirListeValeurEtRafraichir(this, "pays");FieldSet fsAdresse = new FieldSet();fsAdresse.setHeading("Adresse personnelle");fsAdresse.add(main);tiAdresses.add(fsAdresse);}public void creerComposantsInfosNat() {FieldSet fsInfosNat = new FieldSet();fsInfosNat.setTitle("Informations Naturaliste");ChampMultiValeurs specialite = new ChampMultiValeurs(i18nC.personneSpecialite());fsInfosNat.add(specialite);hmInfosNat.put("specialite", specialite);ChampMultiValeursMultiTypes recolte = new ChampMultiValeursMultiTypes(i18nC.personneRecolte());recolte.initialiserType("pays");hmInfosNat.put("recolte", recolte);fsInfosNat.add(recolte);tiInfosNat.add(fsInfosNat);}/*** Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée** @param barreOutils la barre d'outils à modifier* */private void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils) {//Le bouton réintialiser recharge la page sans sauvegarder les informationsenregistrerEtRevenir = new Button("Enregistrer et revenir à la liste");enregistrerEtRevenir.setIcon(Images.ICONES.scriptGo());enregistrerEtRevenir.setIconAlign(IconAlign.LEFT);enregistrerEtRevenir.addSelectionListener(new SelectionListener<ButtonEvent>() {public void componentSelected(ButtonEvent ce) {if (enregistrer() == true) {((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");}}});hmIdentite.put("btnEnregistrerRevenir", enregistrerEtRevenir);barreOutils.add(enregistrerEtRevenir);enregistrerEtRevenir.setEnabled(false);}/*** Ajouter le bouton Sauvegarder à la barre d'outils donnée** @param barreOutils la barre d'outils à modifier* */private void ajouterBoutonEnregistrer(ButtonBar barreOutils) {//Le bouton réintialiser recharge la page sans sauvegarder les informationsenregistrer = new Button("Enregistrer");enregistrer.setIcon(Images.ICONES.scriptSave());enregistrer.setIconAlign(IconAlign.LEFT);enregistrer.setId("main-button");enregistrer.addSelectionListener(new SelectionListener<ButtonEvent>() {public void componentSelected(ButtonEvent ce) {enregistrer();}});enregistrer.setEnabled(false);hmIdentite.put("btnEnregistrer", enregistrer);barreOutils.add(enregistrer);}/*** 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édenteButton 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);}public void obtenirListeRegionParPays(String strPays) {mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);}// RAFRAICHISSEMENT DU PANNEAUpublic void rafraichir(Object nouvellesDonnees) {if (nouvellesDonnees instanceof ValeurListe) {ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;// Créer une liste de valeursList<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("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"))) {remplirCombobox("cbSexe", liste, "hmIdentite");} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {remplirCombobox("cbTelephone", liste, "hmIdentite");//Préselection du télComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");cbTelephone.setValue(liste.get(1));} else if (listeValeurs.getId().equals(config.getListeId("pays"))) {remplirCombobox("cbPays", liste, "hmAdresse");} else if (listeValeurs.getId().equals(config.getListeId("region"))) {remplirCombobox("cbRegion", liste, "hmAdresse");((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);}} else if (nouvellesDonnees instanceof ProjetListe) {ProjetListe projets = (ProjetListe) nouvellesDonnees;List<Projet> liste = projets.toList();ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");ListStore<Projet> storeProjets= cbProjets.getStore();storeProjets.removeAll();storeProjets.add(liste);cbProjets.setStore(storeProjets);} else if (nouvellesDonnees instanceof Information) {Information info = (Information) nouvellesDonnees;if (info.getType().equals("ajout_personne")) {GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");if (clicBoutonvalidation) {mediateur.clicMenu(menuIdCourant);}} else if (info.getType().equals("modification_personne")) {Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");if (clicBoutonvalidation) {mediateur.clicMenu(menuIdCourant);}}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();personneSauvegarde = new Personne();personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);binderPersonne(personne);mettreAJourPersonne(personne);nouvellesDonnees = null;} else {Info.display("messages", info.getMessages().toString());}}if (nouvellesDonnees == null) {ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");//Met à jour le nom Complet du formulaireString valeurRetour = "";// PrefixeString prefixe = "";Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();if (valPrefixe != null) {prefixe = valPrefixe.getNom();} else {prefixe = (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();}// PrénomString prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();// NomString nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();// SuffixeString suffixe = "";Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();if (valSuffixe != null) {suffixe = valSuffixe.getNom();} else {suffixe = (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();}// Mettre à jour la valeurvaleurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;valeurRetour = valeurRetour.replaceAll("null", "");((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);if (!valeurRetour.trim().equals("")) {((LabelField) hmIdentite.get("nomComplet")).show();} else {((LabelField) hmIdentite.get("nomComplet")).hide();}}mediateur.masquerPopinChargement();if (this.mode.equals(MODE_AJOUTER)) {gererEtatActivationBouton();}}private void mettreAJourPersonne(Personne personne) {//Mise à jour de la personne//Personne personne = (Personne) nouvellesDonnees;ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));//PrefixeString prefixe = personne.get("ce_truk_prefix");ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("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);}((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));//SuffixeString suffixe = personne.get("ce_truk_suffixe");ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("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);}((ChampMultiValeurs) hmIdentite.get("nomAutre")).peupler(personne.getString("truk_nom_autre"));((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));((ChampMultiValeurs) hmIdentite.get("abreviationAutre")).peupler(personne.getString("truk_abreviation_autre"));(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));if (personne.estDecedee()) {(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));Radio rbEstDecede = (Radio) hmIdentite.get("rbEstDecedee");rbEstDecede.setValue(true);}((ChampMultiValeurs) hmIdentite.get("telephones")).peupler(personne.getString("truk_telephone"));//Courriel((ChampMultiValeurs) hmIdentite.get("courriels")).peupler(personne.getCourriel());//Sites web((ChampMultiValeurs) hmIdentite.get("sites")).peupler(personne.getString("truk_url"));// SexeString strSexe = personne.get("ce_sexe");ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");if (cbSexe.getStore().findModel("id_valeur", strSexe) != null) {cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));} else {cbSexe.setRawValue(strSexe);}((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));//Logo((ChampMultiValeurs) hmIdentite.get("logos")).peupler(personne.getString("truk_logo"));/*--------------------------------------------------Adresse---------------------------------------------------*/// Adresse((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));// Complément((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));//Boite postale((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));//PaysString strPays = personne.get("pays");ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");if (cbPays.getStore().findModel("nom", strPays) != null) {cbPays.setValue(cbPays.getStore().findModel("nom", strPays));} else {cbPays.setRawValue(strPays);}//RégionString strRegion = personne.get("region");if ((strRegion!=null)&&(!strRegion.equals(""))) {ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");cbRegion.setVisible(true);if (cbRegion.getStore().findModel("nom", strRegion) != null) {cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));} else {cbRegion.setRawValue(strRegion);}}//Cp((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));//Ville((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));/*--------------------------------------------------------* Infos naturalistes* -----------------------------------------------------*/((ChampMultiValeurs) hmInfosNat.get("specialite")).peupler(personne.getString("ce_truk_specialite"));((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).peupler(personne.getString("truk_recolte"));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 reinitialiserFormulaire() {mediateur.afficherPopinChargement();mettreAJourPersonne(personneSauvegarde);mediateur.masquerPopinChargement();}public void binderPersonne(Personne personne) {binding = new FormBinding(getFormulaire());personneSelectionnee = personne;binding.autoBind();binding.bind(personneSelectionnee);layout();}/*** Enregistre les information de la personne en cours**/public boolean enregistrer() {boolean success = false;LinkedList lstMessageErreur = new LinkedList<String>();ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");Projet projet = cbProjets.getValue();if (projet == null) {lstMessageErreur.add("Le projet n'a pas été renseigné");} else {personneSelectionnee.set("ce_projet", projet.getId());}String strTfNom = ((TextField<String>) hmIdentite.get("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 = ((TextField<String>) hmIdentite.get("tfPrenom")).getValue();personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));//Préparer les donnéesComboBox combo = (ComboBox) hmIdentite.get("cbSexe");Valeur valeur;String strValeur = "";valeur = (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 = ((ChampMultiValeurs) hmIdentite.get("nomAutre")).getValeurs();personneSelectionnee.set("truk_nom_autre", nomAutre);String abreviationAutre = ((ChampMultiValeurs) hmIdentite.get("abreviationAutre")).getValeurs();personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);personneSelectionnee.set("truk_courriel", ((ChampMultiValeurs) hmIdentite.get("courriels")).getValeurs());//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'idString strPrefixe = "";combo = (ComboBox) hmIdentite.get("cbPrefixe");valeur = (Valeur) combo.getValue();if (valeur != null) {strPrefixe = valeur.getNom();} else {strPrefixe = combo.getRawValue();}String strSuffixe = "";combo = (ComboBox) hmIdentite.get("cbSuffixe");valeur = (Valeur) combo.getValue();if (valeur != null) {strSuffixe = valeur.getNom() + " ";} else {strSuffixe = combo.getRawValue() +" ";}personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");Date naissanceDate = dfDateNaissance.getValue();personneSelectionnee.setNaissanceDate(naissanceDate);Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");if (rbEstDecedee.getValue() == true) {DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");String decesLieu = ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue();personneSelectionnee.setDeces(dfDecesDate.getValue(), decesLieu);} else {personneSelectionnee.setNonDecedee();}strValeur = obtenirValeurCombo("cbPays");personneSelectionnee.set("ce_truk_pays", strValeur);strValeur = obtenirValeurCombo("cbRegion");personneSelectionnee.set("ce_truk_region", strValeur);personneSelectionnee.set("truk_telephone", ((ChampMultiValeursMultiTypes) hmIdentite.get("telephones")).getValeurs());String logoUrls = ((ChampMultiValeursImage) hmIdentite.get("logos")).getValeurs();personneSelectionnee.set("truk_logo", logoUrls);personneSelectionnee.set("truk_url", ((ChampMultiValeurs) hmIdentite.get("sites")).getValeurs());//Infos NaturalistesString recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs();personneSelectionnee.set("truk_recolte", recolte);String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();personneSelectionnee.set("ce_truk_specialite", specialite);if (lstMessageErreur.size() == 0) {mediateur.enregistrerPersonne(this, personneSelectionnee);success = true;} else {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 String obtenirValeurCombo(String strComboName) {String strValeur = "";Valeur valeur;ComboBox combo = (ComboBox) hmIdentite.get(strComboName);if (combo == null) {combo = (ComboBox) hmAdresse.get(strComboName);}strValeur = combo.getRawValue();valeur = (Valeur) combo.getStore().findModel(strValeur);if (valeur != null) {strValeur = valeur.getId();}/*if (combo.getValue()!=null) {valeur = (Valeur) combo.getValue();strValeur = valeur.getId();} else {strValeur = combo.getRawValue();}*/return strValeur;}@Overrideprotected SelectionListener<ButtonEvent> creerEcouteurValidation() {SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {String code = ((Button) ce.getComponent()).getData("code");if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {soumettreFormulaire();clicBoutonvalidation = true;} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {soumettreFormulaire();} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {mediateur.clicMenu(menuIdCourant);} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {reinitialiserFormulaire();}}};return ecouteur;}protected boolean soumettreFormulaire() {if (verifierFormulaire()) {mediateur.enregistrerPersonne(this, personneSelectionnee);}return true;}protected boolean verifierFormulaire() {boolean success = false;LinkedList lstMessageErreur = new LinkedList<String>();ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");Projet projet = cbProjets.getValue();if (projet == null) {lstMessageErreur.add("Le projet n'a pas été renseigné");} else {personneSelectionnee.set("ce_projet", projet.getId());}String strTfNom = ((TextField<String>) hmIdentite.get("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 = ((TextField<String>) hmIdentite.get("tfPrenom")).getValue();personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));//Préparer les donnéesComboBox combo = (ComboBox) hmIdentite.get("cbSexe");Valeur valeur;String strValeur = "";valeur = (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 = ((ChampMultiValeurs) hmIdentite.get("nomAutre")).getValeurs();personneSelectionnee.set("truk_nom_autre", nomAutre);String abreviationAutre = ((ChampMultiValeurs) hmIdentite.get("abreviationAutre")).getValeurs();personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);personneSelectionnee.set("truk_courriel", ((ChampMultiValeurs) hmIdentite.get("courriels")).getValeurs());//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'idString strPrefixe = "";combo = (ComboBox) hmIdentite.get("cbPrefixe");valeur = (Valeur) combo.getValue();if (valeur != null) {strPrefixe = valeur.getNom();} else {strPrefixe = combo.getRawValue();}String strSuffixe = "";combo = (ComboBox) hmIdentite.get("cbSuffixe");valeur = (Valeur) combo.getValue();if (valeur != null) {strSuffixe = valeur.getNom() + " ";} else {strSuffixe = combo.getRawValue() +" ";}personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");Date naissanceDate = dfDateNaissance.getValue();personneSelectionnee.setNaissanceDate(naissanceDate);Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");if (rbEstDecedee.getValue() == true) {DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");String decesLieu = ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue();personneSelectionnee.setDeces(dfDecesDate.getValue(), decesLieu);} else {personneSelectionnee.setNonDecedee();}strValeur = obtenirValeurCombo("cbPays");personneSelectionnee.set("ce_truk_pays", strValeur);strValeur = obtenirValeurCombo("cbRegion");personneSelectionnee.set("ce_truk_region", strValeur);personneSelectionnee.set("truk_telephone", ((ChampMultiValeursMultiTypes) hmIdentite.get("telephones")).getValeurs());String logoUrls = ((ChampMultiValeursImage) hmIdentite.get("logos")).getValeurs();personneSelectionnee.set("truk_logo", logoUrls);personneSelectionnee.set("truk_url", ((ChampMultiValeurs) hmIdentite.get("sites")).getValeurs());//Infos NaturalistesString recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs();personneSelectionnee.set("truk_recolte", recolte);String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();personneSelectionnee.set("ce_truk_specialite", specialite);if (lstMessageErreur.size() == 0) {success = true;} else {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;}}