127 |
gduche |
1 |
package org.tela_botanica.client.vues;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import org.tela_botanica.client.Mediateur;
|
|
|
7 |
import org.tela_botanica.client.RegistreId;
|
512 |
gduche |
8 |
import org.tela_botanica.client.images.Images;
|
596 |
gduche |
9 |
import org.tela_botanica.client.interfaces.ListePaginable;
|
127 |
gduche |
10 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
353 |
gduche |
11 |
import org.tela_botanica.client.modeles.Information;
|
127 |
gduche |
12 |
import org.tela_botanica.client.modeles.Personne;
|
|
|
13 |
import org.tela_botanica.client.modeles.PersonneListe;
|
617 |
gduche |
14 |
import org.tela_botanica.client.modeles.Utilisateur;
|
|
|
15 |
|
127 |
gduche |
16 |
import com.extjs.gxt.ui.client.Registry;
|
377 |
gduche |
17 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
562 |
gduche |
18 |
import com.extjs.gxt.ui.client.data.BasePagingLoader;
|
|
|
19 |
import com.extjs.gxt.ui.client.data.ModelData;
|
|
|
20 |
import com.extjs.gxt.ui.client.data.PagingLoadResult;
|
|
|
21 |
import com.extjs.gxt.ui.client.data.PagingLoader;
|
|
|
22 |
import com.extjs.gxt.ui.client.data.PagingModelMemoryProxy;
|
566 |
jp_milcent |
23 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
489 |
gduche |
24 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
566 |
jp_milcent |
25 |
import com.extjs.gxt.ui.client.event.Events;
|
|
|
26 |
import com.extjs.gxt.ui.client.event.Listener;
|
127 |
gduche |
27 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
28 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|
|
29 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
30 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
31 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
353 |
gduche |
32 |
import com.extjs.gxt.ui.client.widget.Info;
|
489 |
gduche |
33 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
512 |
gduche |
34 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
|
35 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
36 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
|
37 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
127 |
gduche |
38 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
562 |
gduche |
39 |
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
|
127 |
gduche |
40 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
278 |
jp_milcent |
41 |
import com.google.gwt.core.client.GWT;
|
562 |
gduche |
42 |
import com.google.gwt.i18n.client.Dictionary;
|
127 |
gduche |
43 |
|
436 |
gduche |
44 |
public class PersonneListeVue extends ContentPanel implements Rafraichissable {
|
127 |
gduche |
45 |
|
278 |
jp_milcent |
46 |
private Mediateur mediateur = null ;
|
512 |
gduche |
47 |
|
|
|
48 |
private Grid<Personne> grille = null;
|
287 |
gduche |
49 |
private Personne personneSelectionnee = null;
|
596 |
gduche |
50 |
private BarrePaginationVue pagination;
|
563 |
gduche |
51 |
private ColumnModel modeleColonnes;
|
562 |
gduche |
52 |
private final int nbElementsPage = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbElementsPage"));
|
617 |
gduche |
53 |
private final Button supprimer;
|
258 |
gduche |
54 |
|
436 |
gduche |
55 |
public PersonneListeVue() {
|
278 |
jp_milcent |
56 |
mediateur = Registry.get(RegistreId.MEDIATEUR);
|
127 |
gduche |
57 |
|
566 |
jp_milcent |
58 |
setHeading(mediateur.i18nC.personneListeLabel());
|
|
|
59 |
setLayout(new FitLayout());
|
562 |
gduche |
60 |
|
127 |
gduche |
61 |
//Définition de la barre d'outil
|
|
|
62 |
ToolBar toolBar = new ToolBar();
|
489 |
gduche |
63 |
Button ajouter = new Button(mediateur.i18nC.ajouter());
|
512 |
gduche |
64 |
ajouter.setIcon(Images.ICONES.ajouter());
|
489 |
gduche |
65 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
66 |
public void componentSelected(ButtonEvent ce) {
|
278 |
jp_milcent |
67 |
mediateur.clicAjouterPersonne();
|
127 |
gduche |
68 |
}
|
|
|
69 |
});
|
|
|
70 |
toolBar.add(ajouter);
|
217 |
aurelien |
71 |
final Rafraichissable r = this ;
|
127 |
gduche |
72 |
|
489 |
gduche |
73 |
final Button modifier = new Button(mediateur.i18nC.modifier());
|
512 |
gduche |
74 |
modifier.setIcon(Images.ICONES.formModifier());
|
489 |
gduche |
75 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
76 |
public void componentSelected(ButtonEvent ce) {
|
661 |
gduche |
77 |
|
662 |
gduche |
78 |
//A déplacer dans médiateur
|
661 |
gduche |
79 |
int tailleSelection = grille.getSelectionModel().getSelectedItems().size();
|
|
|
80 |
if ( tailleSelection == 0) {
|
|
|
81 |
Info.display("Information", "Veuillez sélectionner une personne.");
|
|
|
82 |
} else if (tailleSelection > 1) {
|
|
|
83 |
Info.display("Information", "Veuillez sélectionner une seule personne à la fois.");
|
|
|
84 |
} else {
|
|
|
85 |
mediateur.clicModifierPersonne(personneSelectionnee);
|
|
|
86 |
}
|
217 |
aurelien |
87 |
}
|
|
|
88 |
});
|
127 |
gduche |
89 |
toolBar.add(modifier);
|
|
|
90 |
|
617 |
gduche |
91 |
supprimer = new Button(mediateur.i18nC.supprimer());
|
489 |
gduche |
92 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
93 |
public void componentSelected(ButtonEvent ce) {
|
512 |
gduche |
94 |
mediateur.clicSupprimerPersonne(r, grille.getSelectionModel().getSelectedItems());
|
217 |
aurelien |
95 |
}
|
|
|
96 |
});
|
512 |
gduche |
97 |
supprimer.setIcon(Images.ICONES.supprimer());
|
127 |
gduche |
98 |
toolBar.add(supprimer);
|
617 |
gduche |
99 |
|
|
|
100 |
gererEtatActivationBouton();
|
566 |
jp_milcent |
101 |
|
127 |
gduche |
102 |
setTopComponent(toolBar);
|
566 |
jp_milcent |
103 |
|
|
|
104 |
// Définition des colomnes de la grille:
|
512 |
gduche |
105 |
List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
|
566 |
jp_milcent |
106 |
ColumnConfig ccId = new ColumnConfig("id_personne", "Id", 45);
|
541 |
gduche |
107 |
lstColumns.add(ccId);
|
566 |
jp_milcent |
108 |
ColumnConfig ccFmtNomComplet = new ColumnConfig("fmt_nom_complet", "Nom Complet", 200);
|
512 |
gduche |
109 |
lstColumns.add(ccFmtNomComplet);
|
566 |
jp_milcent |
110 |
ColumnConfig ccCodePostal = new ColumnConfig("code_postal", "Code postal", 100);
|
512 |
gduche |
111 |
lstColumns.add(ccCodePostal);
|
566 |
jp_milcent |
112 |
ColumnConfig ccVille = new ColumnConfig("ville", "Ville", 100);
|
512 |
gduche |
113 |
lstColumns.add(ccVille);
|
566 |
jp_milcent |
114 |
ColumnConfig ccCourriel = new ColumnConfig("courriel_princ", "Courriel", 200);
|
512 |
gduche |
115 |
lstColumns.add(ccCourriel);
|
566 |
jp_milcent |
116 |
ColumnConfig ccNom = new ColumnConfig("nom", "Nom", 100);
|
512 |
gduche |
117 |
ccNom.setHidden(true);
|
|
|
118 |
lstColumns.add(ccNom);
|
566 |
jp_milcent |
119 |
ColumnConfig ccPrenom = new ColumnConfig("prenom", "Prénom", 100);
|
512 |
gduche |
120 |
ccPrenom.setHidden(true);
|
|
|
121 |
lstColumns.add(ccPrenom);
|
563 |
gduche |
122 |
modeleColonnes = new ColumnModel(lstColumns);
|
566 |
jp_milcent |
123 |
|
|
|
124 |
// Définition de la grille
|
512 |
gduche |
125 |
GridSelectionModel<Personne> gsmSelectionGrille = new GridSelectionModel<Personne>();
|
|
|
126 |
gsmSelectionGrille.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
|
520 |
gduche |
127 |
public void selectionChanged(SelectionChangedEvent<Personne> event) {
|
|
|
128 |
Personne p = (Personne) event.getSelectedItem();
|
|
|
129 |
personneSelectionnee = p;
|
|
|
130 |
clicListe(p);
|
|
|
131 |
}
|
150 |
gduche |
132 |
});
|
287 |
gduche |
133 |
|
566 |
jp_milcent |
134 |
grille = new Grid<Personne>( new ListStore<Personne>(), modeleColonnes);
|
512 |
gduche |
135 |
grille.setSelectionModel(gsmSelectionGrille);
|
566 |
jp_milcent |
136 |
grille.setWidth("100%");
|
512 |
gduche |
137 |
grille.setAutoExpandColumn("fmt_nom_complet");
|
566 |
jp_milcent |
138 |
grille.getView().setAutoFill(true);
|
|
|
139 |
grille.getView().setForceFit(true);
|
|
|
140 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
|
|
141 |
@Override
|
|
|
142 |
public void handleEvent(BaseEvent be) {
|
624 |
gduche |
143 |
grille.getStore().sort("fmt_nom_complet", SortDir.ASC);
|
566 |
jp_milcent |
144 |
grille.getSelectionModel().select(0, false);
|
|
|
145 |
}
|
|
|
146 |
});
|
562 |
gduche |
147 |
add(grille);
|
512 |
gduche |
148 |
|
566 |
jp_milcent |
149 |
// Définition de la barre de pagination
|
596 |
gduche |
150 |
pagination = new BarrePaginationVue(new PersonneListe(), mediateur);
|
562 |
gduche |
151 |
setBottomComponent(pagination);
|
127 |
gduche |
152 |
}
|
|
|
153 |
|
150 |
gduche |
154 |
private void clicListe(Personne personne) {
|
278 |
jp_milcent |
155 |
mediateur.clicListePersonne(personne);
|
127 |
gduche |
156 |
}
|
|
|
157 |
|
617 |
gduche |
158 |
private void gererEtatActivationBouton() {
|
|
|
159 |
|
|
|
160 |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false) {
|
|
|
161 |
supprimer.setEnabled(false);
|
|
|
162 |
} else {
|
|
|
163 |
|
|
|
164 |
supprimer.setEnabled(true);
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
353 |
gduche |
169 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
170 |
if (nouvellesDonnees instanceof PersonneListe) {
|
596 |
gduche |
171 |
|
353 |
gduche |
172 |
PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
|
127 |
gduche |
173 |
|
596 |
gduche |
174 |
pagination.setlistePaginable(listePersonnes);
|
|
|
175 |
pagination.rafraichir(listePersonnes.getPageTable());
|
|
|
176 |
|
567 |
jp_milcent |
177 |
if (listePersonnes != null) {
|
|
|
178 |
List<Personne> liste = (List<Personne>) listePersonnes.toList();
|
|
|
179 |
|
596 |
gduche |
180 |
ListStore<Personne> store = new ListStore<Personne>();
|
|
|
181 |
store.add(liste);
|
567 |
jp_milcent |
182 |
grille.reconfigure(store, modeleColonnes);
|
|
|
183 |
|
|
|
184 |
mediateur.actualiserPanneauCentral();
|
649 |
gduche |
185 |
grille.fireEvent(Events.ViewReady);
|
596 |
gduche |
186 |
|
567 |
jp_milcent |
187 |
}
|
417 |
gduche |
188 |
} else if (nouvellesDonnees instanceof Information) {
|
617 |
gduche |
189 |
|
417 |
gduche |
190 |
Information info = (Information) nouvellesDonnees;
|
|
|
191 |
if (info.getType().equals("suppression_personne")) {
|
512 |
gduche |
192 |
Info.display("Suppression de personne", info.getMessages().toString());
|
658 |
gduche |
193 |
//Rechargement de la liste
|
|
|
194 |
pagination.getlistePaginable().recharger();
|
|
|
195 |
|
617 |
gduche |
196 |
} else if (info.getType().equals("maj_utilisateur")) {
|
|
|
197 |
gererEtatActivationBouton();
|
|
|
198 |
} else {
|
512 |
gduche |
199 |
Info.display("Erreur", info.getMessages().toString());
|
361 |
jp_milcent |
200 |
}
|
|
|
201 |
} else {
|
533 |
jp_milcent |
202 |
GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
127 |
gduche |
203 |
}
|
596 |
gduche |
204 |
|
|
|
205 |
|
|
|
206 |
|
278 |
jp_milcent |
207 |
layout();
|
127 |
gduche |
208 |
}
|
|
|
209 |
}
|
189 |
gduche |
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|