Subversion Repositories eFlore/Applications.coel

Rev

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

package org.tela_botanica.client.vues;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;

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.i18n.Constantes;
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.Structure;
import org.tela_botanica.client.modeles.StructureAPersonne;
import org.tela_botanica.client.modeles.StructureAPersonneListe;
import org.tela_botanica.client.modeles.StructureConservation;
import org.tela_botanica.client.modeles.StructureValorisation;
import org.tela_botanica.client.modeles.Valeur;
import org.tela_botanica.client.modeles.ValeurListe;

import com.extjs.gxt.ui.client.Events;
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.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Html;
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.layout.AnchorLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;

public class StructureDetailPanneauVue extends LayoutContainer implements Rafraichissable {

        private Mediateur mediateur = null;
        private Constantes i18nC = null;
        
        private String enteteTpl = null;
        private String identificationTpl = null;
        private String personnelTpl = null;
        private String tableauPersonnelTpl = null;
        private String lignePersonnelTpl = null;
        private String conservationTpl = null;
        private String valorisationTpl = null;
        private String sautLigneTpl = null;
        
        private Structure structure = null;
        private StructureAPersonneListe personnel = null;
        private StructureValorisation valorisation = null;
        private StructureConservation conservation = null;
        
        private ContentPanel panneauPrincipal = null;
        private Html entete = null;
        private TabPanel onglets = null;
        private TabItem identificationOnglet = null;
        private TabItem personnelOnglet = null;
        private TabItem conservationOnglet = null;
        private TabItem valorisationOnglet = null;
        
        private Params identificationParams = null;
        private Params personnelParams = null;
        private Params conservationParams = null;
        
        public StructureDetailPanneauVue(Mediateur mediateurCourant) {
                mediateur = mediateurCourant;
                i18nC = mediateur.i18nC; 
                initialiserTousLesTpl();
                
                setLayout(new FitLayout());
                setBorders(false);
                setScrollMode(Scroll.AUTO);
                
                conservationParams  = new Params();
                
                mediateur.obtenirListeValeurEtRafraichir(this, "localStockage");
                mediateur.obtenirListeValeurEtRafraichir(this, "meubleStockage");
                mediateur.obtenirListeValeurEtRafraichir(this, "parametreStockage");
                
                panneauPrincipal = new ContentPanel();
                panneauPrincipal.setLayout(new FlowLayout());
                panneauPrincipal.setHeaderVisible(false);
                panneauPrincipal.setBodyBorder(false);
                        
            entete = new Html();
            entete.setId(ComposantId.ZONE_DETAIL_ENTETE);
            panneauPrincipal.setTopComponent(entete);
                
                onglets = new TabPanel();
                onglets.setId(ComposantId.ZONE_DETAIL_CORPS);
                onglets.setHeight("100%");
                onglets.setBodyBorder(false);

                identificationOnglet = new TabItem("Général");
                identificationOnglet.setLayout(new AnchorLayout());
                identificationOnglet.setScrollMode(Scroll.AUTO);
                onglets.add(identificationOnglet);
                
                personnelOnglet = new TabItem("Personnel");
                personnelOnglet.setLayout(new AnchorLayout());
                personnelOnglet.setScrollMode(Scroll.AUTO);
                onglets.add(personnelOnglet);
                
                conservationOnglet = new TabItem("Conservation");
                conservationOnglet.setLayout(new AnchorLayout());
                conservationOnglet.setScrollMode(Scroll.AUTO);
                onglets.add(conservationOnglet);
                
                valorisationOnglet = new TabItem("Valorisation");
                valorisationOnglet.setLayout(new AnchorLayout());
                valorisationOnglet.setScrollMode(Scroll.AUTO);
                onglets.add(valorisationOnglet);
                
                panneauPrincipal.add(onglets);
                add(panneauPrincipal);
        }

        private void afficherDetailInstitution() {
                if (structure != null) {
                        personnel = structure.getPersonnel();
                        valorisation = structure.getValorisation();
                        conservation = structure.getConservation();
                        
                        afficherEntete();
                        afficherIdentification();
                        if (personnel != null) {
                                afficherPersonnel();
                        }
                        if (conservation != null) {
                                afficherConservation();
                        }
                        if (valorisation != null) {
                                //afficherValorisation();
                        }
                }
                layout();
        }
        
