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