Subversion Repositories eFlore/Applications.coel

Rev

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

package org.tela_botanica.client.vues.accueil;

import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.configuration.Configuration;
import org.tela_botanica.client.modeles.InterneValeur;
import org.tela_botanica.client.util.Debug;
import org.tela_botanica.client.vues.Formulaire;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.IconButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.event.WindowEvent;
import com.extjs.gxt.ui.client.event.WindowListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.HtmlContainer;
import com.extjs.gxt.ui.client.widget.button.ToolButton;
import com.extjs.gxt.ui.client.widget.custom.Portlet;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;

public class AppletteStatistique extends Portlet {
        
        private String baseUrl = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
        
        public AppletteStatistique() {
                initialiserAppletteStatistique(null);
        }
        
        public AppletteStatistique(String contenu) {
                initialiserAppletteStatistique(contenu);
        }
        
        private void initialiserAppletteStatistique(String contenu) {
                setLayout(new FitLayout());
                setHeading("Statistiques des collections");
                setHeight(250);
                setCollapsible(true);
                setAnimCollapse(true);
                setScrollMode(Scroll.AUTO);
                
                attribuerContenu(contenu);
                
                getHeader().addTool(new ToolButton("x-tool-gear", new SelectionListener<IconButtonEvent>() {
                        @Override
                        public void componentSelected(IconButtonEvent ce) {
                                ContentPanel panneau = new ContentPanel();
                                panneau.setHeaderVisible(false);
                                panneau.setLayout(Formulaire.creerFormLayout(350, LabelAlign.TOP));
                                
                                ListStore<InterneValeur> appletteStore = new ListStore<InterneValeur>();
                                appletteStore.add(new InterneValeur("NombreDonnees", "Nombre de données"));
                                appletteStore.add(new InterneValeur("TypeDepot", "Types de dépôt des collections"));
                                appletteStore.add(new InterneValeur("NombreCollectionParStructure", "Nombre de collections par institution"));
                                
                                final ComboBox<InterneValeur> applettesCombo = new ComboBox<InterneValeur>();
                                applettesCombo.setFieldLabel("Veuillez sélectionner le type d'applette");
                                applettesCombo.setForceSelection(true);
                                applettesCombo.setTriggerAction(TriggerAction.ALL);
                                applettesCombo.setDisplayField("nom");
                                applettesCombo.setStore(appletteStore);
                                applettesCombo.setEditable(false);
                                applettesCombo.setWidth(300);
                                
                                panneau.add(applettesCombo);
                                
                                final Dialog configurationFenetre = new Dialog();  
                                configurationFenetre.setHeading("Configuration de l'applette");
                                configurationFenetre.setButtons(Dialog.OK);
                                configurationFenetre.setSize(350, 150);  
                                configurationFenetre.setPlain(true);  
                                configurationFenetre.setModal(true);
                                configurationFenetre.setBlinkModal(true);  
                                configurationFenetre.setLayout(new FitLayout());
                                configurationFenetre.setHideOnButtonClick(true);
                                configurationFenetre.addWindowListener(new WindowListener(){
                                        public void windowHide(WindowEvent we) {
                                                String abreviation = applettesCombo.getValue().getAbr();
                                                attribuerContenu(abreviation);
                                        }
                                });
                                configurationFenetre.add(panneau);
                                configurationFenetre.show();
                        }
                }));
                
                getHeader().addTool(new ToolButton("x-tool-pin", new SelectionListener<IconButtonEvent>() {
                        @Override
                        public void componentSelected(IconButtonEvent ce) {
                                if (isPinned()) {
                                        ce.getComponent().setStylePrimaryName("x-tool-pin");
                                        setPinned(false);
                                } else {
                                        ce.getComponent().setStylePrimaryName("x-tool-unpin");
                                        setPinned(true);
                                }
                                layout();
                        }
                }));
                
                getHeader().addTool(new ToolButton("x-tool-close", new SelectionListener<IconButtonEvent>() {
                        @Override
                        public void componentSelected(IconButtonEvent ce) {
                                removeFromParent();
                        }
                }));
        }
        
        
        private void attribuerContenu(String abreviation) {
                if (abreviation == null) {
                        abreviation = "NombreDonnees";
                }
                
                setData("contenu", abreviation);
                String url = baseUrl+"CoelStatistique/"+abreviation;
                
                HtmlContainer conteneurHtml = new HtmlContainer();
                conteneurHtml.setUrl(url);
                conteneurHtml.recalculate();
                
                removeAll();
                add(conteneurHtml);
                layout();
        }
}