        private void afficherEntete() {
                Params enteteParams = new Params();
                enteteParams.set("css_id", ComposantId.ZONE_DETAIL_ENTETE);
                enteteParams.set("css_meta", ComposantClass.META);
                
                enteteParams.set("nom", structure.getNom());
                enteteParams.set("ville", structure.getVille());
                enteteParams.set("id", structure.getId());
                enteteParams.set("guid", structure.getGuid());
                enteteParams.set("projet", structure.getIdProjet());
                
                String eHtml = Format.substitute(enteteTpl, enteteParams);
                entete.getElement().setInnerHTML(eHtml);
        }
        
        private void afficherIdentification() {
                identificationParams = new Params();
                identificationParams.set("css_corps", ComposantClass.DETAIL_CORPS_CONTENU);
                identificationParams.set("css_label", ComposantClass.LABEL);
                identificationParams.set("css_fieldset", ComposantClass.FIELDSET);
                identificationParams.set("css_clear", ComposantClass.CLEAR);
                
                identificationParams.set("i18n_titre_administratif", i18nC.titreAdministratif());
                identificationParams.set("i18n_acronyme", i18nC.acronyme());
                identificationParams.set("i18n_statut", i18nC.statut());
                identificationParams.set("i18n_date_fondation", mediateur.i18nC.dateFondation());
                identificationParams.set("i18n_nbre_personnel", mediateur.i18nC.nbrePersonnel());
                
                identificationParams.set("i18n_titre_description", mediateur.i18nC.description());
                identificationParams.set("i18n_description", mediateur.i18nC.description());
                
                identificationParams.set("i18n_titre_adresse", mediateur.i18nC.adresse());
                identificationParams.set("i18n_adresse", mediateur.i18nC.adresse());
                identificationParams.set("i18n_cp", mediateur.i18nC.codePostal());
                identificationParams.set("i18n_ville", mediateur.i18nC.ville());
                identificationParams.set("i18n_region", mediateur.i18nC.region());
                identificationParams.set("i18n_pays", mediateur.i18nC.pays());
                
                identificationParams.set("i18n_titre_communication", mediateur.i18nC.titreCommunication());
                identificationParams.set("i18n_tel", mediateur.i18nC.telephone());
                identificationParams.set("i18n_fax", mediateur.i18nC.fax());
                identificationParams.set("i18n_courriel", mediateur.i18nC.courriel());
                identificationParams.set("i18n_acces", mediateur.i18nC.acces());
                identificationParams.set("i18n_web", mediateur.i18nC.siteWeb());
                
                identificationParams.set("acronyme", structure.getIdAlternatif());
                identificationParams.set("statut", structure.getTypePrive()+structure.getTypePublic());
                identificationParams.set("date_fondation", structure.getDateFondationFormatLong());
                identificationParams.set("nbre_personnel", structure.getNbrePersonne());
                
                identificationParams.set("description", structure.getDescription());
                
                identificationParams.set("adresse", structure.getAdresse());
                identificationParams.set("cp", structure.getCodePostal());
                identificationParams.set("ville", structure.getVille());
                identificationParams.set("region", structure.getRegion());
                identificationParams.set("pays", structure.getPays());
                
                identificationParams.set("tel", structure.getTelephone());
                identificationParams.set("fax", structure.getFax());
                identificationParams.set("courriel", structure.getCourriel());
                identificationParams.set("acces", structure.getConditionAcces());
                identificationParams.set("web", structure.getUrl());
                
                afficherOnglet(identificationTpl, identificationParams, identificationOnglet);
        }
        
        private void afficherPersonnel() {
                String tableauPersonnelHtml = "";
                if (personnel.size() > 0) {
                        tableauPersonnelHtml = construireTableauDuPersonnel();
                }
                
                personnelParams = new Params();
                personnelParams.set("css_corps", ComposantClass.DETAIL_CORPS_CONTENU);
                personnelParams.set("i18n_titre_personnel", i18nC.titrePersonnel());
                personnelParams.set("i18n_nbre_personnel_collection", i18nC.nbrePersonnelCollection());
                personnelParams.set("nbre_personnel_collection", personnel.size());
                personnelParams.set("tableau_personnel", tableauPersonnelHtml);
                
                afficherOnglet(personnelTpl, personnelParams, personnelOnglet);
        }
        
