1 |
package org.tela_botanica.client.vues.structure;
|
1 |
package org.tela_botanica.client.vues.structure;
|
2 |
|
2 |
|
3 |
import java.util.ArrayList;
|
3 |
import java.util.ArrayList;
|
4 |
import java.util.List;
|
4 |
import java.util.List;
|
5 |
|
5 |
|
6 |
import org.tela_botanica.client.Mediateur;
|
6 |
import org.tela_botanica.client.Mediateur;
|
7 |
import org.tela_botanica.client.RegistreId;
|
7 |
import org.tela_botanica.client.RegistreId;
|
8 |
import org.tela_botanica.client.composants.InfoLogger;
|
8 |
import org.tela_botanica.client.composants.InfoLogger;
|
9 |
import org.tela_botanica.client.i18n.Constantes;
|
9 |
import org.tela_botanica.client.i18n.Constantes;
|
10 |
import org.tela_botanica.client.images.Images;
|
10 |
import org.tela_botanica.client.images.Images;
|
11 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
11 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
12 |
import org.tela_botanica.client.modeles.Information;
|
12 |
import org.tela_botanica.client.modeles.Information;
|
13 |
import org.tela_botanica.client.modeles.Utilisateur;
|
13 |
import org.tela_botanica.client.modeles.Utilisateur;
|
14 |
import org.tela_botanica.client.modeles.structure.Structure;
|
14 |
import org.tela_botanica.client.modeles.structure.Structure;
|
15 |
import org.tela_botanica.client.modeles.structure.StructureListe;
|
15 |
import org.tela_botanica.client.modeles.structure.StructureListe;
|
16 |
import org.tela_botanica.client.vues.BarrePaginationVue;
|
16 |
import org.tela_botanica.client.vues.BarrePaginationVue;
|
17 |
|
17 |
|
18 |
import com.extjs.gxt.ui.client.Registry;
|
18 |
import com.extjs.gxt.ui.client.Registry;
|
19 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
19 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
20 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
20 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
21 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
21 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
22 |
import com.extjs.gxt.ui.client.event.Events;
|
22 |
import com.extjs.gxt.ui.client.event.Events;
|
23 |
import com.extjs.gxt.ui.client.event.Listener;
|
23 |
import com.extjs.gxt.ui.client.event.Listener;
|
24 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
24 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
25 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
25 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
26 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
26 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
27 |
import com.extjs.gxt.ui.client.store.ListStore;
|
27 |
import com.extjs.gxt.ui.client.store.ListStore;
|
28 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
28 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
29 |
import com.extjs.gxt.ui.client.widget.Info;
|
29 |
import com.extjs.gxt.ui.client.widget.Info;
|
30 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
30 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
31 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
31 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
32 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
32 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
33 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
33 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
34 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
34 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
35 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
35 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
36 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
36 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
37 |
import com.google.gwt.core.client.GWT;
|
37 |
import com.google.gwt.core.client.GWT;
|
38 |
import com.google.gwt.user.client.Window;
|
38 |
import com.google.gwt.user.client.Window;
|
39 |
|
39 |
|
40 |
public class StructureListeVue extends ContentPanel implements Rafraichissable {
|
40 |
public class StructureListeVue extends ContentPanel implements Rafraichissable {
|
41 |
|
41 |
|
42 |
private Mediateur mediateur = null;
|
42 |
private Mediateur mediateur = null;
|
43 |
private Constantes i18nC = null;
|
43 |
private Constantes i18nC = null;
|
44 |
|
44 |
|
45 |
private Grid<Structure> grille = null;
|
45 |
private Grid<Structure> grille = null;
|
46 |
private ListStore<Structure> store = null;
|
46 |
private ListStore<Structure> store = null;
|
47 |
|
47 |
|
48 |
private Button modifier;
|
48 |
private Button modifier;
|
49 |
private Button supprimer;
|
49 |
private Button supprimer;
|
50 |
private Button ajouter;
|
50 |
private Button ajouter;
|
51 |
|
51 |
|
52 |
private BarrePaginationVue pagination = null;
|
52 |
private BarrePaginationVue pagination = null;
|
53 |
|
53 |
|
54 |
public StructureListeVue(Mediateur mediateurCourant) {
|
54 |
public StructureListeVue(Mediateur mediateurCourant) {
|
55 |
mediateur = mediateurCourant;
|
55 |
mediateur = mediateurCourant;
|
56 |
i18nC = mediateur.i18nC;
|
56 |
i18nC = mediateur.i18nC;
|
57 |
|
57 |
|
58 |
setHeading(i18nC.titreStructureListe());
|
58 |
setHeading(i18nC.titreStructureListe());
|
59 |
setLayout(new FitLayout());
|
59 |
setLayout(new FitLayout());
|
60 |
|
60 |
|
61 |
ToolBar toolBar = new ToolBar();
|
61 |
ToolBar toolBar = new ToolBar();
|
62 |
ajouter = new Button(i18nC.ajouter());
|
62 |
ajouter = new Button(i18nC.ajouter());
|
63 |
ajouter.setIcon(Images.ICONES.ajouter());
|
63 |
ajouter.setIcon(Images.ICONES.ajouter());
|
64 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
64 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
65 |
public void componentSelected(ButtonEvent ce) {
|
65 |
public void componentSelected(ButtonEvent ce) {
|
66 |
mediateur.clicAjouterStructure();
|
66 |
mediateur.clicAjouterStructure();
|
67 |
}
|
67 |
}
|
68 |
});
|
68 |
});
|
69 |
toolBar.add(ajouter);
|
69 |
toolBar.add(ajouter);
|
70 |
|
70 |
|
71 |
modifier = new Button(i18nC.modifier());
|
71 |
modifier = new Button(i18nC.modifier());
|
72 |
modifier.setIcon(Images.ICONES.formModifier());
|
72 |
modifier.setIcon(Images.ICONES.formModifier());
|
73 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
73 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
74 |
public void componentSelected(ButtonEvent ce) {
|
74 |
public void componentSelected(ButtonEvent ce) {
|
75 |
mediateur.clicModifierStructure(grille.getSelectionModel().getSelectedItems());
|
75 |
mediateur.clicModifierStructure(grille.getSelectionModel().getSelectedItems());
|
76 |
}
|
76 |
}
|
77 |
});
|
77 |
});
|
78 |
toolBar.add(modifier);
|
78 |
toolBar.add(modifier);
|
79 |
|
79 |
|
80 |
supprimer = new Button(i18nC.supprimer());
|
80 |
supprimer = new Button(i18nC.supprimer());
|
81 |
supprimer.setIcon(Images.ICONES.supprimer());
|
81 |
supprimer.setIcon(Images.ICONES.supprimer());
|
82 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
82 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
83 |
public void componentSelected(ButtonEvent ce) {
|
83 |
public void componentSelected(ButtonEvent ce) {
|
84 |
clicSupprimerStructure(grille.getSelectionModel().getSelectedItems());
|
84 |
clicSupprimerStructure(grille.getSelectionModel().getSelectedItems());
|
85 |
}
|
85 |
}
|
86 |
});
|
86 |
});
|
87 |
toolBar.add(supprimer);
|
87 |
toolBar.add(supprimer);
|
88 |
|
88 |
|
89 |
setTopComponent(toolBar);
|
89 |
setTopComponent(toolBar);
|
90 |
|
90 |
|
91 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
91 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
92 |
colonnes.add(new ColumnConfig("ville", "Ville", 150));
|
92 |
colonnes.add(new ColumnConfig("ville", "Ville", 150));
|
93 |
colonnes.add(new ColumnConfig("nom", "Nom", 450));
|
93 |
colonnes.add(new ColumnConfig("nom", "Nom", 450));
|
94 |
ColumnModel modeleDeColonne = new ColumnModel(colonnes);
|
94 |
ColumnModel modeleDeColonne = new ColumnModel(colonnes);
|
95 |
|
95 |
|
96 |
GridSelectionModel<Structure> modeleDeSelection = new GridSelectionModel<Structure>();
|
96 |
GridSelectionModel<Structure> modeleDeSelection = new GridSelectionModel<Structure>();
|
97 |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
|
97 |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
|
98 |
public void selectionChanged(SelectionChangedEvent<Structure> event) {
|
98 |
public void selectionChanged(SelectionChangedEvent<Structure> event) {
|
99 |
Structure structureSelectionnee = (Structure) event.getSelectedItem();
|
99 |
Structure structureSelectionnee = (Structure) event.getSelectedItem();
|
100 |
clicListe(structureSelectionnee);
|
100 |
clicListe(structureSelectionnee);
|
101 |
}
|
101 |
}
|
102 |
});
|
102 |
});
|
103 |
|
103 |
|
104 |
store = new ListStore<Structure>();
|
104 |
store = new ListStore<Structure>();
|
105 |
store.sort("ville", SortDir.ASC);
|
105 |
store.sort("ville", SortDir.ASC);
|
106 |
|
106 |
|
107 |
grille = new Grid<Structure>(store, modeleDeColonne);
|
107 |
grille = new Grid<Structure>(store, modeleDeColonne);
|
108 |
grille.setWidth("100%");
|
108 |
grille.setWidth("100%");
|
109 |
grille.setAutoExpandColumn("nom");
|
109 |
grille.setAutoExpandColumn("nom");
|
110 |
grille.getView().setAutoFill(true);
|
110 |
grille.getView().setAutoFill(true);
|
111 |
grille.getView().setForceFit(true);
|
111 |
grille.getView().setForceFit(true);
|
112 |
grille.setSelectionModel(modeleDeSelection);
|
112 |
grille.setSelectionModel(modeleDeSelection);
|
113 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
113 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
114 |
@Override
|
- |
|
115 |
public void handleEvent(BaseEvent be) {
|
114 |
public void handleEvent(BaseEvent be) {
|
116 |
grille.getSelectionModel().select(0, false);
|
115 |
grille.getSelectionModel().select(0, false);
|
117 |
}
|
116 |
}
|
118 |
});
|
117 |
});
|
119 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
|
118 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
|
120 |
@Override
|
- |
|
121 |
public void handleEvent(BaseEvent be) {
|
119 |
public void handleEvent(BaseEvent be) {
|
122 |
modifier.fireEvent(Events.Select);
|
120 |
modifier.fireEvent(Events.Select);
|
123 |
}
|
121 |
}
|
124 |
});
|
122 |
});
|
125 |
add(grille);
|
123 |
add(grille);
|
126 |
|
124 |
|
127 |
// Définition de la barre de pagination
|
125 |
// Définition de la barre de pagination
|
128 |
pagination = new BarrePaginationVue(new StructureListe(), mediateur);
|
126 |
pagination = new BarrePaginationVue(new StructureListe(), mediateur);
|
129 |
setBottomComponent(pagination);
|
127 |
setBottomComponent(pagination);
|
130 |
}
|
128 |
}
|
131 |
|
129 |
|
132 |
private void clicListe(Structure structure) {
|
130 |
private void clicListe(Structure structure) {
|
133 |
if (structure != null && store.getCount() > 0) {
|
131 |
if (structure != null && store.getCount() > 0) {
|
134 |
mediateur.clicListeStructure(structure);
|
132 |
mediateur.clicListeStructure(structure);
|
135 |
}
|
133 |
}
|
136 |
}
|
134 |
}
|
137 |
|
135 |
|
138 |
private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
|
136 |
private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
|
139 |
mediateur.clicSupprimerStructure(this, structuresASupprimer);
|
137 |
mediateur.clicSupprimerStructure(this, structuresASupprimer);
|
140 |
}
|
138 |
}
|
141 |
|
139 |
|
142 |
private void gererEtatActivationBouton() {
|
140 |
private void gererEtatActivationBouton() {
|
143 |
int nbreElementDuMagazin = store.getCount();
|
141 |
int nbreElementDuMagazin = store.getCount();
|
144 |
if (nbreElementDuMagazin == 0) {
|
142 |
if (nbreElementDuMagazin == 0) {
|
145 |
supprimer.disable();
|
143 |
supprimer.disable();
|
146 |
modifier.disable();
|
144 |
modifier.disable();
|
147 |
} else if (nbreElementDuMagazin > 0) {
|
145 |
} else if (nbreElementDuMagazin > 0) {
|
148 |
modifier.enable();
|
146 |
modifier.enable();
|
149 |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
|
147 |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
|
150 |
supprimer.enable();
|
148 |
supprimer.enable();
|
151 |
}
|
149 |
}
|
152 |
}
|
150 |
}
|
153 |
}
|
151 |
}
|
154 |
|
152 |
|
155 |
public void rafraichir(Object nouvellesDonnees) {
|
153 |
public void rafraichir(Object nouvellesDonnees) {
|
156 |
if (nouvellesDonnees instanceof StructureListe) {
|
154 |
if (nouvellesDonnees instanceof StructureListe) {
|
157 |
StructureListe structures = (StructureListe) nouvellesDonnees;
|
155 |
StructureListe structures = (StructureListe) nouvellesDonnees;
|
158 |
pagination.setlistePaginable(structures);
|
156 |
pagination.setlistePaginable(structures);
|
159 |
pagination.rafraichir(structures.getPageTable());
|
157 |
pagination.rafraichir(structures.getPageTable());
|
160 |
|
158 |
|
161 |
if (structures != null) {
|
159 |
if (structures != null) {
|
162 |
List<Structure> liste = structures.toList();
|
160 |
List<Structure> liste = structures.toList();
|
163 |
store.removeAll();
|
161 |
store.removeAll();
|
164 |
store.add(liste);
|
162 |
store.add(liste);
|
165 |
|
163 |
|
166 |
gererEtatActivationBouton();
|
164 |
gererEtatActivationBouton();
|
167 |
|
165 |
|
168 |
mediateur.actualiserPanneauCentral();
|
166 |
mediateur.actualiserPanneauCentral();
|
169 |
grille.fireEvent(Events.ViewReady);
|
167 |
grille.fireEvent(Events.ViewReady);
|
170 |
}
|
168 |
}
|
171 |
} else if (nouvellesDonnees instanceof Information) {
|
169 |
} else if (nouvellesDonnees instanceof Information) {
|
172 |
Information info = (Information) nouvellesDonnees;
|
170 |
Information info = (Information) nouvellesDonnees;
|
173 |
if (info.getType().equals("suppression_structure")) {
|
171 |
if (info.getType().equals("suppression_structure")) {
|
174 |
// Affichage d'un message d'information
|
172 |
// Affichage d'un message d'information
|
175 |
InfoLogger.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
|
173 |
InfoLogger.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
|
176 |
|
174 |
|
177 |
List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();
|
175 |
List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();
|
178 |
|
176 |
|
179 |
if (info.toString().replaceAll("\n", "").equals("OK")) {
|
177 |
if (info.toString().replaceAll("\n", "").equals("OK")) {
|
180 |
mediateur.supprimerStructureAPersonne(this, selectionStructure);
|
178 |
mediateur.supprimerStructureAPersonne(this, selectionStructure);
|
181 |
}
|
179 |
}
|
182 |
|
180 |
|
183 |
// Suppression des structures sélectionnées de la grille
|
181 |
// Suppression des structures sélectionnées de la grille
|
184 |
final int taille = selectionStructure.size();
|
182 |
final int taille = selectionStructure.size();
|
185 |
for (int i = 0; i < taille; i++) {
|
183 |
for (int i = 0; i < taille; i++) {
|
186 |
store.remove(selectionStructure.get(i));
|
184 |
store.remove(selectionStructure.get(i));
|
187 |
}
|
185 |
}
|
188 |
|
186 |
|
189 |
gererEtatActivationBouton();
|
187 |
gererEtatActivationBouton();
|
190 |
} else if (info.getType().equals("maj_utilisateur")) {
|
188 |
} else if (info.getType().equals("maj_utilisateur")) {
|
191 |
gererEtatActivationBouton();
|
189 |
gererEtatActivationBouton();
|
192 |
} else if (info.getType().equals("suppression_structure_a_personne")) {
|
190 |
} else if (info.getType().equals("suppression_structure_a_personne")) {
|
193 |
// Affichage d'un message d'information
|
191 |
// Affichage d'un message d'information
|
194 |
InfoLogger.display(i18nC.suppressionStructureAPersonne(), info.toString().replaceAll("\n", "<br />"));
|
192 |
InfoLogger.display(i18nC.suppressionStructureAPersonne(), info.toString().replaceAll("\n", "<br />"));
|
195 |
}
|
193 |
}
|
196 |
} else {
|
194 |
} else {
|
197 |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
195 |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
198 |
}
|
196 |
}
|
199 |
layout();
|
197 |
layout();
|
200 |
}
|
198 |
}
|
201 |
}
|
199 |
}
|