Rev 791 | Rev 928 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;import java.util.Iterator;import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.RegistreId;import org.tela_botanica.client.i18n.Constantes;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.Menu;import org.tela_botanica.client.modeles.MenuApplicationId;import org.tela_botanica.client.modeles.Projet;import org.tela_botanica.client.modeles.ProjetListe;import com.extjs.gxt.ui.client.event.Events;import com.extjs.gxt.ui.client.GXT;import com.extjs.gxt.ui.client.Registry;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.FlowLayout;import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;import com.google.gwt.core.client.GWT;import com.google.gwt.event.dom.client.ChangeEvent;import com.google.gwt.event.dom.client.ChangeHandler;import com.google.gwt.user.client.ui.ListBox;public class MenuVue extends ContentPanel implements Rafraichissable {private Mediateur mediateur = null;private Constantes i18nC = null;private TreePanel<Menu> arbreMenus;private ListBox listeProjets;private ProjetListe projetsCache = null;private TreeStore<Menu> menuStore;public MenuVue(Mediateur mediateurCourrant) {mediateur = mediateurCourrant;i18nC = mediateur.i18nC;setHeading(i18nC.titreMenu());setLayout(new FlowLayout());setLayoutOnChange(true);chargerProjets();afficherListeProjets();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);menuStore.add(accueilMenu, false);menuStore.add(projetMenu, false);menuStore.add(menuInstitution, false);menuStore.add(menuCollections, false);menuStore.add(menuPersonnes, false);menuStore.add(menuPublications, 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);}private void chargerProjets() {mediateur.selectionnerProjets(this);}private void ajouterProjetsAListe() {Iterator<Projet> it = projetsCache.values().iterator();while (it.hasNext()) {Projet projetCourant = it.next();listeProjets.addItem(projetCourant.getNom(), projetCourant.getId());}}private void afficherListeProjets() {// Ajout de la sélection des projetslisteProjets = new ListBox(false);listeProjets.setWidth("100%");listeProjets.addItem(i18nC.txtListeProjetDefaut(), "NULL");add(listeProjets);// Ajout d'un écouteur pour le changement => enregistre la valeur courante du projet dans le registrelisteProjets.addChangeHandler(new ChangeHandler() {@Overridepublic void onChange(ChangeEvent event) {mediateur.activerChargement(i18nC.chargement());mediateur.selectionnerProjetCourant(projetsCache.get(listeProjets.getValue(listeProjets.getSelectedIndex())));}});}public void rafraichir(Object nouvellesDonnees) {if (nouvellesDonnees instanceof ProjetListe) {projetsCache = (ProjetListe) nouvellesDonnees;Registry.register(RegistreId.PROJETS, projetsCache);ajouterProjetsAListe();} else {GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);}}}