        private String construireTableauDuPersonnel() {
                Params contenuParams = new Params();
                contenuParams.set("i18n_titre_membre", i18nC.titreMembre());
                contenuParams.set("i18n_fonction", i18nC.fonction());
                contenuParams.set("i18n_prenom", i18nC.prenom());
                contenuParams.set("i18n_nom", i18nC.nom());
                contenuParams.set("i18n_tel", i18nC.telephoneFixe());
                contenuParams.set("i18n_fax", i18nC.fax());
                contenuParams.set("i18n_courriel", i18nC.courrielPrincipal());
                contenuParams.set("i18n_statut", i18nC.statut());
                contenuParams.set("i18n_tps_w", i18nC.tpsTravail());
                contenuParams.set("i18n_specialite", i18nC.specialite());
                contenuParams.set("i18n_contact", i18nC.boolContact());
                
                String lignesPersonnel = ""; 
                Iterator<String> it = personnel.keySet().iterator();
                while (it.hasNext()) {
                        StructureAPersonne personne = personnel.get(it.next());
                        Params ligneParams = new Params();
                        ligneParams.set("fonction", personne.getFonction());
                        ligneParams.set("prenom", personne.getPrenom());
                        ligneParams.set("nom", personne.getNom());
                        ligneParams.set("tel", personne.getTelephone());
                        ligneParams.set("fax", personne.getFax());
                        ligneParams.set("courriel", personne.getCourriel());
                        ligneParams.set("statut", personne.getStatut());
                        ligneParams.set("tps_w", personne.getBotaTravailHebdoTps());
                        ligneParams.set("specialite", personne.afficherSpecialite());
                        ligneParams.set("contact", personne.getContact());
                        lignesPersonnel += Format.substitute(lignePersonnelTpl, ligneParams);
                }
                contenuParams.set("lignes", lignesPersonnel);
                
                String cHtml = Format.substitute(tableauPersonnelTpl, contenuParams);
                return cHtml;
        }
        
        private void afficherConservation() {
                conservationParams.set("css_corps", ComposantClass.DETAIL_CORPS_CONTENU);
                conservationParams.set("css_label", ComposantClass.LABEL);
                conservationParams.set("css_fieldset", ComposantClass.FIELDSET);
                conservationParams.set("css_clear", ComposantClass.CLEAR);
                
                conservationParams.set("i18n_titre_conservation_personnel", i18nC.titreConservationPersonnel());
                conservationParams.set("i18n_formation", i18nC.formation());
                conservationParams.set("i18n_formation_interet", i18nC.formationInteret());
                
                conservationParams.set("i18n_titre_local", i18nC.titreLocal());
                conservationParams.set("i18n_local_specifique", i18nC.localSpecifique());
                conservationParams.set("i18n_meuble_specifique", i18nC.meubleSpecifique());
                conservationParams.set("i18n_local_parametre", i18nC.localParametre());
                
                conservationParams.set("formation", formaterOuiNon(conservation.getFormation()));
                conservationParams.set("formation_info", formaterSautDeLigne(conservation.getFormationInfo()));
                conservationParams.set("formation_interet", formaterOuiNon(conservation.getFormationInteret()));
                conservationParams.set("meuble_specifique", conservation.getStockageMeuble());
                
                conservationParams.set("meuble_specifique", conservation.getStockageMeuble());
                conservationParams.set("local_parametre", conservation.getStockageParametre());
                
                afficherOnglet(conservationTpl, conservationParams, conservationOnglet);
        }
        
        private void afficherOnglet(String template, Params parametres, TabItem onglet) {
                String cHtml = Format.substitute(template, parametres);
                HtmlContainer corpsConteneurDuHtml = new HtmlContainer(cHtml);
                onglet.removeAll();
                onglet.add(corpsConteneurDuHtml);               
        }
        
        private String formaterOuiNon(String chaineAFormater) {
                String txtARetourner = "";
                if (chaineAFormater.equals("0")) {
                        txtARetourner = i18nC.non();
                } else if (chaineAFormater.equals("1")) {
                        txtARetourner = i18nC.oui();
                }
                return txtARetourner;
        }
        
        private String formaterSautDeLigne(String chaineAFormater) {
                String txtARetourner = chaineAFormater.replaceAll("\n", sautLigneTpl);
                return txtARetourner;
        }

