Subversion Repositories eFlore/Applications.coel

Rev

Rev 276 | Rev 283 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.vues;

import java.util.HashMap;

import org.tela_botanica.client.ComposantClass;
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.InterneValeur;
import org.tela_botanica.client.modeles.Personne;
import org.tela_botanica.client.modeles.Valeur;


import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.KeyListener;
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.store.Store;
import com.extjs.gxt.ui.client.widget.Container;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.DatePicker;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
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.LabelField;
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.FlowLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;

import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;



public class FormPersonneVue extends ContentPanel implements Rafraichissable {
        
        
        /*--------------------------------------------------------------------------------------
         *              VARIABLES
         * -------------------------------------------------------------------------------------
         */
        
        private TabItem tiIdentite, tiAdresses, tiInfosNat;
        
        
        /*--------------------------------------------------------------------------------------
         *              CONSTRUCTEUR 
         * -------------------------------------------------------------------------------------
         */
        /**
         * Constructeur du panneau
         * 
         * Initialise le panneau et ajoute une barre d'outils à deux boutons (réinitialiser le 
         * formulaire et annuler la saisie). 
         * 
         * */
        public FormPersonneVue() {
                
                initialiserPanneau(this);
                
                ToolBar barreOutils = new ToolBar();
                
                ajouterBoutonEnregistrer(barreOutils);
                ajouterBoutonReinitialiser(barreOutils);
                ajouterBoutonAnnuler(barreOutils);
                
                setTopComponent(barreOutils);
                
                initialiserOnglets();   
                
                creerComposantsIdentite();
                
        }
        
        
        /*---------------------------------------------------------------------------------------
         *              SOUS-METHODES
         * --------------------------------------------------------------------------------------
         */
        /**
         * Inialise le panneau donné
         * 
         * @param contentPanel le panneau à initialiser
         * */
        public void initialiserPanneau(ContentPanel contentPanel)       {
                
                contentPanel.setLayout(new FitLayout());
                contentPanel.setIconStyle("icone-form-ajouter");  
                contentPanel.setCollapsible(false);  
                contentPanel.setHeading("Ajouter une personne");
                contentPanel.setButtonAlign(HorizontalAlignment.CENTER);  
                contentPanel.setLayout(new FormLayout());
        }
        
        /**
         * Crée les onglets identité, adresse et informations naturaliste
         * 
         * */
        public void initialiserOnglets()        {
                //TabPanel
                TabPanel formulaireOnglets = new TabPanel();
                
                //Tab 1 : identite
                tiIdentite = new TabItem("Identité");
                tiIdentite.setLayout(new FormLayout());
                formulaireOnglets.add(tiIdentite);
                
                
                //Tab 2 : Adresse
                tiAdresses = new TabItem("Adresse");
                tiAdresses.setLayout(new FlowLayout());
                formulaireOnglets.add(tiAdresses);
                
                //Tab 3 : Infos Naturalistes
                tiInfosNat = new TabItem("Informations Naturalistes");
                tiInfosNat.setLayout(new FormLayout());
                formulaireOnglets.add(tiInfosNat);
                
                add(formulaireOnglets);
        }
        
        /**
         * Crée les widgets pour l'onglet identité
         * 
         * */
        
        //hmIdentite référence par une chaine de caractère tous les composants de l'onglet Identite
        private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();
        
