Subversion Repositories eFlore/Applications.coel

Rev

Rev 259 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

package org.tela_botanica.client.vues;





import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.MissingResourceException;


import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.i18n.Constantes;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Personne;
import org.tela_botanica.client.util.UtilTruk;

import com.extjs.gxt.ui.client.Registry;


import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;

import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
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.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.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Image;

public class PersonneDetailPanneauVue extends TabPanel implements Rafraichissable {

        // Le panneau détail se compose de formulaires tabulés
        
        // Onglet 1 : identite & contact
        private TabItem tabIdentite;
        
        private ContentPanel panneauIdentite;
        private ContentPanel panneauImage;
        
        private FieldSet fsIdentite;
        private FieldSet fsContact;
        
        // Onglet 2 : Adresses
        private TabItem tabAdresse;
        private FieldSet fsAdressePerso;
                // contient : adresse perso / adresse pro
        
        // Onglet 3 : Informations naturalistes
        private TabItem tabInfosNat;
        
        public PersonneDetailPanneauVue() {
                
                //Constructeur de la classe
                Registry.register(RegistreId.PANNEAU_PERSONNE_DETAIL, this);
                setLayout(new FitLayout());
                
                tabIdentite = new TabItem("Identité");
                TableLayout tLayout = new TableLayout(2);
                tabIdentite.setLayout(tLayout);
                tabIdentite.setScrollMode(Scroll.AUTO);
                
                panneauIdentite = new ContentPanel();
                panneauIdentite.setWidth("400px");
                panneauIdentite.setHeaderVisible(false);
                panneauIdentite.setBorders(false);
                panneauIdentite.setBodyBorder(false);
                panneauImage = new ContentPanel();
                panneauImage.setLayout(new FlowLayout());
                panneauImage.setBorders(false);
                panneauImage.setWidth(350);
                panneauImage.setBodyBorder(false);
                panneauImage.setHeaderVisible(false);
                
                //Gérer l'alignement vertical en haut
                TableData td = new TableData();
                td.setVerticalAlign(VerticalAlignment.TOP);
                
                tabIdentite.add(panneauIdentite, td);
                tabIdentite.add(panneauImage, td);
                
                                
                fsIdentite = new FieldSet();
                fsIdentite.setLayout(new FormLayout());
                
                
                fsContact = new FieldSet();
                fsContact.setLayout(new FormLayout());
                
                this.add(tabIdentite);
                
                //Onglet Adresse:
                tabAdresse = new TabItem("Adresses");
                fsAdressePerso = new FieldSet();
                fsAdressePerso.setLayout(new FormLayout());
                
                this.add(tabAdresse);
                
                //Onglet info naturalistes
                tabInfosNat = new TabItem("Informations naturalistes");
                
                this.add(tabInfosNat);
                
        }

