Subversion Repositories eFlore/Applications.coel

Rev

Blame | Last modification | View Log | RSS feed

package org.tela_botanica.client.vues;

import org.tela_botanica.client.ComposantClass;
import org.tela_botanica.client.ComposantId;
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.ProjetListe;
import org.tela_botanica.client.modeles.Projet;

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

public class ProjetDetailVue extends DetailVue implements Rafraichissable {
        
        private String enteteTpl = null;
        private String contenuTpl = null;
                
        private ContentPanel panneauPrincipal = null;
        private Html entete = null;
        private Html contenu = null;
        
        private Projet projet = null;
        private boolean projetChargementOk = false;

        public ProjetDetailVue(Mediateur mediateurCourant) {
                super(mediateurCourant);
                
                initialiserTousLesTpl();
                
                panneauPrincipal = new ContentPanel();
                panneauPrincipal.setLayout(new FitLayout());
                panneauPrincipal.setHeaderVisible(false);
                panneauPrincipal.setBodyBorder(false);
                        
            entete = new Html();
            entete.setId(ComposantId.ZONE_DETAIL_ENTETE);
            panneauPrincipal.setTopComponent(entete);
            
            contenu = new Html();
            panneauPrincipal.add(contenu);
            
                add(panneauPrincipal);
        }

        private void initialiserTousLesTpl() {
                initialiserEnteteHtmlTpl();
                initialiserGeneralTpl();
        }
        
        private void initialiserEnteteHtmlTpl() {
                enteteTpl =     
                        "<div id='{css_id}'>"+
                        "       <h1>{titre}</h1>"+
                        "       <h2>{auteurs} ({annee})<span class='{css_meta}'>{projet} <br /> {i18n_id}:{id} - {guid}</span></h2>" +
                        "</div>";
        }
        
        private void initialiserGeneralTpl() {
                contenuTpl =
                        "<div class='{css_corps}'>"+
                        "       <div class='{css_fieldset}'>"+
                        "               <h2>{i18n_titre_detail}</h2>"+
                        "               <span class='{css_label}'>{i18n_auteurs} :</span> {auteurs}<br />"+
                        "               <span class='{css_label}'>{i18n_titre} :</span> {titre}<br />"+
                        "               <span class='{css_label}'>{i18n_collection} :</span> {collection}<br />"+
                        "               <span class='{css_label}'>{i18n_editeur} :</span> {editeur}<br />"+
                        "               <span class='{css_label}'>{i18n_annee} :</span> {annee}<br />"+
                        "               <span class='{css_label}'>{i18n_nvt} :</span> {nvt}<br />"+
                        "               <span class='{css_label}'>{i18n_fascicule} :</span> {fascicule}<br />"+
                        "               <span class='{css_label}'>{i18n_pages} :</span> {pages}<br />"+
                        "       </div>"+
                        "       <hr class='{css_clear}'/>"+
                        "</div>";
        }
        
        public void afficherDetail() {
                if (projet != null) {
                        afficherEntete();
                        afficherDetailProjet();
                }
                layout();
        }
        
        private void afficherEntete() {
                Params enteteParams = new Params();
                enteteParams.set("css_id", ComposantId.ZONE_DETAIL_ENTETE);
                enteteParams.set("css_meta", ComposantClass.META);
                
                enteteParams.set("i18n_id", i18nC.id());
                
                enteteParams.set("id", projet.getId());
                enteteParams.set("guid", getGuid());
                enteteParams.set("projet", construireTxtProjet(projet.getId()));
                GWT.log("entete généré", null);
                String eHtml = Format.substitute(enteteTpl, enteteParams);
                entete.getElement().setInnerHTML(eHtml);
        }
        
        public String getGuid() {
                String guid = "URN:tela-botanica.org:";
                guid += "coel"+projet.getId()+":";
                guid += "pro"+projet.getId();
                return guid;
        }
        
        public void afficherDetailProjet() {
                Params contenuParams = new Params();
                
                contenuParams.set("i18n_titre_detail", i18nC.id());
                
                String gHtml = formaterContenu(contenuTpl, contenuParams);
                contenu.getElement().setInnerHTML(gHtml);
        }
        
        public void rafraichir(Object nouvellesDonnees) {
                if (nouvellesDonnees instanceof Projet) {
                        projet = (Projet) nouvellesDonnees;
                        projetChargementOk = true;
                } else if (nouvellesDonnees instanceof ProjetListe) {
                        projets = (ProjetListe) nouvellesDonnees;
                        projetsChargementOk = true;
                        GWT.log("projets recu", null);
                } else {
                        GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
                }
                
                if (avoirDonneesChargees()) {
                        afficherDetail();
                }
        }
        
        private boolean avoirDonneesChargees() {
                boolean ok = false;
                if (projetsChargementOk && projetChargementOk) {
                        ok = true;
                }
                return ok;
        }
}