        public void creerComposantsIdentite()   {
                
                        // Gestion de l'affichage en colonnes
                        // On crée 3 Layout container : un principal, un pour la colonne de gauche, un pour la colonne de droite
                
                        // Gauche
                        LayoutContainer left = new LayoutContainer();
                        left.setLayout(new FormLayout());
                        
                        // Droite
                        LayoutContainer right = new LayoutContainer();
                        right.setLayout(new FormLayout());
                        
                        // Principal
                        LayoutContainer main = new LayoutContainer();
                        main.setLayout(new ColumnLayout());
                        
                        // Ajout au principal
                        main.add(left, new ColumnData(.5));
                        main.add(right, new ColumnData(.5));
                        
                        
                        // Création des champs
                        
                        //FormLayout sera utilisé à plusieurs reprises
                        FormLayout formLayout = new FormLayout();
                        
                        FieldSet fsNoms = new FieldSet();
                        fsNoms.setHeading("Noms");
                        
                        formLayout.setLabelAlign(LabelAlign.LEFT);
                        fsNoms.setLayout(formLayout); 
                        
                        // Nom complet
                        // Affiché que si valeurs saisies
                        LabelField nomComplet = new LabelField();
                        nomComplet.setFieldLabel("Nom complet:");
                        nomComplet.hide();
                        fsNoms.add(nomComplet);
                        
                        hmIdentite.put("nomComplet", nomComplet);
                        
                        //Préfixe
                        ComboBox<Valeur> cbPrefix = new ComboBox<Valeur>();
                        ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
                        cbPrefix.setStore(storePrefixe);
                        cbPrefix.setFieldLabel("Prefix");
                        fsNoms.add(cbPrefix);                   
                        
                        hmIdentite.put("cbPrefix", cbPrefix);
                        
                        //Prénom
                        TextField<String> tfPrenom = new TextField<String>();
                        tfPrenom.setFieldLabel("Prénom");
                        fsNoms.add(tfPrenom);
                        
                        hmIdentite.put("tfPrenom", tfPrenom);
                        
                        //Nom
                        TextField<String> tfNom = new TextField<String>();
                        tfNom.setFieldLabel("Nom");
                        fsNoms.add(tfNom);
                        
                        hmIdentite.put("tfNom", tfNom);
                        
                        //Préfixe
                        ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
                        ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
                        cbSuffixe.setStore(storeSuffixe);
                        cbSuffixe.setFieldLabel("Suffixe");
                        fsNoms.add(cbSuffixe);                  
                        
                        hmIdentite.put("cbSuffixe", cbSuffixe);
                                                
                        // Nom : autre
                        TextField<String> tfNomAutre = new TextField();
                        tfNomAutre.setFieldLabel("Autres noms");
                        fsNoms.add(tfNomAutre);
                        
                        hmIdentite.put("tfNomAutre", tfNomAutre);
                        
                        //Abréviation
                        TextField<String> tfAbreviation = new TextField<String>();
                        tfAbreviation.setFieldLabel("Abréviation");
                        fsNoms.add(tfAbreviation);
                        
                        hmIdentite.put("tfAbreviation", tfAbreviation);
                        
                        //Abréviation autres
                        TextField<String> tfAbreviationAutre = new TextField<String>();
                        tfAbreviationAutre.setFieldLabel("Autres Abrév.");
                        fsNoms.add(tfAbreviationAutre);
                        
                        hmIdentite.put("tfAbreviation", tfAbreviation);
                        
                        
                        left.add(fsNoms);
                        
                        // Naissance & décès
                        FieldSet fsVie = new FieldSet();
                        fsVie.setHeading("Vie");
                        
                        formLayout = new FormLayout();
                        formLayout.setLabelAlign(LabelAlign.TOP);
                        fsVie.setLayout(formLayout); 
                        
                        // Date naissance
                        DateField dfDateNaissance = new DateField();
                        
                        dfDateNaissance.setFieldLabel("Date de naissance");
                        fsVie.add(dfDateNaissance);
                        
                        hmIdentite.put("dfDateNaissance", dfDateNaissance);
                        
                        // Lieu naissance
                        TextField<String> tfLieuNaissance = new TextField();
                        tfLieuNaissance.setFieldLabel("Lieu de naissance");
                        fsVie.add(tfLieuNaissance);
                        
                        hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
                        
                        // Date décès
                        DateField dfDateDeces = new DateField();
                        dfDateDeces.setFieldLabel("Date de décès");
                        fsVie.add(dfDateDeces);
                        
                        hmIdentite.put("dfDateDeces", dfDateDeces);
                        
                        // Lieu décès
                        TextField<String> tfLieuDeces = new TextField();
                        tfLieuDeces.setFieldLabel("Lieu de décès");
                        fsVie.add(tfLieuDeces);
                        
                        hmIdentite.put("tfLieuDeces", tfLieuDeces);
                        
                        //Date picker
                        DatePicker datePick = new DatePicker();
                        
                        
                        left.add(fsVie);
                        
                        tiIdentite.add(main);
                        
                        
                        // Ajout des évènements saisi
                        KeyListener klNoms = new KeyListener()  {
                                public void componentKeyUp(ComponentEvent ev)   {
                                                /*
                                                 * Met à jour le nom Complet du formulaire
                                                 * */
                                                String valeurRetour = "";
                                                // Prefixe
                                                String prefixe = (String) ((ComboBox) hmIdentite.get("cbPrefix")).getSelectedText();
                                                
                                                // Prénom
                                                String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
                                                
                                                // Nom
                                                String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
                                                
                                                // Suffixe
                                                String suffixe = (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getSelectedText();
                                                
                                                // Mettre à jour la valeur
                                                valeurRetour = 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();
                                                }
                                                
                                }                               
                        };
                        
                        cbPrefix.addKeyListener(klNoms);
                        tfPrenom.addKeyListener(klNoms);
                        tfNom.addKeyListener(klNoms);
                        cbSuffixe.addKeyListener(klNoms);
                        
                        
                        //Prénom
                
                        
                        this.recalculate();
                        fsNoms.recalculate();
                        fsNoms.layout();
                        this.layout();
                        this.hide();
                        
                        rafraichir(null);
                        
                        
        }
        