        public void afficherDetailPersonne(Personne personne) {
                if (personne != null) {
                        
                        
                        //MAJ Identité : Configurer les fieldSet
                        panneauIdentite.removeAll();
                        panneauImage.removeAll();
                        
                        fsIdentite.setHeading("Identité");
                        //fsIdentite.setWidth("350px");
                        
                        fsContact.setHeading("Contact");
                        //fsContact.setWidth("350px");
                        
                        panneauIdentite.add(fsIdentite);
                        
                        
                        //La personne peut avoir un ou plusieurs logo
                        panneauImage.setHeight("100%");
                        panneauImage.setPosition(0, 6);
                        panneauImage.setBorders(false);
                        
                        LinkedList<String> listeLogos = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
                        if ((listeLogos != null)&&(listeLogos.size() > 0))      {
                                panneauImage.setBorders(true);
                                for (int i = 0; i < listeLogos.size(); i++)     {
                                        String logoUrl = listeLogos.get(i);
                                        if ((logoUrl!=null)&&(!logoUrl.trim().equals("")))      {
                                                //Si c'est le cas, on l'affiche sur la même ligne que fsIdentité
                                                Image img = new Image();
                                                img.setUrl(logoUrl);
                                                                        
                                                panneauImage.add(img);                  
                                                if (panneauImage.getWidth() < (img.getWidth() + 15))    {
                                                        panneauImage.setWidth(img.getWidth() + 15);
                                                }
                                                
                                        }
                                }
                                
                        }
                        
                        panneauIdentite.add(fsContact);
                        
                        fsIdentite.removeAll();
                        fsContact.removeAll();
                        fsAdressePerso.removeAll();
                        //Ajout des champs Identité
                        
                        
                        
                        // TODO: projet
                        
                        // nom complet
                        Object nomComplet = personne.obtenirValeurChamp("fmt_nom_complet");
                        ajouterTextFieldNonEditable(fsIdentite,"Nom Complet", nomComplet);
                        
                        // Nom autre : champ truk; non-typé
                        LinkedList<String> nomsAutre = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_nom_autre");
                        if ((nomsAutre != null)&&(nomsAutre.size() > 0))        {
                                
                                LabelField noms = new LabelField();
                                noms.setFieldLabel("Autres noms:");
                                String listeNoms = UtilTruk.traiterTrukListe(nomsAutre, ", ");                          
                                noms.setValue(listeNoms);
                                fsIdentite.add(noms);                           
                        }
                        
                        // abreviation
                        Object abreviation = personne.obtenirValeurChamp("abreviation");
                        ajouterTextFieldNonEditable(fsIdentite, "Abreviation", abreviation);
                        
                        // Abréviations, autre : non-typé
                        LinkedList<String> abrevAutres = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_abreviation_autre");
                        if ((abrevAutres != null)&&(abrevAutres.size() > 0))    {
                                
                                LabelField abreviations = new LabelField();
                                abreviations.setFieldLabel("Autres abreviations:");
                                String listeAbrev = UtilTruk.traiterTrukListe(abrevAutres, ", ");
                                abreviations.setValue(listeAbrev);
                                fsIdentite.add(abreviations);                           
                        }
                        fsIdentite.addText("<hr>");
                        
                        // date naissance 
                        // TODO : Mettre la date en format FR 10/12/09
                        Object dateNaissance = personne.obtenirValeurChamp("naissance_date");
                        ajouterTextFieldNonEditable(fsIdentite, "Né le", dateNaissance);
                                                
                        // lieu naissance
                        Object lieuNaissance = personne.obtenirValeurChamp("naissance_lieu");
                        ajouterTextFieldNonEditable(fsIdentite, "A", lieuNaissance);
                        
                        // date deces
                        Object dateDeces = personne.obtenirValeurChamp("deces_date");
                        ajouterTextFieldNonEditable(fsIdentite, "Date décès", dateDeces);
                        
                        // lieu deces
                        Object lieuDeces = personne.obtenirValeurChamp("deces_lieu");
                        ajouterTextFieldNonEditable(fsIdentite, "Lieu de décès", lieuDeces);
                        
                        fsIdentite.addText("<hr>");
                        
                        //Description
                        String description = (String) personne.obtenirValeurChamp("description");
                        if ((description!=null)&&(!description.trim().equals("")))      {
                                LabelField txtDescription = new LabelField();
                                txtDescription.setFieldLabel("Description:");
                                txtDescription.setValue(description);
                                
                                //rendreNonEditable(txtDescription);
                                
                                fsIdentite.add(txtDescription);
                        }
                        
                        
                        // CONTACT
                        // Téléphones
                        // > Plusieurs téléphones possible, typés
                        Constantes constantesI18n = (Constantes) GWT.create(Constantes.class);
                        
                        HashMap<String, String> mapTelephones = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
                        if ((mapTelephones != null)&&(mapTelephones.size() > 0))        {
                                
                                Collection<String> telephoneKeys = mapTelephones.keySet();
                                Iterator<String> itTelephones = telephoneKeys.iterator();
                                
                                while (itTelephones.hasNext())  {
                                        String key = itTelephones.next();
                                        LabelField telephoneLabel = new LabelField();
                                        String label = "";
                                        try {
                                                label = constantesI18n.getString(key);
                                        }
                                        catch (MissingResourceException e)      {
                                                label = key;
                                        }
                                        
                                        telephoneLabel.setFieldLabel( label + ":");
                                        
                                        telephoneLabel.setValue(mapTelephones.get(key));
                                        
                                        fsContact.add(telephoneLabel);
                                }
                        }
                        
                        // Fax
                        // > Plusieurs fax possible, typés
                        
                        HashMap<String, String> mapFax = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_fax");
                        if ((mapFax != null)&&(mapFax.size() > 0))      {
                                
                                Collection<String> faxKeys = mapFax.keySet();
                                Iterator<String> itFax = faxKeys.iterator();
                                
                                while (itFax.hasNext()) {
                                        String key = itFax.next();
                                        LabelField faxLabel = new LabelField();
                                        String label = "";
                                        try {
                                                label = constantesI18n.getString(key);
                                        }
                                        catch (MissingResourceException e)      {
                                                label = key;
                                        }
                                        
                                        faxLabel.setFieldLabel( label + ":");
                                        
                                        faxLabel.setValue(mapTelephones.get(key));
                                        
                                        fsContact.add(faxLabel);
                                }
                        }
                        
                        // Courriel
                        // Courriel est un champ truk de la forme "Adresse@adr.com;; adr2@adr.fr ..."
                        
                        LinkedList<String> listeCourriel = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
                        if ((listeCourriel!=null)&&(listeCourriel.size() > 0))  {
                                String strLabelCourriel = "Courriel";
                                if (listeCourriel.size() > 1)   {
                                        strLabelCourriel += "s";        
                                }
                                
                                LabelField labelCourriel = new LabelField();
                                labelCourriel.setFieldLabel(strLabelCourriel);
                                
                                String valeurCourriel = "";
                                Iterator<String> itCourriel = listeCourriel.iterator();
                                while (itCourriel.hasNext())    {
                                        String valeurCourante = itCourriel.next();
                                        valeurCourriel += "<a href=\"mailto:" + valeurCourante + "\">" + valeurCourante + "</a><br />";
                                                                                
                                }
                                
                                labelCourriel.setValue(valeurCourriel);
                                fsContact.add(labelCourriel);
                        }
                        
                        
                        // Url Site Webs
                        LinkedList listeUrl = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_url");
                        if (listeUrl!=null && listeUrl.size() > 0)      {
                                String strUrl = "";
                                Iterator<String> urlIt = listeUrl.iterator();
                                while (urlIt.hasNext()) {
                                        String urlCourante = urlIt.next();
                                        strUrl += "<a href=\""+urlCourante+"\">" + urlCourante + "</a> <br/>";
                                        
                                        
                                }
                                
                                LabelField urlLabelField = new LabelField();
                                urlLabelField.setFieldLabel("Url:");
                                urlLabelField.setValue(strUrl);
                                fsContact.add(urlLabelField);
                        }
                        
                        
                        panneauIdentite.add(fsContact);
                        
                        
                        fsAdressePerso.setHeading("Adresse personnelle");
                        
                        /*
                         * Adresses :
                         * */
                        String adresse01 = (String) personne.obtenirValeurChamp("adresse_01");
                        ajouterTextFieldNonEditable(fsAdressePerso, "Adresse", adresse01);
                        
                        
                        String adresse02 = (String) personne.obtenirValeurChamp("adresse_02");
                        ajouterTextFieldNonEditable(fsAdressePerso, "", adresse02);
                        
                        String boitePostale = (String) personne.obtenirValeurChamp("bp");
                        ajouterTextFieldNonEditable(fsAdressePerso, "Boite Postale", boitePostale);
                        
                        String codePostal = (String) personne.obtenirValeurChamp("code_postal");
                        ajouterTextFieldNonEditable(fsAdressePerso, "Code postal", codePostal);
                        
                        String ville = (String) personne.obtenirValeurChamp("ville");
                        ajouterTextFieldNonEditable(fsAdressePerso, "Ville", ville);
                        
                        String region = (String) personne.obtenirValeurChamp("region");
                        ajouterTextFieldNonEditable(fsAdressePerso, "Région", region);
                        
                        String pays = (String) personne.obtenirValeurChamp("pays");
                        ajouterTextFieldNonEditable(fsAdressePerso, "Pays", pays);
                        
                        fsAdressePerso.addText("<br >");        
                        fsAdressePerso.setWidth("350px");
                        
                        tabAdresse.add(fsAdressePerso);
                        tabAdresse.setScrollMode(Scroll.AUTO);
                        

                        /*
                         *      Infos naturalistes 
                         * */
                        
                        // Biographie
                        // tabInfosNat
                        layout();
                } 
        }

