Subversion Repositories eFlore/Applications.coel

Rev

Rev 106 | Rev 380 | 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.RegistreId;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Publication;
import org.tela_botanica.client.modeles.PublicationListe;

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

public class PublicationDetailPanneauVue extends ContentPanel implements Rafraichissable {
                
        private ContentPanel content;
        private Html header;
        private String enteteHTML = "<div class='coel-detail'><h1>{0}</h1><h2>{1}</h2><h2>{2}</h2></div>";
        private String contenuHTML = "<div style='padding: 12px;'><h2>Détails de la publication</h2><span style='font-weight:bold;'>Nom de la revue :</span> {0}<br /><span style='font-weight:bold;'>Editeur :</span> {1}<br /><span style='font-weight:bold;'>Année :</span> {2}<br /><span style='font-weight:bold;'>Tome :</span> {3}<br /><span style='font-weight:bold;'>Fascicule :</span> {4}<br /><span style='font-weight:bold;'>Pages :</span> {5}</div>";
        private String publicationNom = null;
        private String publicationAuteur = null;
        private String publicationDateParution = null;

        public PublicationDetailPanneauVue() {
                Registry.register(RegistreId.PANNEAU_PUBLICATION_DETAIL, this);
                
                setHeaderVisible(false);
                setLayout(new FitLayout());

                content = new ContentPanel();
                content.setBodyBorder(false);
                content.setHeaderVisible(false);
                content.setScrollMode(Scroll.AUTO);

                header = new Html();
                header.setStyleName("coel-detail");
                content.setTopComponent(header);

                add(content);
        }

        public void afficherDetailPublication(Publication publication) {
                if (publication != null) {
                        content.removeAll();
                        
                        publicationNom = publication.getTitre();
                        publicationAuteur = publication.getAuteur().replaceAll("\\|", ", ");;
                        publicationDateParution = publication.getDateParution();

                        Params enteteParams = new Params();
                        enteteParams.add(publicationNom);
                        enteteParams.add(publicationAuteur);
                        enteteParams.add(publicationDateParution);

                        String eHtml = Format.substitute(enteteHTML, enteteParams);
                        header.getElement().setInnerHTML(eHtml);

                        Params contenuParams = new Params();
                        contenuParams.add(publication.getCollection());
                        contenuParams.add(publication.getEditeur());
                        contenuParams.add(publication.getDateParution());
                        contenuParams.add(publication.getIndicationNvt());
                        contenuParams.add(publication.getFascicule());
                        contenuParams.add(publication.getPages());
                        
                        String cHtml = Format.substitute(contenuHTML, contenuParams);
                        content.addText(cHtml);

                        layout();
                } else {
                        header.setHtml("");
                        content.removeAll();
                }
        }

        public void rafraichir(Object nouvelleDonnees) {
                if (nouvelleDonnees instanceof Publication) {
                        afficherDetailPublication((Publication) nouvelleDonnees);
                } else if (nouvelleDonnees instanceof PublicationListe) {
                        PublicationListe listePublication = (PublicationListe) nouvelleDonnees;
                        // Test pour savoir si la liste contient des éléments
                        if (listePublication.size() == 0) {
                                afficherDetailPublication(null);
                        }
                }
        }

}