Subversion Repositories eFlore/Applications.coel

Rev

Rev 982 | 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.Mediateur;
import org.tela_botanica.client.i18n.Constantes;
import org.tela_botanica.client.modeles.Menu;
import org.tela_botanica.client.modeles.MenuApplicationId;

import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.GXT;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.TreePanelEvent;
import com.extjs.gxt.ui.client.store.TreeStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;

public class MenuVue extends ContentPanel {

        private Mediateur mediateur = null;
        private Constantes i18nC = null;
        
        private TreePanel<Menu> arbreMenus;
        private TreeStore<Menu> menuStore;
        
        public MenuVue(Mediateur mediateurCourrant) {
                mediateur = mediateurCourrant;
                i18nC = Mediateur.i18nC;
                
                setHeading(i18nC.titreMenu());
                setLayout(new FitLayout());
                setLayoutOnChange(true);
                
                construireMenu();
                afficherMenu();
        }

        private void construireMenu() {
                menuStore = new TreeStore<Menu>();
                
                Menu accueilMenu = new Menu(i18nC.menuAccueil(), MenuApplicationId.ACCUEIL);
                Menu projetMenu = new Menu(i18nC.menuProjet(), MenuApplicationId.PROJET);
            Menu menuInstitution = new Menu(i18nC.menuStructure(), MenuApplicationId.STRUCTURE);
            Menu menuCollections = new Menu(i18nC.menuCollection(), MenuApplicationId.COLLECTION);
            Menu menuPersonnes = new Menu(i18nC.menuPersonne(), MenuApplicationId.PERSONNE);
            Menu menuPublications = new Menu(i18nC.menuPublication(), MenuApplicationId.PUBLICATION);
            Menu menuCommentaires = new Menu(i18nC.menuCommentaire(), MenuApplicationId.COMMENTAIRE);
            
            menuStore.add(accueilMenu, false);
            menuStore.add(projetMenu, false);
            menuStore.add(menuInstitution, false);
            menuStore.add(menuCollections, false);
            menuStore.add(menuPersonnes, false);
            menuStore.add(menuPublications, false);
            menuStore.add(menuCommentaires, false);
        }
        
        private void afficherMenu() {
                arbreMenus = new TreePanel<Menu>(menuStore);
                arbreMenus.getStyle().setLeafIcon(GXT.IMAGES.tree_folder());
                arbreMenus.setDisplayProperty("nom");
                arbreMenus.setHeight("100%");
                arbreMenus.addListener(Events.OnClick, new Listener<TreePanelEvent<Menu>>(){
                        public void handleEvent(TreePanelEvent<Menu> tpe) {
                                Menu menuCourant = arbreMenus.getSelectionModel().getSelectedItem();
                                mediateur.clicMenu(menuCourant.getCode());
                        }
                });
                
                add(arbreMenus);
        }
        
        public void selectionMenu(String code) {
                arbreMenus.getSelectionModel().select(menuStore.findModel("code", code), false);
        }               
}