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