        /**
         * Ajouter le bouton réinitialiser à la barre d'outils donnée
         * 
         * @param barreOutils la barre d'outils à modifier
         * */
        public static void ajouterBoutonReinitialiser(ToolBar barreOutils)      {
                
                //Le bouton réintialiser recharge la page sans sauvegarder les informations
                TextToolItem reinitialiser = new TextToolItem("Réinitialiser");
                reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
                reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {  
                        public void componentSelected(ComponentEvent ce) {  
                                ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
                        }  
                });
                barreOutils.add(reinitialiser);
        }
        
        /**
         * Ajouter le bouton Sauvegarder à la barre d'outils donnée
         * 
         * @param barreOutils la barre d'outils à modifier
         * */
        public static void ajouterBoutonEnregistrer(ToolBar barreOutils)        {
                
                //Le bouton réintialiser recharge la page sans sauvegarder les informations
                TextToolItem reinitialiser = new TextToolItem("Enregistrer");
                reinitialiser.setIconStyle(ComposantClass.ICONE_PREFERENCE);
                reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {  
                        public void componentSelected(ComponentEvent ce) {  
                                // TODO : Enregistrer le formulaire
                        }  
                });
                barreOutils.add(reinitialiser);
        }
        
        /**
         * Ajouter le bouton annuler à la barre d'outils donnée
         * 
         * @param barreOutils la barre d'outils à modifier
         * */
        public static void ajouterBoutonAnnuler(ToolBar barreOutils)    {
                
                // Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
                TextToolItem annuler = new TextToolItem("Annuler");
                annuler.addSelectionListener(new SelectionListener<ComponentEvent>() {  
                        public void componentSelected(ComponentEvent ce) {  
                                ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
                        }  
                });
                annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
                barreOutils.add(annuler);
        }
        
        
        
        /*---------------------------------------------------------------------------------------
         *              RAFRAICHISSEMENT DU PANNEAU
         * --------------------------------------------------------------------------------------
         */     
        public void rafraichir(Object nouvelleDonnees) {
                // TODO Auto-generated method stub
                this.show();
                this.layout();
                this.recalculate();             
        }

        


}