Subversion Repositories eFlore/Applications.coel

Rev

Rev 472 | Blame | Compare with Previous | 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.ComposantClass;
import org.tela_botanica.client.ComposantId;
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.Configuration;
import org.tela_botanica.client.modeles.Personne;
import org.tela_botanica.client.modeles.Valeur;
import org.tela_botanica.client.modeles.ValeurListe;
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.util.Format;
import com.extjs.gxt.ui.client.util.Params;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HtmlContainer;
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.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.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.google.gwt.user.client.ui.Image;

public class PersonneDetailVue extends LayoutContainer implements Rafraichissable {

        
        private LayoutContainer lcDetailHaut;
        
        // Le panneau détail se compose de formulaires tabulés
        private TabPanel tabPanel;
        
        // Onglet 1 : identite & contact
        private TabItem tabIdentite;
        
        
        // Onglet 2 : Adresses
        private TabItem tabAdresse;
        
        // Onglet 3 : Informations naturalistes
        private TabItem tabInfosNat;
        private FieldSet fsSpec;
        
        //Onglet 4 : logos
        private TabItem tabLogos;
        
        
        private Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
        
        public PersonneDetailVue() {
                
                setLayout(new RowLayout());
                
                ContentPanel cp = new ContentPanel();
                cp.setLayout(new FlowLayout());
                
                lcDetailHaut = new LayoutContainer();
                lcDetailHaut.setLayout(new RowLayout());
                //this.add(lcDetailHaut, new RowData(1, 0.2));
                cp.setTopComponent(lcDetailHaut);
                
                add(lcDetailHaut);
            
            
                tabPanel = new TabPanel();
                this.add(tabPanel, new RowData(1, 1));
                
                //Constructeur de la classe
                Registry.register(RegistreId.PANNEAU_PERSONNE_DETAIL, this);
                //setLayout(new FitLayout());
                
                tabIdentite = new TabItem(mediateur.i18nC.personneIdentite());
                tabIdentite.setLayout(new FitLayout());
                tabIdentite.setScrollMode(Scroll.AUTO);
                                
                tabPanel.add(tabIdentite);
                
                //Onglet Adresse:
                tabAdresse = new TabItem(mediateur.i18nC.personneAdresses());
                tabAdresse.setLayout(new FitLayout());
                tabAdresse.setScrollMode(Scroll.AUTO);
                tabPanel.add(tabAdresse);
                
                //Onglet info naturalistes
                tabInfosNat = new TabItem(mediateur.i18nC.personneInfoNat());
                fsSpec = new FieldSet();
                fsSpec.setLayout(new FormLayout());
                tabInfosNat.setScrollMode(Scroll.AUTO);
                
                tabPanel.add(tabInfosNat);
                
                tabLogos = new TabItem(mediateur.i18nC.personneLogos());
                tabLogos.setLayout(new FlowLayout());
                
                tabPanel.add(tabLogos);
        }

        
        private HashMap hmLabelFieldRegion = new HashMap();
        
