Subversion Repositories eFlore/Applications.coel

Rev

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

package org.tela_botanica.client.vues;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.Valeur;

import com.extjs.gxt.ui.client.Style.SortDir;
import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.InfoConfig;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.RowExpander;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.Dictionary;

public class FenetreJournal extends Dialog implements Rafraichissable{

        private int id = 0;
        private EditorGrid<Valeur> grille;
        //private int nbLogs = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbLogs"));
        private ListStore<Valeur> store;
        public FenetreJournal(Mediateur mediateur)      {
                
                this.setHeadingHtml(mediateur.i18nC.titreJournal());
                this.setWidth(500);
                this.setHeight(500);
                setLayout(new FitLayout());
                
                // Définition des colomnes de la grille:
                RowNumberer numeroPlugin = new RowNumberer();
                numeroPlugin.setHeaderHtml("#");
                
                XTemplate infoTpl = XTemplate.create("<p>"+
                        "<b>" + mediateur.i18nC.heureMessage() + " : </b>{heure}<br />" +
                        "<b>" + mediateur.i18nC.message() + " : </b>{description}<br />" +
                        "</p>");  
                RowExpander expansionPlugin = new RowExpander();  
                expansionPlugin.setTemplate(infoTpl);
                
                List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
                lstColumns.add(expansionPlugin);
                lstColumns.add(new ColumnConfig("nom", mediateur.i18nC.publicationTitre(), 200));
                lstColumns.add(new ColumnConfig("description", mediateur.i18nC.message() , 400));

                ColumnModel modeleColonnes = new ColumnModel(lstColumns);
                
                store = new ListStore<Valeur>();
                
                grille = new EditorGrid<Valeur>(store, modeleColonnes);
                grille.addPlugin(expansionPlugin);
                
                grille.setAutoExpandColumn("description");
                grille.getView().setAutoFill(true);
                grille.getView().setForceFit(true);
                
                store.sort("id", SortDir.DESC);
                add(grille);
        }
        
        public void rafraichir(Object nouvellesDonnees) {
                if (nouvellesDonnees instanceof InfoConfig)     {
                        InfoConfig info = (InfoConfig) nouvellesDonnees;
                        id++;
                        Valeur v = new Valeur(String.valueOf(id), info.titleHtml, null, info.html);
                        v.set("heure", getDate());
                        store.add(v);
                        
                        //if (store.getModels().size() > nbLogs)        {
                                //store.remove(store.getAt(nbLogs));
                        //}
                }
        }
        
        public String getDate() {
                Date date = new Date();
                return String.valueOf(DateTimeFormat.getFormat("HH:mm:ss").format(date));
        }
        
        
        protected void createButtons() {
                //Pas de boutons, merci
        }

}