Subversion Repositories eFlore/Applications.coel

Rev

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

package org.tela_botanica.client.vues;

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.Structure;

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.layout.FitLayout;
import com.google.gwt.core.client.GWT;

public class StructureDetailPanneauVue extends LayoutContainer implements Rafraichissable {

        private Mediateur mediateur = null;
        
        private String enteteHTML = "<div class='coel-detail'><h1>{0}</h1><h2>{1}</h2></div>";
        private String contenuHTML = null;
        
        private Structure structure = null;
        
        private ContentPanel panneauPrincipal = null;
        private HtmlContainer entete = null;
        private TabPanel onglets = null;
        private TabItem identificationOnglet = null;

        public StructureDetailPanneauVue(Mediateur mediateurCourant) {
                mediateur = mediateurCourant;
                Registry.register(RegistreId.PANNEAU_INSTITUTION_DETAIL, this);
                initialiserEnteteHtmlTpl();
                initialiserContenuHtmlTpl();
                
                setLayout(new FitLayout());
                setBorders(false);
                setScrollMode(Scroll.AUTO);
                
                panneauPrincipal = new ContentPanel();
                
                entete = new HtmlContainer();
                
                onglets = new TabPanel();
                onglets.setAutoHeight(true);
                onglets.setAutoWidth(true);
                
                identificationOnglet = new TabItem("Général");
                onglets.add(identificationOnglet);
                
                panneauPrincipal.add(entete);
                panneauPrincipal.add(onglets);
                add(panneauPrincipal);
        }

        private void afficherDetailInstitution(Structure structureCourante) {
                removeAll();
                if (structureCourante != null) {
                        structure = structureCourante;

                        afficherEntete();
                        afficherIdentification();
                }
                panneauPrincipal.layout();
        }
        
        private void afficherEntete() {
                Params enteteParams = new Params();
                enteteParams.add(ComposantId.ZONE_DETAIL);
                enteteParams.add(structure.getNom());
                enteteParams.add(structure.getVille());
                
                String eHtml = Format.substitute(enteteHTML, enteteParams);
                entete.getElement().setInnerHTML(eHtml);
        }
        
        private void afficherIdentification() {
                Params contenuParams = new Params();
                contenuParams.add(structure.getDescription());
                contenuParams.add(structure.getAdresse());
                contenuParams.add(structure.getCodePostal());
                contenuParams.add(structure.getVille());
                contenuParams.add(structure.getRegion());
                contenuParams.add(structure.getPays());
                contenuParams.add(structure.getTelephone());
                contenuParams.add(structure.getFax());
                contenuParams.add(structure.getCourriel());
                contenuParams.add(structure.getConditionAcces());
                contenuParams.add(ComposantId.ZONE_DETAIL_CORPS);

                String cHtml = Format.substitute(contenuHTML, contenuParams);
                HtmlContainer corpsConteneurDuHtml = new HtmlContainer(cHtml);
                identificationOnglet.add(corpsConteneurDuHtml);
        }
        
        private void initialiserEnteteHtmlTpl() {
                enteteHTML =    "<div id='{0}'>"+
                                                "       <h1>{1}</h1>"+
                                                "       <h2>{2}</h2>" +
                                                "</div>";
        }
        
        private void initialiserContenuHtmlTpl() {
                contenuHTML =   "<div id='{10}'>"+
                                                "       <h2>Renseignements administratifs</h2>"+
                                                "       <span style='font-weight:bold;'>Condition d'accès :</span> {9}<br />"+
                                                "       <span style='font-weight:bold;'>Adresse :</span> {1}, {2} {3}, {4}, {5}<br />"+
                                                "       <span style='font-weight:bold;'>Téléphone :</span> {6}<br />"+
                                                "       <span style='font-weight:bold;'>Fax :</span> {7}<br />"+
                                                "       <span style='font-weight:bold;'>Courriel :</span> {8}<br />"+
                                                "       {0}"+
                                                "</div>";
        }
        
        public void rafraichir(Object nouvelleDonnees) {
                if (nouvelleDonnees instanceof Structure) {
                        afficherDetailInstitution((Structure) nouvelleDonnees);
                } else {
                        GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
                }
        }

}