877 |
aurelien |
1 |
package org.tela_botanica.client.vues;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Iterator;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
|
|
|
7 |
import org.tela_botanica.client.Mediateur;
|
878 |
aurelien |
8 |
import org.tela_botanica.client.i18n.Constantes;
|
877 |
aurelien |
9 |
import org.tela_botanica.client.images.Images;
|
|
|
10 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
878 |
aurelien |
11 |
import org.tela_botanica.client.modeles.Configuration;
|
877 |
aurelien |
12 |
import org.tela_botanica.client.modeles.Information;
|
|
|
13 |
import org.tela_botanica.client.modeles.MenuApplicationId;
|
|
|
14 |
import org.tela_botanica.client.modeles.Personne;
|
|
|
15 |
import org.tela_botanica.client.modeles.PersonneListe;
|
|
|
16 |
import org.tela_botanica.client.modeles.Projet;
|
|
|
17 |
import org.tela_botanica.client.modeles.Structure;
|
|
|
18 |
import org.tela_botanica.client.modeles.StructureListe;
|
878 |
aurelien |
19 |
import org.tela_botanica.client.modeles.Valeur;
|
|
|
20 |
import org.tela_botanica.client.modeles.ValeurListe;
|
877 |
aurelien |
21 |
import org.tela_botanica.client.util.Pattern;
|
|
|
22 |
import org.tela_botanica.client.util.UtilArray;
|
|
|
23 |
|
878 |
aurelien |
24 |
import com.extjs.gxt.ui.client.Style.SortDir;
|
877 |
aurelien |
25 |
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
26 |
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
27 |
import com.extjs.gxt.ui.client.store.ListStore;
|
|
|
28 |
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
|
|
29 |
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
|
30 |
import com.extjs.gxt.ui.client.widget.MessageBox;
|
|
|
31 |
import com.extjs.gxt.ui.client.widget.button.Button;
|
|
|
32 |
import com.extjs.gxt.ui.client.widget.form.CheckBox;
|
|
|
33 |
import com.extjs.gxt.ui.client.widget.form.ComboBox;
|
|
|
34 |
import com.extjs.gxt.ui.client.widget.form.FieldSet;
|
|
|
35 |
import com.extjs.gxt.ui.client.widget.form.TextArea;
|
|
|
36 |
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
37 |
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
|
|
|
38 |
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
|
|
|
39 |
import com.extjs.gxt.ui.client.widget.layout.FormData;
|
|
|
40 |
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
|
|
41 |
import com.google.gwt.core.client.GWT;
|
878 |
aurelien |
42 |
import com.google.gwt.user.client.Window;
|
877 |
aurelien |
43 |
|
|
|
44 |
|
|
|
45 |
public class ProjetForm extends Formulaire implements Rafraichissable {
|
|
|
46 |
|
|
|
47 |
private Projet projet;
|
878 |
aurelien |
48 |
|
|
|
49 |
private String listeValeurIndexationDureeId = "dureesIndexation";
|
|
|
50 |
private int listeValeurIndexationDureeInt = 1072;
|
|
|
51 |
private String listeValeurIndexationFrequenceId = "frequencesIndexation";
|
|
|
52 |
private int listeValeurIndexationFrequenceInt = 1073;
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
private ListStore<Valeur> listeIndexationDuree = null;
|
|
|
56 |
private ListStore<Valeur> listeIndexationFrequence = null;
|
|
|
57 |
|
877 |
aurelien |
58 |
private FieldSet generalitesFieldset = null;
|
|
|
59 |
private TextField<String> nomChp = null;
|
|
|
60 |
private TextField<String> abreviationChp = null;
|
|
|
61 |
private TextField<String> descriptionChp = null;
|
|
|
62 |
private TextArea resumeChp = null;
|
|
|
63 |
private TextField<String> urlChp = null;
|
|
|
64 |
|
|
|
65 |
private FieldSet complementFieldset = null;
|
|
|
66 |
private TextField<String> motsClesChp = null;
|
|
|
67 |
private TextField<String> citationChp = null;
|
|
|
68 |
private TextField<String> licenceChp = null;
|
|
|
69 |
private CheckBox markPublicChp = null;
|
|
|
70 |
|
|
|
71 |
private FieldSet indexationFieldset = null;
|
|
|
72 |
private TextField<String> indexationHeureChp = null;
|
878 |
aurelien |
73 |
private ComboBox<Valeur> indexationDureeChp = null;
|
|
|
74 |
private ComboBox<Valeur> indexationFrequenceChp = null;
|
877 |
aurelien |
75 |
|
878 |
aurelien |
76 |
private boolean listeIndexationDureeChargee = false;
|
|
|
77 |
private boolean listeIndexationFrequenceChargee = false;
|
877 |
aurelien |
78 |
|
|
|
79 |
private boolean formulaireValideOk = false;
|
|
|
80 |
private boolean projetValideOk = false;
|
|
|
81 |
|
|
|
82 |
private Rafraichissable vueExterneARafraichirApresValidation = null;
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
public ProjetForm(Mediateur mediateurCourrant, String projetId) {
|
|
|
86 |
initialiserProjetForm(mediateurCourrant, projetId);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
public ProjetForm(Mediateur mediateurCourrant, String projetId, Rafraichissable vueARafraichirApresValidation) {
|
|
|
90 |
vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
|
|
|
91 |
initialiserProjetForm(mediateurCourrant, projetId);
|
|
|
92 |
}
|
|
|
93 |
|
878 |
aurelien |
94 |
private void initialiserProjetForm(Mediateur mediateurCourant, String projetId) {
|
877 |
aurelien |
95 |
projet = new Projet();
|
|
|
96 |
projet.setId(projetId);
|
|
|
97 |
|
|
|
98 |
String modeDeCreation = (projet.getId().isEmpty() ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
|
878 |
aurelien |
99 |
initialiserFormulaire(mediateurCourant, modeDeCreation, MenuApplicationId.PROJET);
|
877 |
aurelien |
100 |
|
|
|
101 |
panneauFormulaire.setLayout(new FlowLayout());
|
|
|
102 |
String titre = genererTitreFormulaire();
|
|
|
103 |
panneauFormulaire.setHeading(titre);
|
|
|
104 |
|
|
|
105 |
creerZoneGeneralites();
|
|
|
106 |
panneauFormulaire.add(generalitesFieldset);
|
|
|
107 |
|
|
|
108 |
creerZoneComplement();
|
|
|
109 |
panneauFormulaire.add(complementFieldset);
|
|
|
110 |
|
|
|
111 |
creerZoneIndexation();
|
|
|
112 |
panneauFormulaire.add(indexationFieldset);
|
|
|
113 |
|
|
|
114 |
if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
|
878 |
aurelien |
115 |
mediateurCourant.selectionnerProjet(this, projetId);
|
877 |
aurelien |
116 |
}
|
878 |
aurelien |
117 |
|
|
|
118 |
mediateurCourant.obtenirListeValeurEtRafraichir(this, listeValeurIndexationDureeId);
|
|
|
119 |
mediateurCourant.obtenirListeValeurEtRafraichir(this, listeValeurIndexationFrequenceId);
|
877 |
aurelien |
120 |
}
|
|
|
121 |
|
|
|
122 |
private String genererTitreFormulaire() {
|
|
|
123 |
String titre = "Ajout d'une projet";
|
|
|
124 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
878 |
aurelien |
125 |
titre = "Modification d'un projet - "+i18nC.id()+": "+projet.getId();
|
877 |
aurelien |
126 |
}
|
|
|
127 |
return titre;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
private void creerZoneGeneralites() {
|
|
|
131 |
FormLayout layout = new FormLayout();
|
|
|
132 |
layout.setLabelWidth(100);
|
|
|
133 |
|
|
|
134 |
// Fieldset Infos Générales
|
|
|
135 |
generalitesFieldset = new FieldSet();
|
|
|
136 |
generalitesFieldset.setHeading("Informations générales");
|
|
|
137 |
generalitesFieldset.setCollapsible(true);
|
|
|
138 |
generalitesFieldset.setLayout(layout);
|
|
|
139 |
|
|
|
140 |
nomChp = new TextField<String>();
|
|
|
141 |
nomChp.setName("cpu");
|
|
|
142 |
nomChp.setFieldLabel("Nom");
|
|
|
143 |
generalitesFieldset.add(nomChp, new FormData(450, 0));
|
|
|
144 |
|
|
|
145 |
abreviationChp = new TextField<String>();
|
|
|
146 |
abreviationChp.setFieldLabel("Abréviation");
|
|
|
147 |
generalitesFieldset.add(abreviationChp, new FormData(450, 0));
|
|
|
148 |
|
|
|
149 |
descriptionChp = new TextField<String>();
|
|
|
150 |
descriptionChp.setFieldLabel("Description");
|
|
|
151 |
generalitesFieldset.add(descriptionChp, new FormData(450, 0));
|
|
|
152 |
|
|
|
153 |
resumeChp = new TextArea();
|
|
|
154 |
resumeChp.setFieldLabel("Résumé");
|
|
|
155 |
generalitesFieldset.add(resumeChp, new FormData(450, 0));
|
|
|
156 |
|
|
|
157 |
urlChp = new TextField<String>();
|
|
|
158 |
urlChp.setFieldLabel("URL du projet");
|
|
|
159 |
generalitesFieldset.add(urlChp, new FormData(450, 0));
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
private void creerZoneComplement() {
|
|
|
163 |
FormLayout layout = new FormLayout();
|
|
|
164 |
layout.setLabelWidth(100);
|
|
|
165 |
|
|
|
166 |
// Fieldset Edition
|
|
|
167 |
complementFieldset = new FieldSet();
|
|
|
168 |
complementFieldset.setHeading("Informations complémentaires");
|
|
|
169 |
complementFieldset.setCollapsible(true);
|
|
|
170 |
complementFieldset.setLayout(layout);
|
|
|
171 |
|
|
|
172 |
motsClesChp = new TextField<String>();
|
|
|
173 |
motsClesChp.setFieldLabel("Mots Clés");
|
|
|
174 |
|
|
|
175 |
complementFieldset.add(motsClesChp);
|
|
|
176 |
|
|
|
177 |
citationChp = new TextField<String>();
|
|
|
178 |
citationChp.setFieldLabel("Citation");
|
|
|
179 |
|
|
|
180 |
complementFieldset.add(citationChp);
|
|
|
181 |
|
|
|
182 |
licenceChp = new TextField<String>();
|
|
|
183 |
licenceChp.setFieldLabel("Licence");
|
|
|
184 |
|
|
|
185 |
complementFieldset.add(licenceChp);
|
|
|
186 |
|
|
|
187 |
markPublicChp = new CheckBox();
|
|
|
188 |
markPublicChp.setFieldLabel("Public");
|
|
|
189 |
|
|
|
190 |
complementFieldset.add(markPublicChp);
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
private void creerZoneIndexation() {
|
|
|
194 |
FormLayout layout = new FormLayout();
|
|
|
195 |
layout.setLabelWidth(100);
|
|
|
196 |
|
|
|
197 |
// Fieldset Edition
|
|
|
198 |
indexationFieldset = new FieldSet();
|
|
|
199 |
indexationFieldset.setHeading("Indexation");
|
|
|
200 |
indexationFieldset.setCollapsible(true);
|
|
|
201 |
indexationFieldset.setLayout(layout);
|
|
|
202 |
|
|
|
203 |
indexationHeureChp = new TextField<String>();
|
878 |
aurelien |
204 |
indexationHeureChp.setFieldLabel(i18nC.projetIndexationHeure());
|
877 |
aurelien |
205 |
|
|
|
206 |
indexationFieldset.add(indexationHeureChp, new FormData(80, 0));
|
|
|
207 |
|
878 |
aurelien |
208 |
// liste 1073
|
|
|
209 |
listeIndexationFrequence = new ListStore<Valeur>();
|
|
|
210 |
indexationFrequenceChp = new ComboBox<Valeur>();
|
|
|
211 |
indexationFrequenceChp.setStore(listeIndexationFrequence);
|
|
|
212 |
indexationFrequenceChp.setDisplayField("nom");
|
|
|
213 |
indexationFrequenceChp.setEditable(false);
|
|
|
214 |
indexationFrequenceChp.setFieldLabel(i18nC.projetIndexationFrequence());
|
|
|
215 |
|
|
|
216 |
indexationFieldset.add(indexationFrequenceChp, new FormData(120, 0));
|
|
|
217 |
|
877 |
aurelien |
218 |
// liste 1072
|
878 |
aurelien |
219 |
listeIndexationDuree = new ListStore<Valeur>();
|
|
|
220 |
indexationDureeChp = new ComboBox<Valeur>();
|
|
|
221 |
indexationDureeChp.setStore(listeIndexationDuree);
|
|
|
222 |
indexationDureeChp.setDisplayField("nom");
|
|
|
223 |
indexationDureeChp.setEditable(false);
|
|
|
224 |
indexationDureeChp.setFieldLabel(i18nC.projetIndexationDuree());
|
877 |
aurelien |
225 |
|
|
|
226 |
indexationFieldset.add(indexationDureeChp, new FormData(80, 0));
|
|
|
227 |
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
public void rafraichir(Object nouvellesDonnees) {
|
|
|
231 |
if (nouvellesDonnees instanceof Projet) {
|
|
|
232 |
// Si on a reçu les details d'une projet
|
|
|
233 |
rafraichirProjet((Projet) nouvellesDonnees);
|
878 |
aurelien |
234 |
GWT.log("Un projet est arrivé : "+((Projet) nouvellesDonnees).getNom(), null);
|
877 |
aurelien |
235 |
}
|
|
|
236 |
|
878 |
aurelien |
237 |
if(nouvellesDonnees instanceof ValeurListe) {
|
|
|
238 |
ValeurListe nValeurListe = (ValeurListe)nouvellesDonnees;
|
|
|
239 |
|
|
|
240 |
if(nValeurListe.getId() == listeValeurIndexationDureeInt) {
|
|
|
241 |
for(Iterator<String> it = nValeurListe.keySet().iterator(); it.hasNext();) {
|
|
|
242 |
listeIndexationDuree.add(nValeurListe.get(it.next()));
|
|
|
243 |
listeIndexationDuree.sort("id_valeur", SortDir.ASC);
|
|
|
244 |
listeIndexationDureeChargee = true;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
if(nValeurListe.getId() == listeValeurIndexationFrequenceInt) {
|
|
|
250 |
for(Iterator<String> it = nValeurListe.keySet().iterator(); it.hasNext();) {
|
|
|
251 |
listeIndexationFrequence.add(nValeurListe.get(it.next()));
|
|
|
252 |
listeIndexationFrequence.sort("id_valeur", SortDir.ASC);
|
|
|
253 |
listeIndexationFrequenceChargee = true;
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
|
877 |
aurelien |
258 |
if (etreValide()) {
|
|
|
259 |
initialiserValidation();
|
|
|
260 |
repandreRafraichissement();
|
|
|
261 |
controlerFermetureApresRafraichissement();
|
|
|
262 |
}
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
private void rafraichirProjet(Projet proj) {
|
|
|
266 |
projet = proj;
|
|
|
267 |
peuplerFormulaire();
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
private Boolean etreValide() {
|
|
|
271 |
Boolean valide = false;
|
|
|
272 |
GWT.log("formulaire"+formulaireValideOk+" - Projet :"+projetValideOk, null);
|
|
|
273 |
if (formulaireValideOk && projetValideOk) {
|
|
|
274 |
valide = true;
|
|
|
275 |
}
|
|
|
276 |
return valide;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
private void initialiserValidation() {
|
|
|
280 |
formulaireValideOk = false;
|
|
|
281 |
projetValideOk = false;
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
private void repandreRafraichissement() {
|
|
|
285 |
if (vueExterneARafraichirApresValidation != null) {
|
878 |
aurelien |
286 |
String type = "projet_modifie";
|
877 |
aurelien |
287 |
if (mode.equals(Formulaire.MODE_AJOUTER)) {
|
878 |
aurelien |
288 |
type = "projet_ajoute";
|
877 |
aurelien |
289 |
}
|
|
|
290 |
Information info = new Information(type);
|
|
|
291 |
info.setDonnee(0, projet);
|
|
|
292 |
vueExterneARafraichirApresValidation.rafraichir(info);
|
|
|
293 |
}
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
public boolean soumettreFormulaire() {
|
|
|
297 |
formulaireValideOk = verifierFormulaire();
|
|
|
298 |
GWT.log("Form?"+formulaireValideOk, null);
|
|
|
299 |
if (formulaireValideOk) {
|
|
|
300 |
Projet projetCollecte = collecterProjet();
|
|
|
301 |
if (projetCollecte != null) {
|
|
|
302 |
GWT.log("Info collectée ? ok", null);
|
|
|
303 |
if (mode.equals(Formulaire.MODE_AJOUTER)) {
|
|
|
304 |
mediateur.ajouterProjet(this, projetCollecte);
|
|
|
305 |
} else if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
|
|
306 |
mediateur.modifierProjet(this, projetCollecte);
|
|
|
307 |
}
|
|
|
308 |
}
|
|
|
309 |
}
|
|
|
310 |
return formulaireValideOk;
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
protected boolean verifierFormulaire() {
|
|
|
314 |
boolean valide = true;
|
|
|
315 |
ArrayList<String> messages = new ArrayList<String>();
|
|
|
316 |
|
|
|
317 |
String titre = nomChp.getValue();
|
|
|
318 |
if (titre == null || titre.equals("")) {
|
|
|
319 |
messages.add("Veuillez saisir le nom du projet !");
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
String uri = urlChp.getValue();
|
|
|
323 |
if (uri != null && ! uri.isEmpty() && ! uri.matches(Pattern.url)) {
|
|
|
324 |
messages.add("L'URL saisie n'est pas valide !");
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
if (messages.size() != 0) {
|
|
|
328 |
String[] tableauDeMessages = {};
|
|
|
329 |
tableauDeMessages = messages.toArray(tableauDeMessages);
|
|
|
330 |
MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDeMessages, "<br />"), null);
|
|
|
331 |
valide = false;
|
|
|
332 |
}
|
|
|
333 |
return valide;
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
private void peuplerFormulaire() {
|
|
|
337 |
|
878 |
aurelien |
338 |
nomChp.setValue(projet.getNom());
|
|
|
339 |
abreviationChp.setValue(projet.getAbreviation());
|
|
|
340 |
descriptionChp.setValue(projet.getDescription());
|
|
|
341 |
resumeChp.setValue(projet.getResume());
|
|
|
342 |
urlChp.setValue(projet.getUrl());
|
|
|
343 |
|
|
|
344 |
motsClesChp.setValue(projet.getMotsCles());
|
|
|
345 |
citationChp.setValue(projet.getCitation());
|
|
|
346 |
licenceChp.setValue(projet.getLicence());
|
|
|
347 |
markPublicChp.setValue(Boolean.parseBoolean(projet.getMarkPublic()));
|
|
|
348 |
|
|
|
349 |
indexationHeureChp.setValue(projet.getIndexationHeure());
|
|
|
350 |
indexationFrequenceChp.select(listeIndexationFrequence.findModel(projet.getIndexationFreq()));
|
|
|
351 |
indexationDureeChp.select(listeIndexationDuree.findModel(projet.getIndexationDuree()));
|
|
|
352 |
|
|
|
353 |
doLayout(true);
|
|
|
354 |
|
877 |
aurelien |
355 |
}
|
|
|
356 |
|
|
|
357 |
private Projet collecterProjet() {
|
|
|
358 |
Projet projetARetourner = null;
|
|
|
359 |
Projet projetCollectee = (Projet) projet.cloner(new Projet());
|
|
|
360 |
|
|
|
361 |
// TODO : collecter le reste des champs
|
|
|
362 |
|
|
|
363 |
if (!projetCollectee.comparer(projet)) {
|
|
|
364 |
projetARetourner = projet = projetCollectee;
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
return projetARetourner;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
protected void reinitialiserFormulaire() {
|
|
|
371 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
|
|
372 |
mediateur.afficherFormProjet(projet.getId());
|
|
|
373 |
} else {
|
|
|
374 |
mediateur.afficherFormProjet(null);
|
|
|
375 |
}
|
|
|
376 |
}
|
|
|
377 |
|
|
|
378 |
@Override
|
|
|
379 |
protected SelectionListener<ButtonEvent> creerEcouteurValidation() {
|
|
|
380 |
SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
|
|
|
381 |
@Override
|
|
|
382 |
public void componentSelected(ButtonEvent ce) {
|
|
|
383 |
String code = ((Button) ce.getComponent()).getData("code");
|
|
|
384 |
if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
|
|
|
385 |
soumettreFormulaire();
|
|
|
386 |
clicBoutonvalidation = true;
|
|
|
387 |
} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
|
|
|
388 |
soumettreFormulaire();
|
|
|
389 |
} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
|
|
|
390 |
mediateur.clicMenu(menuIdCourant);
|
|
|
391 |
} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {
|
|
|
392 |
reinitialiserFormulaire();
|
|
|
393 |
}
|
|
|
394 |
}
|
|
|
395 |
};
|
|
|
396 |
|
|
|
397 |
return ecouteur;
|
|
|
398 |
}
|
|
|
399 |
}
|