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