        public void afficherDetailPersonne(Personne personne) {
                if (personne != null) {
                        
                        String enteteTpl = "<div id='{css_id}'>"+
                           "<h1>{nom}</h1>"+
                           "<h2><a href='{mail}'>{mail}</a></h2>" +
                           "</div>";
                        
                        //MAJ Identité : Configurer les fieldSet
                        Params enteteParams = new Params();
                        enteteParams.set("css_id", ComposantId.ZONE_DETAIL_ENTETE);
                        enteteParams.set("nom", (String) personne.get("fmt_nom_complet"));
                        enteteParams.set("mail", (String) personne.get("courriel_princ"));
                        
                        LinkedList lstLogos = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_logo");                       
                        if (lstLogos!=null && lstLogos.size() > 0)      {
                                
                                tabLogos.removeAll();
                                String urlLogoPrinc = (String) lstLogos.get(0);
                                if (!urlLogoPrinc.trim().equals(""))    {
                                        enteteTpl = "<div style='position:absolute; right:0; width:30%; text-align:right'><img src='{image}' alt='logo' height='45px'/></div>" + enteteTpl;
                                        enteteParams.set("image", urlLogoPrinc);
                                }
                                
                                Iterator<String> itLogo = lstLogos.iterator();
                                while (itLogo.hasNext()){
                                        String urlLogoCourant = itLogo.next();
                                        Image imgCourante = new Image(urlLogoCourant);
                                        tabLogos.add(imgCourante);              
                                }
                                
                                tabLogos.enable();                      
                        } else {
                                enteteParams.set("image", "");
                                tabLogos.disable();
                        }
                        
                        lcDetailHaut.el().setInnerHtml(Format.substitute(enteteTpl, enteteParams));
                        
                        String tabIdentiteTpl = "<div class='{css_id}'>" +
                        " <span><b>" + mediateur.i18nC.personneNomComplet() + ":</b></span> {nom_complet}<br />" +
                        " <span><b>" + mediateur.i18nC.personneNomAutre() + ":</b></span> {nom_autre}<br />" +
                        " <span><b>" + mediateur.i18nC.personneAbreviation() + ":</b></span> {abreviation}<br />" +
                        " <span><b>" + mediateur.i18nC.personneAbreviationAutre() + ":</b></b></span> {abreviation_autre}<br /><br />" +
                        " <span><b>" + mediateur.i18nC.personneDateNaissance() + "</b></span> {naissance_date}<br />" +
                        " <span><b>" + mediateur.i18nC.personneLieuNaissance() + ":</b></span> {naissance_lieu}<br /><br />" +
                        " <span><b>" + mediateur.i18nC.personneDateDeces() + ":</b></span> {deces_date}<br />" +
                        " <span><b>" + mediateur.i18nC.personneLieuDeces() + ":</b></span> {deces_lieu}<br /><br />" +
                        "</div>" +
                        "<div class='{css_id}'>" +
                        "       <span style='vertical-align:top'><b>" + mediateur.i18nC.description() + ":</b><br /></span> {description}<br />" +
                        "<br />";
                        
                        Params tabIdentiteParams = new Params();
                        tabIdentiteParams.set("css_id", "coel-fieldset");
                        tabIdentiteParams.set("nom_complet", personne.getString("fmt_nom_complet"));
                        tabIdentiteParams.set("abreviation", personne.getString("abreviation"));
                        tabIdentiteParams.set("naissance_date", personne.getString("naissance_date"));
                        tabIdentiteParams.set("naissance_lieu", personne.getString("naissance_lieu"));
                        tabIdentiteParams.set("deces_date", personne.getString("deces_date"));
                        tabIdentiteParams.set("deces_lieu", personne.getString("deces_lieu"));
                        tabIdentiteParams.set("description", personne.getString("description"));
                        
                        tabInfosNat.removeAll();
                        
                        // Nom autre : champ truk; non-typé
                        LinkedList<String> nomsAutre = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_nom_autre");
                        String listeNoms = "";
                        if ((nomsAutre != null)&&(nomsAutre.size() > 0))        {
                                listeNoms = UtilTruk.traiterTrukListe(nomsAutre, ", ");                         
                        }
                        tabIdentiteParams.set("nom_autre", listeNoms);
                        
                        // Abréviations, autre : non-typé
                        LinkedList<String> abrevAutres = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_abreviation_autre");
                        String listeAbrev = "";
                        if ((abrevAutres != null)&&(abrevAutres.size() > 0))    {
                                listeAbrev = UtilTruk.traiterTrukListe(abrevAutres, ", ");
                        }
                        tabIdentiteParams.set("abreviation_autre", listeAbrev);
                        
                        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();
                                        String label = mapTelephones.get(key);
                                        try {
                                                label = mediateur.i18nC.getString(label);
                                        }
                                        catch (MissingResourceException e)      {
                                                label = key;
                                        }
                                        
                                        tabIdentiteTpl += "<b>" + label + ":</b> " + key;
                                        tabIdentiteTpl += "<br />";
                                }
                        }
                        
                        // FAX > TYPE Téléphone
                        
