1 |
package org.tela_botanica.client.vues.projet;
|
1 |
package org.tela_botanica.client.vues.projet;
|
2 |
|
2 |
|
3 |
import java.util.ArrayList;
|
3 |
import java.util.ArrayList;
|
4 |
import java.util.Arrays;
|
4 |
import java.util.Arrays;
|
5 |
import java.util.Iterator;
|
5 |
import java.util.Iterator;
|
6 |
import java.util.List;
|
6 |
import java.util.List;
|
7 |
|
7 |
|
8 |
import org.tela_botanica.client.Mediateur;
|
8 |
import org.tela_botanica.client.Mediateur;
|
9 |
import org.tela_botanica.client.RegistreId;
|
9 |
import org.tela_botanica.client.RegistreId;
|
10 |
import org.tela_botanica.client.composants.InfoLogger;
|
10 |
import org.tela_botanica.client.composants.InfoLogger;
|
11 |
import org.tela_botanica.client.i18n.Constantes;
|
11 |
import org.tela_botanica.client.i18n.Constantes;
|
12 |
import org.tela_botanica.client.images.Images;
|
12 |
import org.tela_botanica.client.images.Images;
|
13 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
13 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
14 |
import org.tela_botanica.client.modeles.Information;
|
14 |
import org.tela_botanica.client.modeles.Information;
|
15 |
import org.tela_botanica.client.modeles.Utilisateur;
|
15 |
import org.tela_botanica.client.modeles.Utilisateur;
|
16 |
import org.tela_botanica.client.modeles.projet.Projet;
|
16 |
import org.tela_botanica.client.modeles.projet.Projet;
|
17 |
import org.tela_botanica.client.modeles.projet.ProjetListe;
|
17 |
import org.tela_botanica.client.modeles.projet.ProjetListe;
|
18 |
import org.tela_botanica.client.modeles.structure.StructureListe;
|
18 |
import org.tela_botanica.client.modeles.structure.StructureListe;
|
19 |
import org.tela_botanica.client.util.Debug;
|
19 |
import org.tela_botanica.client.util.Debug;
|
20 |
import org.tela_botanica.client.util.UtilString;
|
20 |
import org.tela_botanica.client.util.UtilString;
|
21 |
import org.tela_botanica.client.vues.BarrePaginationVue;
|
21 |
import org.tela_botanica.client.vues.BarrePaginationVue;
|
22 |
|
22 |
|
23 |
import com.extjs.gxt.ui.client.Registry;
|
23 |
import com.extjs.gxt.ui.client.Registry;
|
24 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
24 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
25 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
25 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
26 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
26 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
27 |
import com.extjs.gxt.ui.client.event.Events;
|
27 |
import com.extjs.gxt.ui.client.event.Events;
|
28 |
import com.extjs.gxt.ui.client.event.Listener;
|
28 |
import com.extjs.gxt.ui.client.event.Listener;
|
29 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
29 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
30 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
30 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
31 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
31 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
32 |
import com.extjs.gxt.ui.client.store.ListStore;
|
32 |
import com.extjs.gxt.ui.client.store.ListStore;
|
33 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
33 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
34 |
import com.extjs.gxt.ui.client.widget.Info;
|
34 |
import com.extjs.gxt.ui.client.widget.Info;
|
35 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
35 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
36 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
36 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
37 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
37 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
38 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
38 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
39 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
39 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
40 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
40 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
41 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
41 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
42 |
import com.google.gwt.core.client.GWT;
|
42 |
import com.google.gwt.core.client.GWT;
|
43 |
|
43 |
|
44 |
public class ProjetListeVue extends ContentPanel implements Rafraichissable {
|
44 |
public class ProjetListeVue extends ContentPanel implements Rafraichissable {
|
45 |
|
45 |
|
46 |
private Mediateur mediateur = null;
|
46 |
private Mediateur mediateur = null;
|
47 |
private Constantes i18nC = null;
|
47 |
private Constantes i18nC = null;
|
48 |
|
48 |
|
49 |
private Grid<Projet> grille = null;
|
49 |
private Grid<Projet> grille = null;
|
50 |
private ListStore<Projet> store = null;
|
50 |
private ListStore<Projet> store = null;
|
51 |
private ColumnModel modeleDesColonnes = null;
|
51 |
private ColumnModel modeleDesColonnes = null;
|
52 |
private BarrePaginationVue pagination = null;
|
52 |
private BarrePaginationVue pagination = null;
|
53 |
|
53 |
|
54 |
private Button ajouter;
|
54 |
private Button ajouter;
|
55 |
private Button modifier;
|
55 |
private Button modifier;
|
56 |
private Button supprimer;
|
56 |
private Button supprimer;
|
57 |
|
57 |
|
58 |
public ProjetListeVue(Mediateur mediateurCourant) {
|
58 |
public ProjetListeVue(Mediateur mediateurCourant) {
|
59 |
super();
|
59 |
super();
|
60 |
mediateur = mediateurCourant;
|
60 |
mediateur = mediateurCourant;
|
61 |
i18nC = Mediateur.i18nC;
|
61 |
i18nC = Mediateur.i18nC;
|
62 |
|
62 |
|
63 |
setLayout(new FitLayout());
|
63 |
setLayout(new FitLayout());
|
64 |
setHeading("Projets");
|
64 |
setHeading("Projets");
|
65 |
|
65 |
|
66 |
ToolBar toolBar = new ToolBar();
|
66 |
ToolBar toolBar = new ToolBar();
|
67 |
ajouter = new Button(i18nC.ajouter());
|
67 |
ajouter = new Button(i18nC.ajouter());
|
68 |
ajouter.setIcon(Images.ICONES.ajouter());
|
68 |
ajouter.setIcon(Images.ICONES.ajouter());
|
69 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
69 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
70 |
public void componentSelected(ButtonEvent be) {
|
70 |
public void componentSelected(ButtonEvent be) {
|
71 |
mediateur.clicAjouterProjet();
|
71 |
mediateur.clicAjouterProjet();
|
72 |
}
|
72 |
}
|
73 |
});
|
73 |
});
|
74 |
toolBar.add(ajouter);
|
74 |
toolBar.add(ajouter);
|
75 |
|
75 |
|
76 |
modifier = new Button(i18nC.modifier());
|
76 |
modifier = new Button(i18nC.modifier());
|
77 |
modifier.setIcon(Images.ICONES.formModifier());
|
77 |
modifier.setIcon(Images.ICONES.formModifier());
|
78 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
78 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
79 |
public void componentSelected(ButtonEvent be) {
|
79 |
public void componentSelected(ButtonEvent be) {
|
80 |
mediateur.clicModifierProjet(grille.getSelectionModel().getSelectedItems());
|
80 |
mediateur.clicModifierProjet(grille.getSelectionModel().getSelectedItems());
|
81 |
}
|
81 |
}
|
82 |
});
|
82 |
});
|
83 |
toolBar.add(modifier);
|
83 |
toolBar.add(modifier);
|
84 |
|
84 |
|
85 |
supprimer = new Button(i18nC.supprimer());
|
85 |
supprimer = new Button(i18nC.supprimer());
|
86 |
supprimer.setIcon(Images.ICONES.supprimer());
|
86 |
supprimer.setIcon(Images.ICONES.supprimer());
|
87 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
87 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
88 |
public void componentSelected(ButtonEvent be) {
|
88 |
public void componentSelected(ButtonEvent be) {
|
89 |
mediateur.clicSupprimerProjet(grille.getSelectionModel().getSelectedItems());
|
89 |
mediateur.clicSupprimerProjet(grille.getSelectionModel().getSelectedItems());
|
90 |
}
|
90 |
}
|
91 |
});
|
91 |
});
|
92 |
toolBar.add(supprimer);
|
92 |
toolBar.add(supprimer);
|
93 |
|
93 |
|
94 |
setTopComponent(toolBar);
|
94 |
setTopComponent(toolBar);
|
95 |
|
95 |
|
96 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
96 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
97 |
// ATTENTION : les noms des colonnes doivent correspondre aux noms variables de la classe utilisée dans la liste
|
97 |
// ATTENTION : les noms des colonnes doivent correspondre aux noms variables de la classe utilisée dans la liste
|
98 |
colonnes.add(new ColumnConfig("id_projet", i18nC.id(), 20));
|
98 |
colonnes.add(new ColumnConfig("id_projet", i18nC.id(), 20));
|
99 |
colonnes.add(new ColumnConfig("nom", i18nC.nom(), 200));
|
99 |
colonnes.add(new ColumnConfig("nom", i18nC.nom(), 200));
|
100 |
colonnes.add(new ColumnConfig("abreviation", i18nC.projetAbreviation(), 200));
|
100 |
colonnes.add(new ColumnConfig("abreviation", i18nC.projetAbreviation(), 200));
|
101 |
colonnes.add(new ColumnConfig("resume", i18nC.projetResume(), 300));
|
101 |
colonnes.add(new ColumnConfig("resume", i18nC.projetResume(), 300));
|
102 |
colonnes.add(new ColumnConfig("url", i18nC.projetUrl(), 200));
|
102 |
colonnes.add(new ColumnConfig("url", i18nC.projetUrl(), 200));
|
103 |
colonnes.add(new ColumnConfig("mot_cles", i18nC.projetMotsCles(), 280));
|
103 |
colonnes.add(new ColumnConfig("mot_cles", i18nC.projetMotsCles(), 280));
|
104 |
|
104 |
|
105 |
modeleDesColonnes = new ColumnModel(colonnes);
|
105 |
modeleDesColonnes = new ColumnModel(colonnes);
|
106 |
|
106 |
|
107 |
GridSelectionModel<Projet> modeleDeSelection = new GridSelectionModel<Projet>();
|
107 |
GridSelectionModel<Projet> modeleDeSelection = new GridSelectionModel<Projet>();
|
108 |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
|
108 |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
|
109 |
public void selectionChanged(SelectionChangedEvent<Projet> event) {
|
109 |
public void selectionChanged(SelectionChangedEvent<Projet> event) {
|
110 |
Projet projet = (Projet) event.getSelectedItem();
|
110 |
Projet projet = (Projet) event.getSelectedItem();
|
111 |
clicListe(projet);
|
111 |
clicListe(projet);
|
112 |
}
|
112 |
}
|
113 |
});
|
113 |
});
|
114 |
|
114 |
|
115 |
store = new ListStore<Projet>();
|
115 |
store = new ListStore<Projet>();
|
116 |
store.sort("id_projet", SortDir.ASC);
|
116 |
store.sort("id_projet", SortDir.ASC);
|
117 |
|
117 |
|
118 |
grille = new Grid<Projet>(store, modeleDesColonnes);
|
118 |
grille = new Grid<Projet>(store, modeleDesColonnes);
|
119 |
grille.setWidth("100%");
|
119 |
grille.setWidth("100%");
|
120 |
grille.setAutoExpandColumn("nom");
|
120 |
grille.setAutoExpandColumn("nom");
|
121 |
grille.getView().setAutoFill(true);
|
121 |
grille.getView().setAutoFill(true);
|
122 |
grille.getView().setForceFit(true);
|
122 |
grille.getView().setForceFit(true);
|
123 |
grille.setSelectionModel(modeleDeSelection);
|
123 |
grille.setSelectionModel(modeleDeSelection);
|
124 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
124 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
125 |
@Override
|
- |
|
126 |
public void handleEvent(BaseEvent be) {
|
125 |
public void handleEvent(BaseEvent be) {
|
127 |
grille.getSelectionModel().select(0, false);
|
126 |
grille.getSelectionModel().select(0, false);
|
128 |
}
|
127 |
}
|
129 |
});
|
128 |
});
|
130 |
|
129 |
|
131 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
|
130 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
|
132 |
@Override
|
- |
|
133 |
public void handleEvent(BaseEvent be) {
|
131 |
public void handleEvent(BaseEvent be) {
|
134 |
modifier.fireEvent(Events.Select);
|
132 |
modifier.fireEvent(Events.Select);
|
135 |
}
|
133 |
}
|
136 |
});
|
134 |
});
|
137 |
add(grille);
|
135 |
add(grille);
|
138 |
|
136 |
|
139 |
// Définition de la barre de pagination
|
137 |
// Définition de la barre de pagination
|
140 |
pagination = new BarrePaginationVue(new StructureListe(), mediateur);
|
138 |
pagination = new BarrePaginationVue(new StructureListe(), mediateur);
|
141 |
setBottomComponent(pagination);
|
139 |
setBottomComponent(pagination);
|
142 |
}
|
140 |
}
|
143 |
|
141 |
|
144 |
public ListStore<Projet> getStore() {
|
142 |
public ListStore<Projet> getStore() {
|
145 |
return store;
|
143 |
return store;
|
146 |
}
|
144 |
}
|
147 |
|
145 |
|
148 |
private void clicListe(Projet projet) {
|
146 |
private void clicListe(Projet projet) {
|
149 |
mediateur.clicListeProjet(projet);
|
147 |
mediateur.clicListeProjet(projet);
|
150 |
}
|
148 |
}
|
151 |
|
149 |
|
152 |
private void gererEtatActivationBouton() {
|
150 |
private void gererEtatActivationBouton() {
|
153 |
int nbreElementDuMagazin = store.getCount();
|
151 |
int nbreElementDuMagazin = store.getCount();
|
154 |
ajouter.enable();
|
152 |
ajouter.enable();
|
155 |
if (nbreElementDuMagazin <= 0) {
|
153 |
if (nbreElementDuMagazin <= 0) {
|
156 |
supprimer.disable();
|
154 |
supprimer.disable();
|
157 |
modifier.disable();
|
155 |
modifier.disable();
|
158 |
} else if (nbreElementDuMagazin > 0) {
|
156 |
} else if (nbreElementDuMagazin > 0) {
|
159 |
modifier.enable();
|
157 |
modifier.enable();
|
160 |
if (mediateur.getUtilisateur().isIdentifie()) {
|
158 |
if (mediateur.getUtilisateur().isIdentifie()) {
|
161 |
supprimer.enable();
|
159 |
supprimer.enable();
|
162 |
}
|
160 |
}
|
163 |
}
|
161 |
}
|
164 |
}
|
162 |
}
|
165 |
|
163 |
|
166 |
public void rafraichir(Object nouvellesDonnees) {
|
164 |
public void rafraichir(Object nouvellesDonnees) {
|
167 |
if (nouvellesDonnees instanceof ProjetListe) {
|
165 |
if (nouvellesDonnees instanceof ProjetListe) {
|
168 |
ProjetListe projets = (ProjetListe) nouvellesDonnees;
|
166 |
ProjetListe projets = (ProjetListe) nouvellesDonnees;
|
169 |
pagination.setlistePaginable(projets);
|
167 |
pagination.setlistePaginable(projets);
|
170 |
pagination.rafraichir(projets.getPageTable());
|
168 |
pagination.rafraichir(projets.getPageTable());
|
171 |
|
169 |
|
172 |
if (projets != null) {
|
170 |
if (projets != null) {
|
173 |
List<Projet> projetsListe = projets.toList();
|
171 |
List<Projet> projetsListe = projets.toList();
|
174 |
store.removeAll();
|
172 |
store.removeAll();
|
175 |
if (mediateur.getProjetId() != null) {
|
173 |
if (mediateur.getProjetId() != null) {
|
176 |
String projetIdSelectionne = mediateur.getProjetId();
|
174 |
String projetIdSelectionne = mediateur.getProjetId();
|
177 |
Iterator<Projet> it = projetsListe.iterator();
|
175 |
Iterator<Projet> it = projetsListe.iterator();
|
178 |
while (it.hasNext()) {
|
176 |
while (it.hasNext()) {
|
179 |
Projet projetCourant = it.next();
|
177 |
Projet projetCourant = it.next();
|
180 |
if (projetCourant.getId().equals(projetIdSelectionne)) {
|
178 |
if (projetCourant.getId().equals(projetIdSelectionne)) {
|
181 |
store.add(projetCourant);
|
179 |
store.add(projetCourant);
|
182 |
}
|
180 |
}
|
183 |
}
|
181 |
}
|
184 |
} else {
|
182 |
} else {
|
185 |
store.add(projetsListe);
|
183 |
store.add(projetsListe);
|
186 |
}
|
184 |
}
|
187 |
mediateur.actualiserPanneauCentral();
|
185 |
mediateur.actualiserPanneauCentral();
|
188 |
}
|
186 |
}
|
189 |
} else if (nouvellesDonnees instanceof Information) {
|
187 |
} else if (nouvellesDonnees instanceof Information) {
|
190 |
Information info = (Information) nouvellesDonnees;
|
188 |
Information info = (Information) nouvellesDonnees;
|
191 |
if (info.getType().equals("maj_utilisateur")) {
|
189 |
if (info.getType().equals("maj_utilisateur")) {
|
192 |
gererEtatActivationBouton();
|
190 |
gererEtatActivationBouton();
|
193 |
} else if (info.getType().equals("suppression_projet")) {
|
191 |
} else if (info.getType().equals("suppression_projet")) {
|
194 |
String message = info.toString();
|
192 |
String message = info.toString();
|
195 |
if (info.getDonnee(0) != null) {
|
193 |
if (info.getDonnee(0) != null) {
|
196 |
message = (String) info.getDonnee(0);
|
194 |
message = (String) info.getDonnee(0);
|
197 |
}
|
195 |
}
|
198 |
String idsNonSuppr = info.getDonnee(1).toString();
|
196 |
String idsNonSuppr = info.getDonnee(1).toString();
|
199 |
if (!UtilString.isEmpty(idsNonSuppr)) {
|
197 |
if (!UtilString.isEmpty(idsNonSuppr)) {
|
200 |
message = "Les projets " + idsNonSuppr + " n'ont pas été supprimés car ils sont liés à d'autres éléments";
|
198 |
message = "Les projets " + idsNonSuppr + " n'ont pas été supprimés car ils sont liés à d'autres éléments";
|
201 |
}
|
199 |
}
|
202 |
|
200 |
|
203 |
InfoLogger.display(i18nC.projetTitreSuppression(), message, true);
|
201 |
InfoLogger.display(i18nC.projetTitreSuppression(), message, true);
|
204 |
supprimerProjetsSelectionnees(Arrays.asList(idsNonSuppr.split(",")));
|
202 |
supprimerProjetsSelectionnees(Arrays.asList(idsNonSuppr.split(",")));
|
205 |
gererEtatActivationBouton();
|
203 |
gererEtatActivationBouton();
|
206 |
}
|
204 |
}
|
207 |
} else {
|
205 |
} else {
|
208 |
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
|
206 |
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
|
209 |
}
|
207 |
}
|
210 |
layout();
|
208 |
layout();
|
211 |
}
|
209 |
}
|
212 |
|
210 |
|
213 |
public void supprimerProjetsSelectionnees(List<String> idsNonSuppr) {
|
211 |
public void supprimerProjetsSelectionnees(List<String> idsNonSuppr) {
|
214 |
List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
|
212 |
List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
|
215 |
for (Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
|
213 |
for (Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
|
216 |
Projet projetCourant = it.next();
|
214 |
Projet projetCourant = it.next();
|
217 |
if (!idsNonSuppr.contains(projetCourant.getId().toString())) {
|
215 |
if (!idsNonSuppr.contains(projetCourant.getId().toString())) {
|
218 |
grille.getStore().remove(projetCourant);
|
216 |
grille.getStore().remove(projetCourant);
|
219 |
}
|
217 |
}
|
220 |
}
|
218 |
}
|
221 |
|
219 |
|
222 |
//Mettre à jour les filtres
|
220 |
//Mettre à jour les filtres
|
223 |
mediateur.mettreFiltreAJour(grille.getStore().getModels());
|
221 |
mediateur.mettreFiltreAJour(grille.getStore().getModels());
|
224 |
layout(true);
|
222 |
layout(true);
|
225 |
}
|
223 |
}
|
226 |
}
|
224 |
}
|