127 |
gduche |
1 |
package org.tela_botanica.client.vues;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Iterator;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
|
|
|
7 |
import org.tela_botanica.client.Mediateur;
|
|
|
8 |
import org.tela_botanica.client.RegistreId;
|
512 |
gduche |
9 |
import org.tela_botanica.client.images.Images;
|
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;
|
|
|
14 |
import com.extjs.gxt.ui.client.Registry;
|
377 |
gduche |
15 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
489 |
gduche |
16 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
127 |
gduche |
17 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
18 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|
|
19 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
20 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
21 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
353 |
gduche |
22 |
import com.extjs.gxt.ui.client.widget.Info;
|
489 |
gduche |
23 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
512 |
gduche |
24 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
|
25 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
26 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
|
27 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
127 |
gduche |
28 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
29 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
278 |
jp_milcent |
30 |
import com.google.gwt.core.client.GWT;
|
127 |
gduche |
31 |
|
436 |
gduche |
32 |
public class PersonneListeVue extends ContentPanel implements Rafraichissable {
|
127 |
gduche |
33 |
|
278 |
jp_milcent |
34 |
private Mediateur mediateur = null ;
|
512 |
gduche |
35 |
|
|
|
36 |
private Grid<Personne> grille = null;
|
287 |
gduche |
37 |
private Personne personneSelectionnee = null;
|
258 |
gduche |
38 |
|
436 |
gduche |
39 |
public PersonneListeVue() {
|
278 |
jp_milcent |
40 |
mediateur = Registry.get(RegistreId.MEDIATEUR);
|
127 |
gduche |
41 |
|
|
|
42 |
//Définition de la barre d'outil
|
|
|
43 |
ToolBar toolBar = new ToolBar();
|
489 |
gduche |
44 |
Button ajouter = new Button(mediateur.i18nC.ajouter());
|
512 |
gduche |
45 |
ajouter.setIcon(Images.ICONES.ajouter());
|
489 |
gduche |
46 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
47 |
public void componentSelected(ButtonEvent ce) {
|
278 |
jp_milcent |
48 |
mediateur.clicAjouterPersonne();
|
127 |
gduche |
49 |
}
|
|
|
50 |
});
|
|
|
51 |
toolBar.add(ajouter);
|
217 |
aurelien |
52 |
final Rafraichissable r = this ;
|
127 |
gduche |
53 |
|
489 |
gduche |
54 |
final Button modifier = new Button(mediateur.i18nC.modifier());
|
512 |
gduche |
55 |
modifier.setIcon(Images.ICONES.formModifier());
|
489 |
gduche |
56 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
57 |
public void componentSelected(ButtonEvent ce) {
|
287 |
gduche |
58 |
mediateur.clicModifierPersonne(personneSelectionnee);
|
217 |
aurelien |
59 |
}
|
|
|
60 |
});
|
127 |
gduche |
61 |
toolBar.add(modifier);
|
|
|
62 |
|
489 |
gduche |
63 |
final Button supprimer = new Button(mediateur.i18nC.supprimer());
|
|
|
64 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
65 |
public void componentSelected(ButtonEvent ce) {
|
512 |
gduche |
66 |
mediateur.clicSupprimerPersonne(r, grille.getSelectionModel().getSelectedItems());
|
217 |
aurelien |
67 |
}
|
|
|
68 |
});
|
417 |
gduche |
69 |
|
512 |
gduche |
70 |
supprimer.setIcon(Images.ICONES.supprimer());
|
127 |
gduche |
71 |
toolBar.add(supprimer);
|
|
|
72 |
setTopComponent(toolBar);
|
258 |
gduche |
73 |
|
512 |
gduche |
74 |
List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
|
127 |
gduche |
75 |
|
512 |
gduche |
76 |
// Définition des colomnes de la grille:
|
541 |
gduche |
77 |
ColumnConfig ccId = new ColumnConfig();
|
|
|
78 |
ccId.setId("id_personne");
|
|
|
79 |
ccId.setHeader("Id");
|
|
|
80 |
ccId.setWidth(45);
|
|
|
81 |
lstColumns.add(ccId);
|
|
|
82 |
|
512 |
gduche |
83 |
ColumnConfig ccFmtNomComplet = new ColumnConfig();
|
|
|
84 |
ccFmtNomComplet.setId("fmt_nom_complet");
|
|
|
85 |
ccFmtNomComplet.setHeader("Nom Complet");
|
|
|
86 |
ccFmtNomComplet.setWidth(200);
|
|
|
87 |
lstColumns.add(ccFmtNomComplet);
|
127 |
gduche |
88 |
|
512 |
gduche |
89 |
ColumnConfig ccCodePostal = new ColumnConfig();
|
|
|
90 |
ccCodePostal.setId("code_postal");
|
|
|
91 |
ccCodePostal.setHeader("Code postal");
|
|
|
92 |
ccCodePostal.setWidth(100);
|
|
|
93 |
lstColumns.add(ccCodePostal);
|
462 |
gduche |
94 |
|
512 |
gduche |
95 |
ColumnConfig ccVille = new ColumnConfig();
|
|
|
96 |
ccVille.setId("ville");
|
|
|
97 |
ccVille.setHeader("Ville");
|
|
|
98 |
ccVille.setWidth(100);
|
|
|
99 |
lstColumns.add(ccVille);
|
127 |
gduche |
100 |
|
512 |
gduche |
101 |
ColumnConfig ccCourriel = new ColumnConfig();
|
|
|
102 |
ccCourriel.setId("courriel_princ");
|
|
|
103 |
ccCourriel.setHeader("Courriel");
|
|
|
104 |
ccCourriel.setWidth(200);
|
|
|
105 |
lstColumns.add(ccCourriel);
|
287 |
gduche |
106 |
|
512 |
gduche |
107 |
ColumnConfig ccNom = new ColumnConfig();
|
|
|
108 |
ccNom.setId("nom");
|
|
|
109 |
ccNom.setHeader("Nom");
|
|
|
110 |
ccNom.setWidth(100);
|
|
|
111 |
ccNom.setHidden(true);
|
|
|
112 |
lstColumns.add(ccNom);
|
287 |
gduche |
113 |
|
512 |
gduche |
114 |
ColumnConfig ccPrenom = new ColumnConfig();
|
|
|
115 |
ccPrenom.setId("prenom");
|
|
|
116 |
ccPrenom.setHeader("Prénom");
|
|
|
117 |
ccPrenom.setWidth(100);
|
|
|
118 |
ccPrenom.setHidden(true);
|
|
|
119 |
lstColumns.add(ccPrenom);
|
150 |
gduche |
120 |
|
512 |
gduche |
121 |
grille = new Grid<Personne>( new ListStore<Personne>(),new ColumnModel(lstColumns));
|
|
|
122 |
GridSelectionModel<Personne> gsmSelectionGrille = new GridSelectionModel<Personne>();
|
|
|
123 |
gsmSelectionGrille.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
|
520 |
gduche |
124 |
public void selectionChanged(SelectionChangedEvent<Personne> event) {
|
|
|
125 |
Personne p = (Personne) event.getSelectedItem();
|
|
|
126 |
personneSelectionnee = p;
|
|
|
127 |
clicListe(p);
|
|
|
128 |
}
|
150 |
gduche |
129 |
});
|
287 |
gduche |
130 |
|
512 |
gduche |
131 |
grille.setSelectionModel(gsmSelectionGrille);
|
|
|
132 |
grille.setAutoExpandColumn("fmt_nom_complet");
|
|
|
133 |
|
528 |
gduche |
134 |
|
512 |
gduche |
135 |
add(grille);
|
127 |
gduche |
136 |
setLayout(new FitLayout());
|
|
|
137 |
}
|
|
|
138 |
|
150 |
gduche |
139 |
private void clicListe(Personne personne) {
|
278 |
jp_milcent |
140 |
mediateur.clicListePersonne(personne);
|
127 |
gduche |
141 |
}
|
|
|
142 |
|
353 |
gduche |
143 |
public void rafraichir(Object nouvellesDonnees) {
|
417 |
gduche |
144 |
|
353 |
gduche |
145 |
if (nouvellesDonnees instanceof PersonneListe) {
|
417 |
gduche |
146 |
|
462 |
gduche |
147 |
setHeading(mediateur.i18nC.personneListeLabel());
|
353 |
gduche |
148 |
PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
|
127 |
gduche |
149 |
|
|
|
150 |
List<Personne> liste = new ArrayList<Personne>();
|
|
|
151 |
for (Iterator<String> it = listePersonnes.keySet().iterator(); it.hasNext();) {
|
|
|
152 |
liste.add(listePersonnes.get(it.next()));
|
|
|
153 |
}
|
|
|
154 |
|
512 |
gduche |
155 |
ListStore<Personne> store = grille.getStore();
|
278 |
jp_milcent |
156 |
store.removeAll();
|
|
|
157 |
store.add(liste);
|
377 |
gduche |
158 |
|
417 |
gduche |
159 |
mediateur.actualiserPanneauCentral();
|
377 |
gduche |
160 |
|
512 |
gduche |
161 |
store.sort("fmt_nom_complet", SortDir.ASC);
|
417 |
gduche |
162 |
if (store.getCount() > 0) {
|
528 |
gduche |
163 |
//FIXME : la selection d'une ligne ne mets pas le style voulu (ligne sélectionnée)
|
|
|
164 |
grille.getSelectionModel().select(store.getAt(0), true);
|
417 |
gduche |
165 |
}
|
377 |
gduche |
166 |
|
417 |
gduche |
167 |
} else if (nouvellesDonnees instanceof Information) {
|
377 |
gduche |
168 |
|
417 |
gduche |
169 |
Information info = (Information) nouvellesDonnees;
|
|
|
170 |
if (info.getType().equals("suppression_personne")) {
|
512 |
gduche |
171 |
|
|
|
172 |
Info.display("Suppression de personne", info.getMessages().toString());
|
417 |
gduche |
173 |
|
512 |
gduche |
174 |
List<Personne> selectionPersonnes = grille.getSelectionModel().getSelectedItems();
|
417 |
gduche |
175 |
final int taille = selectionPersonnes.size();
|
|
|
176 |
for (int i = 0; i < taille; i++) {
|
512 |
gduche |
177 |
grille.getStore().remove(selectionPersonnes.get(i));
|
417 |
gduche |
178 |
}
|
512 |
gduche |
179 |
} else {
|
|
|
180 |
Info.display("Erreur", info.getMessages().toString());
|
361 |
jp_milcent |
181 |
}
|
|
|
182 |
|
|
|
183 |
} else {
|
533 |
jp_milcent |
184 |
GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
127 |
gduche |
185 |
}
|
278 |
jp_milcent |
186 |
layout();
|
127 |
gduche |
187 |
}
|
|
|
188 |
}
|
189 |
gduche |
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|