        private void initialiserTousLesTpl() {
                initialiserEnteteHtmlTpl();
                initialiserIdentificationTpl();
                initialiserPersonnelTpl();
                initialiserTableauPersonnelTpl();
                initialiserLignePersonnelTpl();
                initialiserConservationTpl();
                initialiserValorisationTpl();
                initialiserSautLigneTpl();
        }
        
        private void initialiserEnteteHtmlTpl() {
                enteteTpl =     "<div id='{css_id}'>"+
                                                "       <h1>{nom}</h1>"+
                                                "       <h2>{ville}<span class='{css_meta}'>{projet} - {id} - {guid}</span></h2>" +
                                                "       " +
                                                "</div>";
        }
        
        private void initialiserIdentificationTpl() {
                identificationTpl =
                                                "<div class='{css_corps}'>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_administratif}</h2>"+
                                                "               <span class='{css_label}'>{i18n_acronyme} :</span> {acronyme}<br />"+
                                                "               <span class='{css_label}'>{i18n_acces} :</span> {acces}<br />"+
                                                "               <span class='{css_label}'>{i18n_statut} :</span> {statut}<br />"+
                                                "               <span class='{css_label}'>{i18n_date_fondation} :</span> {date_fondation}<br />"+
                                                "               <span class='{css_label}'>{i18n_nbre_personnel} :</span> {nbre_personnel}<br />"+
                                                "       </div>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_description}</h2>"+
                                                "               {description}"+
                                                "       </div>"+
                                                "       <hr class='{css_clear}'/>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_adresse}</h2>"+
                                                "               <span class='{css_label}'>{i18n_adresse} :</span> {adresse}<br />" +
                                                "               <span class='{css_label}'>{i18n_cp} :</span> {cp}<br />" +
                                                "               <span class='{css_label}'>{i18n_ville} :</span> {ville}<br />" +
                                                "               <span class='{css_label}'>{i18n_region} :</span> {region}<br />" +
                                                "               <span class='{css_label}'>{i18n_pays} :</span> {pays}<br />" +
                                                "       </div>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_communication}</h2>"+
                                                "               <span class='{css_label}'>{i18n_tel} :</span> {tel}<br />"+
                                                "               <span class='{css_label}'>{i18n_fax} :</span> {fax}<br />"+
                                                "               <span class='{css_label}'>{i18n_courriel} :</span> {courriel}<br />"+
                                                "               <span class='{css_label}'>{i18n_web} :</span> {web}<br />"+
                                                "       </div>"+
                                                "</div>";
        }
        
        private void initialiserPersonnelTpl() {
                personnelTpl =
                                                "<div class='{css_corps}'>"+
                                                "       <h2>{i18n_titre_personnel}</h2>"+
                                                "       <p><span class='{css_label}'>{i18n_nbre_personnel_collection} :</span> {nbre_personnel_collection}</p>"+
                                                "       {tableau_personnel}"+
                                                "</div>";
        }
        
        private void initialiserTableauPersonnelTpl() {
                tableauPersonnelTpl =
                                                "<h3>{i18n_titre_membre}</h3>"+
                                                "<table>"+
                                                "       <thead>"+
                                                "               <tr>" +
                                                "                       <th>{i18n_fonction}</th>" +
                                                "                       <th>{i18n_prenom}</th>" +
                                                "                       <th>{i18n_nom}</th>" +
                                                "                       <th>{i18n_tel}</th>" +
                                                "                       <th>{i18n_fax}</th>" +
                                                "                       <th>{i18n_courriel}</th>" +
                                                "                       <th>{i18n_statut}</th>" +
                                                "                       <th>{i18n_tps_w}</th>" +
                                                "                       <th>{i18n_specialite}</th>" +
                                                "                       <th>{i18n_contact}</th>" +
                                                "               </tr>"+
                                                "       </thead>"+
                                                "       <tbody>"+
                                                "               {lignes}"+
                                                "       </tbody>"+
                                                "</table>";
        }
        
        private void initialiserLignePersonnelTpl() {
                lignePersonnelTpl =
                                                "<tr>"+
                                                "       <td>{fonction}</td>"+
                                                "       <td>{prenom}</td>"+
                                                "       <td>{nom}</td>"+
                                                "       <td>{tel}</td>" +
                                                "       <td>{fax}</td>" +
                                                "       <td>{courriel}</td>" +
                                                "       <td>{statut}</td>" +
                                                "       <td>{tps_w}</td>" +
                                                "       <td>{specialite}</td>" +
                                                "       <td>{contact}</td>" +
                                                "</tr>";
        }
        