        private void ajouterTextFieldNonEditable(FieldSet fs, String tfLabel, Object tfValue)   {
        
                if ((tfValue!=null)&&(!tfValue.toString().trim().equals("")))   {
                        
                        
                        LabelField tf = new LabelField();
                
                        tf.setFieldLabel(tfLabel + ":");
                        if ((tfLabel==null)||("".equals(tfLabel)))      {
                                tf.setHideLabel(true);
                                tf.setStyleAttribute("margin", "0 0 0 105px");
                        }
                        tf.setValue(tfValue);
                
                        // Non éditable : on empêche l'évènement par défaut
                        // > MAJ 27/07 : inutile avec LabelField
                        //rendreNonEditable(tf);
                         
                        //Ajout au fieldSet
                        fs.add(tf);
                }
        }
        
        /*
         * private void rendreNonEditable(Field field)  {
                        
                field.addKeyListener(new KeyListener()  {
                        public void componentKeyPress(ComponentEvent ev)        {
                                ev.stopEvent();
                        }
                        });
        }
        */
                
        
        public void rafraichir(Object nouvelleDonnees) {
                
                // Si on a reçu une personne on en affiche les détails
                if (nouvelleDonnees instanceof Personne) {
                        afficherDetailPersonne((Personne) nouvelleDonnees);
                } 
        }

}