935 |
jpm |
1 |
package org.tela_botanica.client.vues.personne;
|
127 |
gduche |
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
670 |
gduche |
6 |
|
127 |
gduche |
7 |
import org.tela_botanica.client.Mediateur;
|
|
|
8 |
import org.tela_botanica.client.RegistreId;
|
1239 |
cyprien |
9 |
import org.tela_botanica.client.composants.InfoLogger;
|
512 |
gduche |
10 |
import org.tela_botanica.client.images.Images;
|
127 |
gduche |
11 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
353 |
gduche |
12 |
import org.tela_botanica.client.modeles.Information;
|
617 |
gduche |
13 |
import org.tela_botanica.client.modeles.Utilisateur;
|
935 |
jpm |
14 |
import org.tela_botanica.client.modeles.personne.Personne;
|
|
|
15 |
import org.tela_botanica.client.modeles.personne.PersonneListe;
|
1613 |
aurelien |
16 |
import org.tela_botanica.client.modeles.projet.Projet;
|
1367 |
cyprien |
17 |
import org.tela_botanica.client.util.Debug;
|
935 |
jpm |
18 |
import org.tela_botanica.client.vues.BarrePaginationVue;
|
617 |
gduche |
19 |
|
127 |
gduche |
20 |
import com.extjs.gxt.ui.client.Registry;
|
377 |
gduche |
21 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
566 |
jp_milcent |
22 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
489 |
gduche |
23 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
566 |
jp_milcent |
24 |
import com.extjs.gxt.ui.client.event.Events;
|
|
|
25 |
import com.extjs.gxt.ui.client.event.Listener;
|
127 |
gduche |
26 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
27 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|
|
28 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
29 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
30 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
353 |
gduche |
31 |
import com.extjs.gxt.ui.client.widget.Info;
|
489 |
gduche |
32 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
512 |
gduche |
33 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
|
34 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
35 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
|
36 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
127 |
gduche |
37 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
38 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
278 |
jp_milcent |
39 |
import com.google.gwt.core.client.GWT;
|
127 |
gduche |
40 |
|
436 |
gduche |
41 |
public class PersonneListeVue extends ContentPanel implements Rafraichissable {
|
127 |
gduche |
42 |
|
278 |
jp_milcent |
43 |
private Mediateur mediateur = null ;
|
512 |
gduche |
44 |
|
|
|
45 |
private Grid<Personne> grille = null;
|
865 |
jpm |
46 |
private ListStore<Personne> store = null;
|
915 |
jpm |
47 |
private BarrePaginationVue pagination = null;
|
|
|
48 |
private ColumnModel modeleColonnes = null;
|
|
|
49 |
private Button ajouter = null;
|
|
|
50 |
private Button modifier = null;
|
|
|
51 |
private Button supprimer = null;
|
258 |
gduche |
52 |
|
1613 |
aurelien |
53 |
private int indexElementSelectionne = 0;
|
|
|
54 |
private Personne personneSelectionnee = null;
|
|
|
55 |
|
436 |
gduche |
56 |
public PersonneListeVue() {
|
278 |
jp_milcent |
57 |
mediateur = Registry.get(RegistreId.MEDIATEUR);
|
127 |
gduche |
58 |
|
865 |
jpm |
59 |
setHeading(Mediateur.i18nC.personneListeLabel());
|
566 |
jp_milcent |
60 |
setLayout(new FitLayout());
|
562 |
gduche |
61 |
|
127 |
gduche |
62 |
//Définition de la barre d'outil
|
|
|
63 |
ToolBar toolBar = new ToolBar();
|
915 |
jpm |
64 |
ajouter = new Button(Mediateur.i18nC.ajouter());
|
512 |
gduche |
65 |
ajouter.setIcon(Images.ICONES.ajouter());
|
489 |
gduche |
66 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
67 |
public void componentSelected(ButtonEvent ce) {
|
278 |
jp_milcent |
68 |
mediateur.clicAjouterPersonne();
|
127 |
gduche |
69 |
}
|
|
|
70 |
});
|
|
|
71 |
toolBar.add(ajouter);
|
|
|
72 |
|
865 |
jpm |
73 |
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) {
|
915 |
jpm |
77 |
mediateur.clicModifierPersonne(grille.getSelectionModel().getSelectedItems());
|
217 |
aurelien |
78 |
}
|
|
|
79 |
});
|
127 |
gduche |
80 |
toolBar.add(modifier);
|
|
|
81 |
|
865 |
jpm |
82 |
supprimer = new Button(Mediateur.i18nC.supprimer());
|
915 |
jpm |
83 |
supprimer.setIcon(Images.ICONES.supprimer());
|
489 |
gduche |
84 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
85 |
public void componentSelected(ButtonEvent ce) {
|
915 |
jpm |
86 |
clicSupprimerPersonne(grille.getSelectionModel().getSelectedItems());
|
217 |
aurelien |
87 |
}
|
|
|
88 |
});
|
127 |
gduche |
89 |
toolBar.add(supprimer);
|
|
|
90 |
setTopComponent(toolBar);
|
566 |
jp_milcent |
91 |
|
|
|
92 |
// Définition des colomnes de la grille:
|
512 |
gduche |
93 |
List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
|
677 |
gduche |
94 |
lstColumns.add(new ColumnConfig("id_personne", "Id", 45));
|
|
|
95 |
lstColumns.add(new ColumnConfig("nom", "Nom", 100));
|
|
|
96 |
lstColumns.add(new ColumnConfig("prenom", "Prénom", 100));
|
|
|
97 |
lstColumns.add(new ColumnConfig("fmt_nom_complet", "Nom Complet", 200));
|
|
|
98 |
lstColumns.add(new ColumnConfig("code_postal", "Code postal", 100));
|
|
|
99 |
lstColumns.add(new ColumnConfig("ville", "Ville", 100));
|
947 |
gduche |
100 |
lstColumns.add(new ColumnConfig("_courriel_princ_", "Courriel", 200));
|
677 |
gduche |
101 |
|
|
|
102 |
lstColumns.get(0).setHidden(true);
|
|
|
103 |
lstColumns.get(1).setHidden(true);
|
|
|
104 |
lstColumns.get(2).setHidden(true);
|
|
|
105 |
|
563 |
gduche |
106 |
modeleColonnes = new ColumnModel(lstColumns);
|
566 |
jp_milcent |
107 |
|
|
|
108 |
// Définition de la grille
|
512 |
gduche |
109 |
GridSelectionModel<Personne> gsmSelectionGrille = new GridSelectionModel<Personne>();
|
|
|
110 |
gsmSelectionGrille.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
|
520 |
gduche |
111 |
public void selectionChanged(SelectionChangedEvent<Personne> event) {
|
1613 |
aurelien |
112 |
personneSelectionnee = (Personne) event.getSelectedItem();
|
|
|
113 |
indexElementSelectionne = store.indexOf(personneSelectionnee);
|
915 |
jpm |
114 |
clicListe(personneSelectionnee);
|
520 |
gduche |
115 |
}
|
150 |
gduche |
116 |
});
|
287 |
gduche |
117 |
|
865 |
jpm |
118 |
store = new ListStore<Personne>();
|
|
|
119 |
store.sort("fmt_nom_complet", SortDir.ASC);
|
|
|
120 |
|
|
|
121 |
grille = new Grid<Personne>(store, modeleColonnes);
|
512 |
gduche |
122 |
grille.setSelectionModel(gsmSelectionGrille);
|
566 |
jp_milcent |
123 |
grille.setWidth("100%");
|
512 |
gduche |
124 |
grille.setAutoExpandColumn("fmt_nom_complet");
|
566 |
jp_milcent |
125 |
grille.getView().setAutoFill(true);
|
|
|
126 |
grille.getView().setForceFit(true);
|
|
|
127 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
|
|
128 |
public void handleEvent(BaseEvent be) {
|
624 |
gduche |
129 |
grille.getStore().sort("fmt_nom_complet", SortDir.ASC);
|
566 |
jp_milcent |
130 |
grille.getSelectionModel().select(0, false);
|
|
|
131 |
}
|
|
|
132 |
});
|
670 |
gduche |
133 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
|
|
|
134 |
public void handleEvent(BaseEvent be) {
|
|
|
135 |
modifier.fireEvent(Events.Select);
|
|
|
136 |
}
|
|
|
137 |
});
|
562 |
gduche |
138 |
add(grille);
|
512 |
gduche |
139 |
|
566 |
jp_milcent |
140 |
// Définition de la barre de pagination
|
596 |
gduche |
141 |
pagination = new BarrePaginationVue(new PersonneListe(), mediateur);
|
562 |
gduche |
142 |
setBottomComponent(pagination);
|
127 |
gduche |
143 |
}
|
|
|
144 |
|
150 |
gduche |
145 |
private void clicListe(Personne personne) {
|
865 |
jpm |
146 |
if (personne != null && store.getCount() > 0) {
|
|
|
147 |
mediateur.clicListePersonne(personne);
|
|
|
148 |
}
|
127 |
gduche |
149 |
}
|
915 |
jpm |
150 |
|
|
|
151 |
private void clicSupprimerPersonne(List<Personne> personnesASupprimer) {
|
|
|
152 |
if (store.getCount() > 0) {
|
|
|
153 |
mediateur.clicSupprimerPersonne(this, personnesASupprimer);
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
|
617 |
gduche |
157 |
private void gererEtatActivationBouton() {
|
915 |
jpm |
158 |
int nbreElementDuMagazin = store.getCount();
|
|
|
159 |
ajouter.enable();
|
|
|
160 |
if (nbreElementDuMagazin == 0) {
|
|
|
161 |
supprimer.disable();
|
|
|
162 |
modifier.disable();
|
|
|
163 |
} else if (nbreElementDuMagazin > 0) {
|
|
|
164 |
modifier.enable();
|
|
|
165 |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
|
|
|
166 |
supprimer.enable();
|
|
|
167 |
}
|
617 |
gduche |
168 |
}
|
|
|
169 |
}
|
|
|
170 |
|
353 |
gduche |
171 |
public void rafraichir(Object nouvellesDonnees) {
|
1367 |
cyprien |
172 |
|
353 |
gduche |
173 |
if (nouvellesDonnees instanceof PersonneListe) {
|
|
|
174 |
PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
|
127 |
gduche |
175 |
|
596 |
gduche |
176 |
pagination.setlistePaginable(listePersonnes);
|
|
|
177 |
pagination.rafraichir(listePersonnes.getPageTable());
|
|
|
178 |
|
567 |
jp_milcent |
179 |
if (listePersonnes != null) {
|
|
|
180 |
List<Personne> liste = (List<Personne>) listePersonnes.toList();
|
915 |
jpm |
181 |
store.removeAll();
|
596 |
gduche |
182 |
store.add(liste);
|
567 |
jp_milcent |
183 |
|
|
|
184 |
mediateur.actualiserPanneauCentral();
|
649 |
gduche |
185 |
grille.fireEvent(Events.ViewReady);
|
567 |
jp_milcent |
186 |
}
|
417 |
gduche |
187 |
} else if (nouvellesDonnees instanceof Information) {
|
|
|
188 |
Information info = (Information) nouvellesDonnees;
|
1613 |
aurelien |
189 |
if (info.getType().equals("maj_utilisateur")) {
|
|
|
190 |
gererEtatActivationBouton();
|
|
|
191 |
} else if(info.getType().equals("personne_modifiee")) {
|
|
|
192 |
if(personneSelectionnee != null) {
|
|
|
193 |
store.remove(indexElementSelectionne);
|
|
|
194 |
personneSelectionnee = null;
|
|
|
195 |
}
|
|
|
196 |
Personne personneModifiee = (Personne)info.getDonnee(0);
|
|
|
197 |
// au cas ou le bouton appliquer aurait été cliqué avant de valider
|
|
|
198 |
store.remove(personneModifiee);
|
|
|
199 |
store.insert(personneModifiee, indexElementSelectionne);
|
|
|
200 |
grille.repaint();
|
|
|
201 |
grille.getSelectionModel().select(indexElementSelectionne, true);
|
|
|
202 |
clicListe(personneModifiee);
|
|
|
203 |
} else if (info.getType().equals("suppression_personne")) {
|
1239 |
cyprien |
204 |
InfoLogger.display("Suppression de personne", info.getMessages().toString());
|
658 |
gduche |
205 |
pagination.getlistePaginable().recharger();
|
915 |
jpm |
206 |
gererEtatActivationBouton();
|
617 |
gduche |
207 |
} else if (info.getType().equals("maj_utilisateur")) {
|
|
|
208 |
gererEtatActivationBouton();
|
|
|
209 |
} else {
|
1239 |
cyprien |
210 |
InfoLogger.display("Erreur", info.getMessages().toString(), true);
|
361 |
jp_milcent |
211 |
}
|
|
|
212 |
} else {
|
865 |
jpm |
213 |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
127 |
gduche |
214 |
}
|
596 |
gduche |
215 |
|
278 |
jp_milcent |
216 |
layout();
|
127 |
gduche |
217 |
}
|
|
|
218 |
}
|
189 |
gduche |
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|