1 |
package org.tela_botanica.client.vues;
|
1 |
package org.tela_botanica.client.vues;
|
2 |
|
2 |
|
3 |
import java.util.Iterator;
|
3 |
import java.util.Iterator;
|
4 |
|
4 |
|
5 |
import org.tela_botanica.client.Mediateur;
|
5 |
import org.tela_botanica.client.Mediateur;
|
6 |
import org.tela_botanica.client.i18n.Constantes;
|
6 |
import org.tela_botanica.client.i18n.Constantes;
|
7 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
7 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
8 |
import org.tela_botanica.client.modeles.Menu;
|
8 |
import org.tela_botanica.client.modeles.Menu;
|
9 |
import org.tela_botanica.client.modeles.MenuApplicationId;
|
9 |
import org.tela_botanica.client.modeles.MenuApplicationId;
|
10 |
import org.tela_botanica.client.modeles.Projet;
|
10 |
import org.tela_botanica.client.modeles.Projet;
|
11 |
import org.tela_botanica.client.modeles.ProjetListe;
|
11 |
import org.tela_botanica.client.modeles.ProjetListe;
|
12 |
|
12 |
|
13 |
import com.extjs.gxt.ui.client.event.Events;
|
13 |
import com.extjs.gxt.ui.client.event.Events;
|
14 |
import com.extjs.gxt.ui.client.GXT;
|
14 |
import com.extjs.gxt.ui.client.GXT;
|
15 |
import com.extjs.gxt.ui.client.event.Listener;
|
15 |
import com.extjs.gxt.ui.client.event.Listener;
|
16 |
import com.extjs.gxt.ui.client.event.TreePanelEvent;
|
16 |
import com.extjs.gxt.ui.client.event.TreePanelEvent;
|
17 |
import com.extjs.gxt.ui.client.store.TreeStore;
|
17 |
import com.extjs.gxt.ui.client.store.TreeStore;
|
18 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
18 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
19 |
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
|
19 |
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
|
20 |
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
|
20 |
import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
|
21 |
import com.google.gwt.core.client.GWT;
|
21 |
import com.google.gwt.core.client.GWT;
|
22 |
import com.google.gwt.event.dom.client.ChangeEvent;
|
22 |
import com.google.gwt.event.dom.client.ChangeEvent;
|
23 |
import com.google.gwt.event.dom.client.ChangeHandler;
|
23 |
import com.google.gwt.event.dom.client.ChangeHandler;
|
24 |
import com.google.gwt.user.client.ui.ListBox;
|
24 |
import com.google.gwt.user.client.ui.ListBox;
|
25 |
|
25 |
|
26 |
public class MenuVue extends ContentPanel implements Rafraichissable {
|
26 |
public class MenuVue extends ContentPanel implements Rafraichissable {
|
27 |
|
27 |
|
28 |
private Mediateur mediateur = null;
|
28 |
private Mediateur mediateur = null;
|
29 |
private Constantes i18nC = null;
|
29 |
private Constantes i18nC = null;
|
30 |
|
30 |
|
31 |
private TreePanel<Menu> arbreMenus;
|
31 |
private TreePanel<Menu> arbreMenus;
|
32 |
private ListBox listeProjets;
|
32 |
private ListBox listeProjets;
|
33 |
private ProjetListe projetsCache = null;
|
33 |
private ProjetListe projetsCache = null;
|
34 |
private TreeStore<Menu> menuStore;
|
34 |
private TreeStore<Menu> menuStore;
|
35 |
|
35 |
|
36 |
public MenuVue(Mediateur mediateurCourrant) {
|
36 |
public MenuVue(Mediateur mediateurCourrant) {
|
37 |
mediateur = mediateurCourrant;
|
37 |
mediateur = mediateurCourrant;
|
38 |
i18nC = mediateur.i18nC;
|
38 |
i18nC = mediateur.i18nC;
|
39 |
|
39 |
|
40 |
setHeading(i18nC.titreMenu());
|
40 |
setHeading(i18nC.titreMenu());
|
41 |
setLayout(new FlowLayout());
|
41 |
setLayout(new FlowLayout());
|
42 |
setLayoutOnChange(true);
|
42 |
setLayoutOnChange(true);
|
43 |
|
43 |
|
44 |
chargerProjets();
|
44 |
chargerProjets();
|
45 |
afficherListeProjets();
|
45 |
afficherListeProjets();
|
46 |
|
46 |
|
47 |
construireMenu();
|
47 |
construireMenu();
|
48 |
afficherMenu();
|
48 |
afficherMenu();
|
49 |
}
|
49 |
}
|
50 |
|
50 |
|
51 |
private void construireMenu() {
|
51 |
private void construireMenu() {
|
52 |
menuStore = new TreeStore<Menu>();
|
52 |
menuStore = new TreeStore<Menu>();
|
53 |
|
53 |
|
54 |
Menu accueilMenu = new Menu(i18nC.menuAccueil(), MenuApplicationId.ACCUEIL);
|
54 |
Menu accueilMenu = new Menu(i18nC.menuAccueil(), MenuApplicationId.ACCUEIL);
|
55 |
Menu projetMenu = new Menu(i18nC.menuProjet(), MenuApplicationId.PROJET);
|
55 |
Menu projetMenu = new Menu(i18nC.menuProjet(), MenuApplicationId.PROJET);
|
56 |
Menu menuInstitution = new Menu(i18nC.menuStructure(), MenuApplicationId.STRUCTURE);
|
56 |
Menu menuInstitution = new Menu(i18nC.menuStructure(), MenuApplicationId.STRUCTURE);
|
57 |
Menu menuCollections = new Menu(i18nC.menuCollection(), MenuApplicationId.COLLECTION);
|
57 |
Menu menuCollections = new Menu(i18nC.menuCollection(), MenuApplicationId.COLLECTION);
|
58 |
Menu menuPersonnes = new Menu(i18nC.menuPersonne(), MenuApplicationId.PERSONNE);
|
58 |
Menu menuPersonnes = new Menu(i18nC.menuPersonne(), MenuApplicationId.PERSONNE);
|
59 |
Menu menuPublications = new Menu(i18nC.menuPublication(), MenuApplicationId.PUBLICATION);
|
59 |
Menu menuPublications = new Menu(i18nC.menuPublication(), MenuApplicationId.PUBLICATION);
|
60 |
|
60 |
|
61 |
menuStore.add(accueilMenu, false);
|
61 |
menuStore.add(accueilMenu, false);
|
62 |
menuStore.add(projetMenu, false);
|
62 |
menuStore.add(projetMenu, false);
|
63 |
menuStore.add(menuInstitution, false);
|
63 |
menuStore.add(menuInstitution, false);
|
64 |
menuStore.add(menuCollections, false);
|
64 |
menuStore.add(menuCollections, false);
|
65 |
menuStore.add(menuPersonnes, false);
|
65 |
menuStore.add(menuPersonnes, false);
|
66 |
menuStore.add(menuPublications, false);
|
66 |
menuStore.add(menuPublications, false);
|
67 |
}
|
67 |
}
|
68 |
|
68 |
|
69 |
private void afficherMenu() {
|
69 |
private void afficherMenu() {
|
70 |
arbreMenus = new TreePanel<Menu>(menuStore);
|
70 |
arbreMenus = new TreePanel<Menu>(menuStore);
|
71 |
arbreMenus.getStyle().setLeafIcon(GXT.IMAGES.tree_folder());
|
71 |
arbreMenus.getStyle().setLeafIcon(GXT.IMAGES.tree_folder());
|
72 |
arbreMenus.setDisplayProperty("nom");
|
72 |
arbreMenus.setDisplayProperty("nom");
|
73 |
arbreMenus.setHeight("100%");
|
73 |
arbreMenus.setHeight("100%");
|
74 |
arbreMenus.addListener(Events.OnClick, new Listener<TreePanelEvent<Menu>>(){
|
74 |
arbreMenus.addListener(Events.OnClick, new Listener<TreePanelEvent<Menu>>(){
|
75 |
public void handleEvent(TreePanelEvent<Menu> tpe) {
|
75 |
public void handleEvent(TreePanelEvent<Menu> tpe) {
|
76 |
Menu menuCourant = arbreMenus.getSelectionModel().getSelectedItem();
|
76 |
Menu menuCourant = arbreMenus.getSelectionModel().getSelectedItem();
|
77 |
selectionMenu(menuCourant);
|
77 |
mediateur.clicMenu(menuCourant.getCode());
|
78 |
}
|
78 |
}
|
79 |
});
|
79 |
});
|
80 |
|
80 |
|
81 |
add(arbreMenus);
|
81 |
add(arbreMenus);
|
82 |
}
|
82 |
}
|
83 |
|
83 |
|
84 |
private void selectionMenu(Menu menuSelectionne) {
|
84 |
public void selectionMenu(String code) {
|
85 |
String codeMenuSelectionne = menuSelectionne.getCode();
|
- |
|
86 |
mediateur.clicMenu(codeMenuSelectionne);
|
85 |
arbreMenus.getSelectionModel().select(menuStore.findModel("code", code), false);
|
87 |
}
|
86 |
}
|
88 |
|
87 |
|
89 |
private void chargerProjets() {
|
88 |
private void chargerProjets() {
|
90 |
mediateur.selectionnerProjets(this);
|
89 |
mediateur.selectionnerProjets(this);
|
91 |
}
|
90 |
}
|
92 |
|
91 |
|
93 |
private void ajouterProjetsAListe() {
|
92 |
private void ajouterProjetsAListe() {
|
94 |
Iterator<Projet> it = projetsCache.values().iterator();
|
93 |
Iterator<Projet> it = projetsCache.values().iterator();
|
95 |
while (it.hasNext()) {
|
94 |
while (it.hasNext()) {
|
96 |
Projet projetCourant = it.next();
|
95 |
Projet projetCourant = it.next();
|
97 |
listeProjets.addItem(projetCourant.getNom(), projetCourant.getId());
|
96 |
listeProjets.addItem(projetCourant.getNom(), projetCourant.getId());
|
98 |
}
|
97 |
}
|
99 |
}
|
98 |
}
|
100 |
|
99 |
|
101 |
private void afficherListeProjets() {
|
100 |
private void afficherListeProjets() {
|
102 |
// Ajout de la sélection des projets
|
101 |
// Ajout de la sélection des projets
|
103 |
listeProjets = new ListBox(false);
|
102 |
listeProjets = new ListBox(false);
|
104 |
listeProjets.setWidth("100%");
|
103 |
listeProjets.setWidth("100%");
|
105 |
listeProjets.addItem(i18nC.txtListeProjetDefaut(), "NULL");
|
104 |
listeProjets.addItem(i18nC.txtListeProjetDefaut(), "NULL");
|
106 |
add(listeProjets);
|
105 |
add(listeProjets);
|
107 |
|
106 |
|
108 |
// Ajout d'un écouteur pour le changement => enregistre la valeur courante du projet dans le registre
|
107 |
// Ajout d'un écouteur pour le changement => enregistre la valeur courante du projet dans le registre
|
109 |
listeProjets.addChangeHandler(new ChangeHandler() {
|
108 |
listeProjets.addChangeHandler(new ChangeHandler() {
|
110 |
@Override
|
109 |
@Override
|
111 |
public void onChange(ChangeEvent event) {
|
110 |
public void onChange(ChangeEvent event) {
|
112 |
mediateur.activerChargement(i18nC.chargement());
|
111 |
mediateur.activerChargement(i18nC.chargement());
|
113 |
mediateur.selectionnerProjetCourant(projetsCache.get(listeProjets.getValue(listeProjets.getSelectedIndex())));
|
112 |
mediateur.selectionnerProjetCourant(projetsCache.get(listeProjets.getValue(listeProjets.getSelectedIndex())));
|
114 |
}
|
113 |
}
|
115 |
});
|
114 |
});
|
116 |
}
|
115 |
}
|
117 |
|
116 |
|
118 |
public void rafraichir(Object nouvellesDonnees) {
|
117 |
public void rafraichir(Object nouvellesDonnees) {
|
119 |
if (nouvellesDonnees instanceof ProjetListe) {
|
118 |
if (nouvellesDonnees instanceof ProjetListe) {
|
120 |
projetsCache = (ProjetListe) nouvellesDonnees;
|
119 |
projetsCache = (ProjetListe) nouvellesDonnees;
|
121 |
ajouterProjetsAListe();
|
120 |
ajouterProjetsAListe();
|
122 |
} else {
|
121 |
} else {
|
123 |
GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
122 |
GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
124 |
}
|
123 |
}
|
125 |
}
|
124 |
}
|
126 |
}
|
125 |
}
|