Subversion Repositories eFlore/Applications.coel

Rev

Rev 882 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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