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