        private void initialiserConservationTpl() {
                conservationTpl =
                                                "<div class='{css_corps}'>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_conservation_personnel}</h2>"+
                                                "               <span class='{css_label}'>{i18n_formation} :</span> {formation}<br />"+
                                                "               {formation_info}<br />"+
                                                "               <span class='{css_label}'>{i18n_formation_interet} :</span> {formation_interet}<br />"+
                                                "       </div>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_local}</h2>"+
                                                "               <span class='{css_label}'>{i18n_local_specifique} :</span> {local_specifique}<br />"+
                                                "               <span class='{css_label}'>{i18n_meuble_specifique} :</span> {meuble_specifique}<br />"+
                                                "               <span class='{css_label}'>{i18n_local_parametre} :</span> {local_parametre}<br />"+
                                                "               <span class='{css_label}'>{i18n_conservation_en_commun} :</span> {conservation_en_commun}<br />"+
                                                "               <span class='{css_label}'>{i18n_acces_control} :</span> {acces_control}<br />"+
                                                "       </div>"+
                                                "       <hr class='{css_clear}'/>"+
                                                "</div>";
        }
        
        private void initialiserValorisationTpl() {
                valorisationTpl =
                                                "<div class='{css_corps}'>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_action_valorisation}</h2>"+
                                                "       </div>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_recherche_scientifique}</h2>"+
                                                "       </div>"+
                                                "       <hr class='{css_clear}'/>"+
                                                "       <div class='{css_fieldset}'>"+
                                                "               <h2>{i18n_titre_acces_usage}</h2>"+
                                                "       </div>"+
                                                "</div>";
        }
        
        private void initialiserSautLigneTpl() {
                sautLigneTpl = "<br />\n";
        }
                
        public void rafraichir(Object nouvelleDonnees) {
                if (nouvelleDonnees instanceof Structure) {
                        structure = (Structure) nouvelleDonnees;
                        afficherDetailInstitution();
                } else if (nouvelleDonnees instanceof Information) {
                        Information info = (Information) nouvelleDonnees;
                        if (info.getType().equals("liste_structure_a_personne")) {
                                allouerPersonnelAStructure((StructureAPersonneListe) info.getDonnee(0));
                                afficherDetailInstitution();
                        }
                } else if (nouvelleDonnees instanceof ValeurListe) {
                        ValeurListe ontologie = (ValeurListe) nouvelleDonnees;
                        
                        if (ontologie.size() > 0) {
                                Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
                                
                                if (ontologie.getId().equals(config.getListeId("localStockage"))) {
                                        String chaineAAnalyser = conservation.getStockageLocal();
                                        String chaineAAfficher = construireTxtListeOntologie(ontologie, chaineAAnalyser);
                                        conservationParams.set("local_specifique", chaineAAfficher);
                                        GWT.log(chaineAAfficher, null);
                                }
                        }
                } else {
                        GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
                }
        }
        
        protected String construireTxtListeOntologie(ValeurListe ontologie, String chaineAAnalyser) {
                String chaineAAfficher = "";
                if ((chaineAAnalyser != null) && (!chaineAAnalyser.trim().equals("")))  {
                        String[] valeurs = chaineAAnalyser.split(";;");
                        int nbreValeurs = valeurs.length;
                        if (nbreValeurs > 0)    {
                                for (int i = 0; i < nbreValeurs; i++)   {
                                        if (valeurs[i].contains("##"))  {
                                                
                                        } else {
                                                Valeur valeur = ontologie.get(valeurs[i]);
                                                if (valeur != null) {
                                                        String termeOntologie = valeur.getNom();
                                                        if (i != (nbreValeurs - 1)) {
                                                                termeOntologie += ", ";
                                                        }
                                                        chaineAAfficher += termeOntologie;
                                                        GWT.log("Valeur :"+valeurs[i]+" - Ontologie :"+valeur.getNom(), null);
                                                }
                                        }
                                }
                        }
                }
                return chaineAAfficher;
        }
        
        protected void allouerPersonnelAStructure(StructureAPersonneListe personnel) {
                structure.setPersonnel(personnel);
        }

}