                        // Courriel :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";        
                                }
                                
                                String valeurCourriel = "";
                                Iterator<String> itCourriel = listeCourriel.iterator();
                                while (itCourriel.hasNext())    {
                                        String valeurCourante = itCourriel.next();
                                        valeurCourriel += "<br /><a href=\"mailto:" + valeurCourante + "\">" + valeurCourante + "</a>";
                                                                                
                                }
                                
                                tabIdentiteTpl += valeurCourriel;
                        }

                        // Url Site Webs
                        LinkedList listeUrl = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_url");
                        if (listeUrl!=null && listeUrl.size() > 0)      {
                                
                                tabIdentiteTpl += "<br /><br /><b>Sites web:</b><br /><span style='display:inline-block'>";
                                String strUrl = "";
                                Iterator<String> urlIt = listeUrl.iterator();
                                while (urlIt.hasNext()) {
                                        String urlCourante = urlIt.next();
                                        strUrl += "<a href=\""+urlCourante+"\">" + urlCourante + "</a> <br/>";
                                }
                                
                                tabIdentiteTpl += strUrl + "</span><br />";
                        }                       
                        
                        tabIdentiteTpl += "</div>";
                        
                        afficherOnglet(tabIdentiteTpl, tabIdentiteParams, tabIdentite);
                        tabIdentite.setStyleAttribute("padding", "15px");
                        
                        String tabAdresseTpl =  "<div id='css_id'>" +
                                                                        "       <h1>Adresse personnelle:</h1>" +
                                                                        "       {adresse01} <br />" +
                                                                        "       {adresse02} <br />" +
                                                                        "       {boitePostale}<br />" +
                                                                        "       {codePostal} {region}<br />" +
                                                                        "       <span style='uppercase'>{pays}</span><br />" +
                                                                        "</div>";
                        //Adresses :
                        Params paramAdresseTpl = new Params();
                        paramAdresseTpl.set("adresse01", (String) personne.obtenirValeurChamp("adresse_01"));
                        paramAdresseTpl.set("adresse02", (String) personne.obtenirValeurChamp("adresse_02"));
                        paramAdresseTpl.set("boitePostale", (String) personne.obtenirValeurChamp("bp"));
                        paramAdresseTpl.set("codePostal", (String) personne.obtenirValeurChamp("code_postal"));
                        paramAdresseTpl.set("ville", (String) personne.obtenirValeurChamp("ville"));
                        paramAdresseTpl.set("region", (String) personne.obtenirValeurChamp("region"));
                        paramAdresseTpl.set("pays",  (String) personne.obtenirValeurChamp("pays"));
                        
                        afficherOnglet(tabAdresseTpl, paramAdresseTpl, tabAdresse);
                        tabAdresse.setStyleAttribute("padding", "15px");

                        // Infos naturalistes :Biographie, Spécialité (typé)
                        
                        fsSpec.setHeading("Spécialités");
                        tabInfosNat.add(fsSpec);
                        
                        HashMap hmSpecialite = (HashMap) personne.getChaineDenormaliseAsMapOrList("ce_truk_specialite");
                        if ((hmSpecialite != null)&&(hmSpecialite.size() > 0))  {
                                
                                Collection<String> specialiteKeys = hmSpecialite.keySet();
                                Iterator<String> itSpec = specialiteKeys.iterator();
                                
                                while (itSpec.hasNext())        {
                                        String key = itSpec.next();
                                        LabelField specLabel = new LabelField();
                                        String label = "";
                                        try {
                                                label = mediateur.i18nC.getString(key);
                                        }
                                        catch (MissingResourceException e)      {
                                                label = key;
                                        }
                                        
                                        specLabel.setFieldLabel( label + ":");
                                        
                                        specLabel.setValue(hmSpecialite.get(key));
                                        
                                        fsSpec.add(specLabel);
                                }
                        }
                        
                        // Récolte
                        LinkedList<String> lstRecolte = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_recolte");
                        if ((lstRecolte!=null)&&(lstRecolte.size()>0))  {
                                FieldSet fsRecolte = new FieldSet();
                                fsRecolte.setHeading("Récoltes");
                                fsRecolte.setLayout(new FormLayout());
                                
                                Iterator<String> itRecolte = lstRecolte.iterator();
                                while (itRecolte.hasNext())     {
                                        
                                        String recolteCourante = itRecolte.next();
                                        LabelField lfRecolte = new LabelField();
                                        String[] splitRecolte = recolteCourante.split("\\|");
                                        
                                        String labelRecolte = "";
                                        if (splitRecolte.length > 1)    {
                                                lfRecolte.setValue(splitRecolte[1]);
                                        }
                                        
                                        lfRecolte.setFieldLabel(splitRecolte[0]);
                                        fsRecolte.add(lfRecolte);
                                        
                                        LinkedList<LabelField> lstComposantsRegion = (LinkedList<LabelField>) hmLabelFieldRegion.get(splitRecolte[0]);
                                        
                                        if (lstComposantsRegion == null)        {
                                                lstComposantsRegion = new LinkedList<LabelField>();
                                        }
                                        
                                        lstComposantsRegion.add(lfRecolte);
                                        hmLabelFieldRegion.remove(splitRecolte[0]);
                                        hmLabelFieldRegion.put(splitRecolte[0], lstComposantsRegion);
                                                                        
                                }
                                
                                tabInfosNat.add(fsRecolte);
                        }
                        
                        changerLabelRegions();
                        // tabInfosNat
                        layout();
                } 
        }
        
        protected void afficherOnglet(String template, Params parametres, TabItem onglet) {
                String cHtml = Format.substitute(template, parametres);
                
                Params cssParams = new Params();
                cssParams.set("css_corps", ComposantClass.DETAIL_CORPS_CONTENU);
                cssParams.set("css_label", ComposantClass.LABEL);
                cssParams.set("css_indentation", ComposantClass.INDENTATION);
                cssParams.set("css_fieldset", ComposantClass.FIELDSET);
                cssParams.set("css_clear", ComposantClass.CLEAR);
                cHtml = Format.substitute(cHtml, cssParams);
                
                HtmlContainer corpsConteneurDuHtml = new HtmlContainer(cHtml);
                onglet.removeAll();
                onglet.add(corpsConteneurDuHtml);               
        }
        
        
        private void changerLabelRegions()      {
                
                Collection<String> colClesComposants = hmLabelFieldRegion.keySet();
                Iterator<String> itComposants = colClesComposants.iterator();
                
                while (itComposants.hasNext())  {
                        String region = itComposants.next();
                        mediateur.obtenirValeurEtRafraichir(this, "region", region);
                }
        }

        private void ajouterLabelField(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);
                
                        //Ajout au fieldSet
                        fs.add(tf);
                }
        }
        
        
                
        private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
        
        public void rafraichir(Object nouvellesDonnees) {
                
                // Si on a reçu une personne on en affiche les détails
                if (nouvellesDonnees instanceof Personne) {
                        afficherDetailPersonne((Personne) nouvellesDonnees);
                } else if (nouvellesDonnees instanceof ValeurListe)     {
                        
                        ValeurListe listeValeur = (ValeurListe) nouvellesDonnees;
                        if (listeValeur.getId().equals(config.getListeId("region")))    {
                                
                                Collection colCleListeValeur = listeValeur.keySet();
                                
                                Iterator<String> itLv = colCleListeValeur.iterator();
                                
                                while (itLv.hasNext())  {
                                        String idRegion = itLv.next();
                                        Valeur region = listeValeur.get(idRegion);
                                        
                                        
                                        
                                        if (region != null)     {
                                                
                                                String strRegionId = region.getAbreviation();
                                                
                                                LinkedList<LabelField> listComposantsRegion = (LinkedList) hmLabelFieldRegion.get(strRegionId);
                                                for (int i=0; i < listComposantsRegion.size(); i++)     {
                                                        LabelField lfRegion = listComposantsRegion.get(i);
                                                        lfRegion.setFieldLabel(region.getNom());        
                                                }
                                        
                                        }
                                }
                        }
                }
        }

}