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;
|
127 |
gduche |
9 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
353 |
gduche |
10 |
import org.tela_botanica.client.modeles.Information;
|
127 |
gduche |
11 |
import org.tela_botanica.client.modeles.Personne;
|
|
|
12 |
import org.tela_botanica.client.modeles.PersonneListe;
|
|
|
13 |
import com.extjs.gxt.ui.client.Registry;
|
377 |
gduche |
14 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
562 |
gduche |
15 |
import com.extjs.gxt.ui.client.data.BasePagingLoader;
|
|
|
16 |
import com.extjs.gxt.ui.client.data.ModelData;
|
|
|
17 |
import com.extjs.gxt.ui.client.data.PagingLoadResult;
|
|
|
18 |
import com.extjs.gxt.ui.client.data.PagingLoader;
|
|
|
19 |
import com.extjs.gxt.ui.client.data.PagingModelMemoryProxy;
|
566 |
jp_milcent |
20 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
489 |
gduche |
21 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
566 |
jp_milcent |
22 |
import com.extjs.gxt.ui.client.event.Events;
|
|
|
23 |
import com.extjs.gxt.ui.client.event.Listener;
|
127 |
gduche |
24 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
25 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|
|
26 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
27 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
28 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
353 |
gduche |
29 |
import com.extjs.gxt.ui.client.widget.Info;
|
489 |
gduche |
30 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
512 |
gduche |
31 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
|
32 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
33 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
|
34 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
127 |
gduche |
35 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
562 |
gduche |
36 |
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
|
127 |
gduche |
37 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
278 |
jp_milcent |
38 |
import com.google.gwt.core.client.GWT;
|
562 |
gduche |
39 |
import com.google.gwt.i18n.client.Dictionary;
|
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;
|
287 |
gduche |
46 |
private Personne personneSelectionnee = null;
|
562 |
gduche |
47 |
private PagingToolBar pagination;
|
563 |
gduche |
48 |
private ColumnModel modeleColonnes;
|
562 |
gduche |
49 |
private final int nbElementsPage = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbElementsPage"));
|
258 |
gduche |
50 |
|
436 |
gduche |
51 |
public PersonneListeVue() {
|
278 |
jp_milcent |
52 |
mediateur = Registry.get(RegistreId.MEDIATEUR);
|
127 |
gduche |
53 |
|
566 |
jp_milcent |
54 |
setHeading(mediateur.i18nC.personneListeLabel());
|
|
|
55 |
setLayout(new FitLayout());
|
562 |
gduche |
56 |
|
127 |
gduche |
57 |
//Définition de la barre d'outil
|
|
|
58 |
ToolBar toolBar = new ToolBar();
|
489 |
gduche |
59 |
Button ajouter = new Button(mediateur.i18nC.ajouter());
|
512 |
gduche |
60 |
ajouter.setIcon(Images.ICONES.ajouter());
|
489 |
gduche |
61 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
62 |
public void componentSelected(ButtonEvent ce) {
|
278 |
jp_milcent |
63 |
mediateur.clicAjouterPersonne();
|
127 |
gduche |
64 |
}
|
|
|
65 |
});
|
|
|
66 |
toolBar.add(ajouter);
|
217 |
aurelien |
67 |
final Rafraichissable r = this ;
|
127 |
gduche |
68 |
|
489 |
gduche |
69 |
final Button modifier = new Button(mediateur.i18nC.modifier());
|
512 |
gduche |
70 |
modifier.setIcon(Images.ICONES.formModifier());
|
489 |
gduche |
71 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
72 |
public void componentSelected(ButtonEvent ce) {
|
287 |
gduche |
73 |
mediateur.clicModifierPersonne(personneSelectionnee);
|
217 |
aurelien |
74 |
}
|
|
|
75 |
});
|
127 |
gduche |
76 |
toolBar.add(modifier);
|
|
|
77 |
|
489 |
gduche |
78 |
final Button supprimer = new Button(mediateur.i18nC.supprimer());
|
|
|
79 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
80 |
public void componentSelected(ButtonEvent ce) {
|
512 |
gduche |
81 |
mediateur.clicSupprimerPersonne(r, grille.getSelectionModel().getSelectedItems());
|
217 |
aurelien |
82 |
}
|
|
|
83 |
});
|
512 |
gduche |
84 |
supprimer.setIcon(Images.ICONES.supprimer());
|
127 |
gduche |
85 |
toolBar.add(supprimer);
|
566 |
jp_milcent |
86 |
|
127 |
gduche |
87 |
setTopComponent(toolBar);
|
566 |
jp_milcent |
88 |
|
|
|
89 |
// Définition des colomnes de la grille:
|
512 |
gduche |
90 |
List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
|
566 |
jp_milcent |
91 |
ColumnConfig ccId = new ColumnConfig("id_personne", "Id", 45);
|
541 |
gduche |
92 |
lstColumns.add(ccId);
|
566 |
jp_milcent |
93 |
ColumnConfig ccFmtNomComplet = new ColumnConfig("fmt_nom_complet", "Nom Complet", 200);
|
512 |
gduche |
94 |
lstColumns.add(ccFmtNomComplet);
|
566 |
jp_milcent |
95 |
ColumnConfig ccCodePostal = new ColumnConfig("code_postal", "Code postal", 100);
|
512 |
gduche |
96 |
lstColumns.add(ccCodePostal);
|
566 |
jp_milcent |
97 |
ColumnConfig ccVille = new ColumnConfig("ville", "Ville", 100);
|
512 |
gduche |
98 |
lstColumns.add(ccVille);
|
566 |
jp_milcent |
99 |
ColumnConfig ccCourriel = new ColumnConfig("courriel_princ", "Courriel", 200);
|
512 |
gduche |
100 |
lstColumns.add(ccCourriel);
|
566 |
jp_milcent |
101 |
ColumnConfig ccNom = new ColumnConfig("nom", "Nom", 100);
|
512 |
gduche |
102 |
ccNom.setHidden(true);
|
|
|
103 |
lstColumns.add(ccNom);
|
566 |
jp_milcent |
104 |
ColumnConfig ccPrenom = new ColumnConfig("prenom", "Prénom", 100);
|
512 |
gduche |
105 |
ccPrenom.setHidden(true);
|
|
|
106 |
lstColumns.add(ccPrenom);
|
563 |
gduche |
107 |
modeleColonnes = new ColumnModel(lstColumns);
|
566 |
jp_milcent |
108 |
|
|
|
109 |
// Définition de la grille
|
512 |
gduche |
110 |
GridSelectionModel<Personne> gsmSelectionGrille = new GridSelectionModel<Personne>();
|
|
|
111 |
gsmSelectionGrille.addSelectionChangedListener(new SelectionChangedListener<Personne>() {
|
520 |
gduche |
112 |
public void selectionChanged(SelectionChangedEvent<Personne> event) {
|
|
|
113 |
Personne p = (Personne) event.getSelectedItem();
|
|
|
114 |
personneSelectionnee = p;
|
|
|
115 |
clicListe(p);
|
|
|
116 |
}
|
150 |
gduche |
117 |
});
|
287 |
gduche |
118 |
|
566 |
jp_milcent |
119 |
grille = new Grid<Personne>( new ListStore<Personne>(), modeleColonnes);
|
512 |
gduche |
120 |
grille.setSelectionModel(gsmSelectionGrille);
|
566 |
jp_milcent |
121 |
grille.setWidth("100%");
|
512 |
gduche |
122 |
grille.setAutoExpandColumn("fmt_nom_complet");
|
566 |
jp_milcent |
123 |
grille.getView().setAutoFill(true);
|
|
|
124 |
grille.getView().setForceFit(true);
|
|
|
125 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
|
|
126 |
@Override
|
|
|
127 |
public void handleEvent(BaseEvent be) {
|
|
|
128 |
grille.getSelectionModel().select(0, false);
|
|
|
129 |
}
|
|
|
130 |
});
|
562 |
gduche |
131 |
add(grille);
|
512 |
gduche |
132 |
|
566 |
jp_milcent |
133 |
// Définition de la barre de pagination
|
562 |
gduche |
134 |
pagination = new PagingToolBar(nbElementsPage);
|
|
|
135 |
setBottomComponent(pagination);
|
127 |
gduche |
136 |
}
|
|
|
137 |
|
150 |
gduche |
138 |
private void clicListe(Personne personne) {
|
278 |
jp_milcent |
139 |
mediateur.clicListePersonne(personne);
|
127 |
gduche |
140 |
}
|
|
|
141 |
|
353 |
gduche |
142 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
143 |
if (nouvellesDonnees instanceof PersonneListe) {
|
|
|
144 |
PersonneListe listePersonnes = (PersonneListe) nouvellesDonnees;
|
566 |
jp_milcent |
145 |
List<Personne> liste = (List<Personne>) listePersonnes.toList();
|
127 |
gduche |
146 |
|
562 |
gduche |
147 |
PagingModelMemoryProxy proxy = new PagingModelMemoryProxy(liste);
|
|
|
148 |
PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(proxy);
|
|
|
149 |
loader.setRemoteSort(true);
|
|
|
150 |
pagination.bind(loader);
|
|
|
151 |
loader.load(0, nbElementsPage);
|
377 |
gduche |
152 |
|
562 |
gduche |
153 |
ListStore<Personne> store = new ListStore<Personne>(loader);
|
563 |
gduche |
154 |
grille.reconfigure(store, modeleColonnes);
|
562 |
gduche |
155 |
|
417 |
gduche |
156 |
mediateur.actualiserPanneauCentral();
|
512 |
gduche |
157 |
store.sort("fmt_nom_complet", SortDir.ASC);
|
377 |
gduche |
158 |
|
417 |
gduche |
159 |
} else if (nouvellesDonnees instanceof Information) {
|
|
|
160 |
Information info = (Information) nouvellesDonnees;
|
|
|
161 |
if (info.getType().equals("suppression_personne")) {
|
512 |
gduche |
162 |
Info.display("Suppression de personne", info.getMessages().toString());
|
566 |
jp_milcent |
163 |
List<Personne> selectionPersonnes = grille.getSelectionModel().getSelectedItems();
|
|
|
164 |
final int taille = selectionPersonnes.size();
|
|
|
165 |
for (int i = 0; i < taille; i++) {
|
|
|
166 |
grille.getStore().remove(selectionPersonnes.get(i));
|
|
|
167 |
}
|
512 |
gduche |
168 |
} else {
|
|
|
169 |
Info.display("Erreur", info.getMessages().toString());
|
361 |
jp_milcent |
170 |
}
|
|
|
171 |
} else {
|
533 |
jp_milcent |
172 |
GWT.log(mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
127 |
gduche |
173 |
}
|
278 |
jp_milcent |
174 |
layout();
|
127 |
gduche |
175 |
}
|
|
|
176 |
}
|
189 |
gduche |
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|