935 |
jpm |
1 |
package org.tela_botanica.client.vues.projet;
|
834 |
aurelien |
2 |
|
1644 |
aurelien |
3 |
import java.text.ParseException;
|
834 |
aurelien |
4 |
import java.util.ArrayList;
|
1080 |
gduche |
5 |
import java.util.Arrays;
|
1644 |
aurelien |
6 |
import java.util.Comparator;
|
834 |
aurelien |
7 |
import java.util.Iterator;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
|
|
|
10 |
import org.tela_botanica.client.Mediateur;
|
|
|
11 |
import org.tela_botanica.client.RegistreId;
|
1633 |
aurelien |
12 |
import org.tela_botanica.client.composants.ChampFiltreRecherche;
|
1239 |
cyprien |
13 |
import org.tela_botanica.client.composants.InfoLogger;
|
834 |
aurelien |
14 |
import org.tela_botanica.client.i18n.Constantes;
|
|
|
15 |
import org.tela_botanica.client.images.Images;
|
|
|
16 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
17 |
import org.tela_botanica.client.modeles.Information;
|
|
|
18 |
import org.tela_botanica.client.modeles.Utilisateur;
|
935 |
jpm |
19 |
import org.tela_botanica.client.modeles.projet.Projet;
|
|
|
20 |
import org.tela_botanica.client.modeles.projet.ProjetListe;
|
1613 |
aurelien |
21 |
import org.tela_botanica.client.modeles.publication.Publication;
|
1045 |
gduche |
22 |
import org.tela_botanica.client.modeles.structure.StructureListe;
|
926 |
jpm |
23 |
import org.tela_botanica.client.util.Debug;
|
1080 |
gduche |
24 |
import org.tela_botanica.client.util.UtilString;
|
1045 |
gduche |
25 |
import org.tela_botanica.client.vues.BarrePaginationVue;
|
834 |
aurelien |
26 |
|
|
|
27 |
import com.extjs.gxt.ui.client.Registry;
|
|
|
28 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
|
|
29 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
|
|
30 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
31 |
import com.extjs.gxt.ui.client.event.Events;
|
|
|
32 |
import com.extjs.gxt.ui.client.event.Listener;
|
|
|
33 |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
|
34 |
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|
|
35 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
36 |
import com.extjs.gxt.ui.client.store.ListStore;
|
1644 |
aurelien |
37 |
import com.extjs.gxt.ui.client.store.StoreSorter;
|
834 |
aurelien |
38 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
931 |
jpm |
39 |
import com.extjs.gxt.ui.client.widget.Info;
|
834 |
aurelien |
40 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
|
|
41 |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
|
42 |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
|
43 |
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
|
44 |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
|
|
|
45 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
|
46 |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
|
|
47 |
import com.google.gwt.core.client.GWT;
|
1613 |
aurelien |
48 |
import com.google.gwt.user.client.Window;
|
834 |
aurelien |
49 |
|
|
|
50 |
public class ProjetListeVue extends ContentPanel implements Rafraichissable {
|
|
|
51 |
|
|
|
52 |
private Mediateur mediateur = null;
|
|
|
53 |
private Constantes i18nC = null;
|
|
|
54 |
|
|
|
55 |
private Grid<Projet> grille = null;
|
|
|
56 |
private ListStore<Projet> store = null;
|
|
|
57 |
private ColumnModel modeleDesColonnes = null;
|
1633 |
aurelien |
58 |
|
|
|
59 |
private ChampFiltreRecherche champFiltreRecherche = null;
|
1045 |
gduche |
60 |
private BarrePaginationVue pagination = null;
|
|
|
61 |
|
834 |
aurelien |
62 |
private Button ajouter;
|
|
|
63 |
private Button modifier;
|
|
|
64 |
private Button supprimer;
|
|
|
65 |
|
1613 |
aurelien |
66 |
private int indexElementSelectionne = 0;
|
|
|
67 |
private Projet projetSelectionne = null;
|
|
|
68 |
|
834 |
aurelien |
69 |
public ProjetListeVue(Mediateur mediateurCourant) {
|
|
|
70 |
super();
|
|
|
71 |
mediateur = mediateurCourant;
|
|
|
72 |
i18nC = Mediateur.i18nC;
|
|
|
73 |
|
|
|
74 |
setLayout(new FitLayout());
|
|
|
75 |
setHeading("Projets");
|
|
|
76 |
|
|
|
77 |
ToolBar toolBar = new ToolBar();
|
|
|
78 |
ajouter = new Button(i18nC.ajouter());
|
|
|
79 |
ajouter.setIcon(Images.ICONES.ajouter());
|
|
|
80 |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
81 |
public void componentSelected(ButtonEvent be) {
|
|
|
82 |
mediateur.clicAjouterProjet();
|
|
|
83 |
}
|
|
|
84 |
});
|
1630 |
aurelien |
85 |
ajouter.setToolTip(i18nC.indicationCreerUneFiche()+" "+i18nC.projetSingulier());
|
834 |
aurelien |
86 |
toolBar.add(ajouter);
|
|
|
87 |
|
|
|
88 |
modifier = new Button(i18nC.modifier());
|
|
|
89 |
modifier.setIcon(Images.ICONES.formModifier());
|
|
|
90 |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
91 |
public void componentSelected(ButtonEvent be) {
|
924 |
jpm |
92 |
mediateur.clicModifierProjet(grille.getSelectionModel().getSelectedItems());
|
1613 |
aurelien |
93 |
indexElementSelectionne = store.indexOf(grille.getSelectionModel().getSelectedItem());
|
834 |
aurelien |
94 |
}
|
|
|
95 |
});
|
1630 |
aurelien |
96 |
modifier.setToolTip(i18nC.indicationModifierUneFiche());
|
924 |
jpm |
97 |
toolBar.add(modifier);
|
834 |
aurelien |
98 |
|
|
|
99 |
supprimer = new Button(i18nC.supprimer());
|
|
|
100 |
supprimer.setIcon(Images.ICONES.supprimer());
|
|
|
101 |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
102 |
public void componentSelected(ButtonEvent be) {
|
|
|
103 |
mediateur.clicSupprimerProjet(grille.getSelectionModel().getSelectedItems());
|
|
|
104 |
}
|
|
|
105 |
});
|
1630 |
aurelien |
106 |
supprimer.setToolTip(i18nC.indicationSupprimerUneFiche());
|
924 |
jpm |
107 |
toolBar.add(supprimer);
|
834 |
aurelien |
108 |
|
|
|
109 |
setTopComponent(toolBar);
|
|
|
110 |
|
|
|
111 |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
|
|
|
112 |
// ATTENTION : les noms des colonnes doivent correspondre aux noms variables de la classe utilisée dans la liste
|
877 |
aurelien |
113 |
colonnes.add(new ColumnConfig("id_projet", i18nC.id(), 20));
|
834 |
aurelien |
114 |
colonnes.add(new ColumnConfig("nom", i18nC.nom(), 200));
|
|
|
115 |
colonnes.add(new ColumnConfig("abreviation", i18nC.projetAbreviation(), 200));
|
877 |
aurelien |
116 |
colonnes.add(new ColumnConfig("resume", i18nC.projetResume(), 300));
|
|
|
117 |
colonnes.add(new ColumnConfig("url", i18nC.projetUrl(), 200));
|
928 |
jpm |
118 |
colonnes.add(new ColumnConfig("mot_cles", i18nC.projetMotsCles(), 280));
|
834 |
aurelien |
119 |
|
|
|
120 |
modeleDesColonnes = new ColumnModel(colonnes);
|
|
|
121 |
|
|
|
122 |
GridSelectionModel<Projet> modeleDeSelection = new GridSelectionModel<Projet>();
|
|
|
123 |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
|
|
|
124 |
public void selectionChanged(SelectionChangedEvent<Projet> event) {
|
1613 |
aurelien |
125 |
projetSelectionne = (Projet) event.getSelectedItem();
|
|
|
126 |
clicListe(projetSelectionne);
|
834 |
aurelien |
127 |
}
|
|
|
128 |
});
|
|
|
129 |
|
|
|
130 |
store = new ListStore<Projet>();
|
1644 |
aurelien |
131 |
Comparator<Object> compStp = new Comparator<Object>() {
|
|
|
132 |
@Override
|
|
|
133 |
public int compare(Object o1, Object o2) {
|
|
|
134 |
return comparerNaturellementChampProjet(o1,o2);
|
|
|
135 |
}
|
|
|
136 |
};
|
|
|
137 |
StoreSorter<Projet> stp = new StoreSorter<Projet>(compStp);
|
|
|
138 |
store.setStoreSorter(stp);
|
926 |
jpm |
139 |
store.sort("id_projet", SortDir.ASC);
|
834 |
aurelien |
140 |
|
|
|
141 |
grille = new Grid<Projet>(store, modeleDesColonnes);
|
|
|
142 |
grille.setWidth("100%");
|
924 |
jpm |
143 |
grille.setAutoExpandColumn("nom");
|
834 |
aurelien |
144 |
grille.getView().setAutoFill(true);
|
|
|
145 |
grille.getView().setForceFit(true);
|
|
|
146 |
grille.setSelectionModel(modeleDeSelection);
|
|
|
147 |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
|
|
|
148 |
public void handleEvent(BaseEvent be) {
|
|
|
149 |
grille.getSelectionModel().select(0, false);
|
|
|
150 |
}
|
|
|
151 |
});
|
|
|
152 |
|
|
|
153 |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
|
|
|
154 |
public void handleEvent(BaseEvent be) {
|
|
|
155 |
modifier.fireEvent(Events.Select);
|
|
|
156 |
}
|
|
|
157 |
});
|
|
|
158 |
add(grille);
|
1045 |
gduche |
159 |
|
1633 |
aurelien |
160 |
ProjetListe projetListe = new ProjetListe();
|
|
|
161 |
champFiltreRecherche = new ChampFiltreRecherche(mediateurCourant, toolBar, projetListe);
|
1045 |
gduche |
162 |
// Définition de la barre de pagination
|
1633 |
aurelien |
163 |
pagination = new BarrePaginationVue(projetListe, mediateur);
|
1045 |
gduche |
164 |
setBottomComponent(pagination);
|
834 |
aurelien |
165 |
}
|
|
|
166 |
|
1644 |
aurelien |
167 |
private int comparerNaturellementChampProjet(Object o1, Object o2) {
|
|
|
168 |
int compare = 0;
|
|
|
169 |
String s1 = (String)o1;
|
|
|
170 |
String s2 = (String)o2;
|
|
|
171 |
try {
|
|
|
172 |
Integer i1 = Integer.parseInt(s1);
|
|
|
173 |
Integer i2 = Integer.parseInt(s2);
|
|
|
174 |
compare = i1.compareTo(i2);
|
|
|
175 |
} catch (NumberFormatException e) {
|
|
|
176 |
compare = s1.compareTo(s2);
|
|
|
177 |
}
|
|
|
178 |
return compare;
|
|
|
179 |
}
|
|
|
180 |
|
834 |
aurelien |
181 |
public ListStore<Projet> getStore() {
|
|
|
182 |
return store;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
private void clicListe(Projet projet) {
|
|
|
186 |
mediateur.clicListeProjet(projet);
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
private void gererEtatActivationBouton() {
|
|
|
190 |
int nbreElementDuMagazin = store.getCount();
|
|
|
191 |
ajouter.enable();
|
1074 |
jpm |
192 |
if (nbreElementDuMagazin <= 0) {
|
834 |
aurelien |
193 |
supprimer.disable();
|
|
|
194 |
modifier.disable();
|
1074 |
jpm |
195 |
} else if (nbreElementDuMagazin > 0) {
|
|
|
196 |
modifier.enable();
|
|
|
197 |
if (mediateur.getUtilisateur().isIdentifie()) {
|
834 |
aurelien |
198 |
supprimer.enable();
|
|
|
199 |
}
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
|
851 |
gduche |
203 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
204 |
if (nouvellesDonnees instanceof ProjetListe) {
|
|
|
205 |
ProjetListe projets = (ProjetListe) nouvellesDonnees;
|
1633 |
aurelien |
206 |
champFiltreRecherche.setListePaginable(projets);
|
1045 |
gduche |
207 |
pagination.setlistePaginable(projets);
|
|
|
208 |
pagination.rafraichir(projets.getPageTable());
|
|
|
209 |
|
834 |
aurelien |
210 |
if (projets != null) {
|
928 |
jpm |
211 |
List<Projet> projetsListe = projets.toList();
|
834 |
aurelien |
212 |
store.removeAll();
|
928 |
jpm |
213 |
if (mediateur.getProjetId() != null) {
|
|
|
214 |
String projetIdSelectionne = mediateur.getProjetId();
|
|
|
215 |
Iterator<Projet> it = projetsListe.iterator();
|
|
|
216 |
while (it.hasNext()) {
|
|
|
217 |
Projet projetCourant = it.next();
|
|
|
218 |
if (projetCourant.getId().equals(projetIdSelectionne)) {
|
|
|
219 |
store.add(projetCourant);
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
} else {
|
|
|
223 |
store.add(projetsListe);
|
|
|
224 |
}
|
924 |
jpm |
225 |
mediateur.actualiserPanneauCentral();
|
834 |
aurelien |
226 |
}
|
851 |
gduche |
227 |
} else if (nouvellesDonnees instanceof Information) {
|
|
|
228 |
Information info = (Information) nouvellesDonnees;
|
834 |
aurelien |
229 |
if (info.getType().equals("maj_utilisateur")) {
|
|
|
230 |
gererEtatActivationBouton();
|
1613 |
aurelien |
231 |
} else if (info.getType().equals("projet_modifie")) {
|
|
|
232 |
if(projetSelectionne != null) {
|
|
|
233 |
store.remove(indexElementSelectionne);
|
|
|
234 |
projetSelectionne = null;
|
|
|
235 |
}
|
|
|
236 |
Projet projetModifie = (Projet)info.getDonnee(0);
|
|
|
237 |
// au cas ou le bouton appliquer aurait été cliqué avant de valider
|
|
|
238 |
store.remove(projetModifie);
|
|
|
239 |
store.insert(projetModifie, indexElementSelectionne);
|
|
|
240 |
grille.repaint();
|
|
|
241 |
grille.getSelectionModel().select(indexElementSelectionne, true);
|
|
|
242 |
clicListe(projetModifie);
|
924 |
jpm |
243 |
} else if (info.getType().equals("suppression_projet")) {
|
931 |
jpm |
244 |
String message = info.toString();
|
|
|
245 |
if (info.getDonnee(0) != null) {
|
|
|
246 |
message = (String) info.getDonnee(0);
|
|
|
247 |
}
|
1080 |
gduche |
248 |
String idsNonSuppr = info.getDonnee(1).toString();
|
|
|
249 |
if (!UtilString.isEmpty(idsNonSuppr)) {
|
|
|
250 |
message = "Les projets " + idsNonSuppr + " n'ont pas été supprimés car ils sont liés à d'autres éléments";
|
|
|
251 |
}
|
|
|
252 |
|
1239 |
cyprien |
253 |
InfoLogger.display(i18nC.projetTitreSuppression(), message, true);
|
1080 |
gduche |
254 |
supprimerProjetsSelectionnees(Arrays.asList(idsNonSuppr.split(",")));
|
931 |
jpm |
255 |
gererEtatActivationBouton();
|
834 |
aurelien |
256 |
}
|
|
|
257 |
} else {
|
1117 |
jpm |
258 |
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
|
834 |
aurelien |
259 |
}
|
1117 |
jpm |
260 |
layout();
|
834 |
aurelien |
261 |
}
|
|
|
262 |
|
1117 |
jpm |
263 |
public void supprimerProjetsSelectionnees(List<String> idsNonSuppr) {
|
834 |
aurelien |
264 |
List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
|
1117 |
jpm |
265 |
for (Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
|
1080 |
gduche |
266 |
Projet projetCourant = it.next();
|
|
|
267 |
if (!idsNonSuppr.contains(projetCourant.getId().toString())) {
|
|
|
268 |
grille.getStore().remove(projetCourant);
|
|
|
269 |
}
|
834 |
aurelien |
270 |
}
|
1088 |
gduche |
271 |
|
|
|
272 |
//Mettre à jour les filtres
|
|
|
273 |
mediateur.mettreFiltreAJour(grille.getStore().getModels());
|
834 |
aurelien |
274 |
layout(true);
|
|
|
275 |
}
|
1117 |
jpm |
276 |
}
|