Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
935 jpm 1
package org.tela_botanica.client.vues.projet;
877 aurelien 2
 
3
import java.util.ArrayList;
4
 
980 jpm 5
import org.tela_botanica.client.ComposantClass;
877 aurelien 6
import org.tela_botanica.client.Mediateur;
1115 jpm 7
import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;
1329 cyprien 8
import org.tela_botanica.client.composants.ChampComboBoxRechercheTempsReelPaginable;
1239 cyprien 9
import org.tela_botanica.client.composants.InfoLogger;
1329 cyprien 10
import org.tela_botanica.client.composants.pagination.ProxyValeur;
877 aurelien 11
import org.tela_botanica.client.interfaces.Rafraichissable;
12
import org.tela_botanica.client.modeles.Information;
13
import org.tela_botanica.client.modeles.MenuApplicationId;
1329 cyprien 14
import org.tela_botanica.client.modeles.Valeur;
935 jpm 15
import org.tela_botanica.client.modeles.projet.Projet;
928 jpm 16
import org.tela_botanica.client.util.Debug;
877 aurelien 17
import org.tela_botanica.client.util.Pattern;
18
import org.tela_botanica.client.util.UtilArray;
928 jpm 19
import org.tela_botanica.client.util.UtilString;
935 jpm 20
import org.tela_botanica.client.vues.Formulaire;
877 aurelien 21
 
1322 gduche 22
import com.extjs.gxt.ui.client.Style.Scroll;
1329 cyprien 23
import com.extjs.gxt.ui.client.data.ModelData;
24
import com.extjs.gxt.ui.client.data.ModelType;
1118 jpm 25
import com.extjs.gxt.ui.client.event.BaseEvent;
980 jpm 26
import com.extjs.gxt.ui.client.event.Events;
1118 jpm 27
import com.extjs.gxt.ui.client.event.Listener;
928 jpm 28
import com.extjs.gxt.ui.client.widget.Info;
877 aurelien 29
import com.extjs.gxt.ui.client.widget.MessageBox;
30
import com.extjs.gxt.ui.client.widget.form.CheckBox;
31
import com.extjs.gxt.ui.client.widget.form.FieldSet;
32
import com.extjs.gxt.ui.client.widget.form.TextArea;
33
import com.extjs.gxt.ui.client.widget.form.TextField;
34
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
35
import com.extjs.gxt.ui.client.widget.layout.FormData;
36
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
37
 
38
public class ProjetForm extends Formulaire implements Rafraichissable {
39
 
40
	private Projet projet;
878 aurelien 41
 
42
	private String listeValeurIndexationDureeId = "dureesIndexation";
43
	private String listeValeurIndexationFrequenceId = "frequencesIndexation";
887 aurelien 44
	private String listeLanguesId = "langues";
878 aurelien 45
 
877 aurelien 46
	private FieldSet generalitesFieldset = null;
47
	private TextField<String> nomChp = null;
48
	private TextField<String> abreviationChp = null;
886 aurelien 49
	private TextArea descriptionChp = null;
877 aurelien 50
	private TextArea resumeChp = null;
51
	private TextField<String> urlChp = null;
52
 
53
	private FieldSet complementFieldset = null;
54
	private TextField<String> motsClesChp = null;
55
	private TextField<String> citationChp = null;
56
	private TextField<String> licenceChp = null;
1329 cyprien 57
	private ChampComboBoxRechercheTempsReelPaginable langueChp = null;
877 aurelien 58
	private CheckBox markPublicChp = null;
59
 
60
	private FieldSet indexationFieldset = null;
61
	private TextField<String> indexationHeureChp = null;
1115 jpm 62
	private ChampComboBoxListeValeurs indexationDureeChp = null;
63
	private ChampComboBoxListeValeurs indexationFrequenceChp = null;
877 aurelien 64
 
65
	private boolean formulaireValideOk = false;
66
	private boolean projetValideOk = false;
67
 
68
	private Rafraichissable vueExterneARafraichirApresValidation = null;
69
 
70
 
71
	public ProjetForm(Mediateur mediateurCourrant, String projetId) {
72
		initialiserProjetForm(mediateurCourrant, projetId);
73
	}
74
 
75
	public ProjetForm(Mediateur mediateurCourrant, String projetId, Rafraichissable vueARafraichirApresValidation) {
76
		vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
77
		initialiserProjetForm(mediateurCourrant, projetId);
78
	}
79
 
878 aurelien 80
	private void initialiserProjetForm(Mediateur mediateurCourant, String projetId) {
877 aurelien 81
		projet = new Projet();
82
		projet.setId(projetId);
83
 
84
		String modeDeCreation = (projet.getId().isEmpty() ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
878 aurelien 85
		initialiserFormulaire(mediateurCourant, modeDeCreation, MenuApplicationId.PROJET);
877 aurelien 86
 
87
		panneauFormulaire.setLayout(new FlowLayout());
1322 gduche 88
		panneauFormulaire.setScrollMode(Scroll.AUTO);
1094 jpm 89
		genererTitreFormulaire();
877 aurelien 90
 
91
		creerZoneGeneralites();
92
		panneauFormulaire.add(generalitesFieldset);
93
 
94
		creerZoneComplement();
95
		panneauFormulaire.add(complementFieldset);
96
 
97
		creerZoneIndexation();
98
		panneauFormulaire.add(indexationFieldset);
99
 
886 aurelien 100
		creerTabIndex();
101
 
877 aurelien 102
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
1322 gduche 103
			mediateur.selectionnerProjet(this, projetId, null);
1118 jpm 104
		}
877 aurelien 105
	}
106
 
1094 jpm 107
	private void genererTitreFormulaire() {
928 jpm 108
		String titre = i18nC.projetTitreFormAjout();
877 aurelien 109
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
1094 jpm 110
			 titre = i18nC.projetTitreFormModif();
111
			 if (projet != null) {
112
				 titre += " - "+i18nC.id()+": "+projet.getId();
113
			 }
877 aurelien 114
		}
928 jpm 115
		panneauFormulaire.setHeading(titre);
877 aurelien 116
	}
117
 
118
	private void creerZoneGeneralites() {
119
		FormLayout layout = new FormLayout();
120
		layout.setLabelWidth(100);
121
 
122
		// Fieldset Infos Générales
123
		generalitesFieldset = new FieldSet();
928 jpm 124
		generalitesFieldset.setHeading(i18nC.projetTitreInfoGenerale());
877 aurelien 125
		generalitesFieldset.setCollapsible(true);
126
		generalitesFieldset.setLayout(layout);
127
 
128
		nomChp = new TextField<String>();
129
		nomChp.setName("cpu");
1118 jpm 130
		nomChp.setFieldLabel(i18nC.projetNom());
980 jpm 131
		nomChp.addStyleName(ComposantClass.OBLIGATOIRE);
132
		nomChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
877 aurelien 133
		generalitesFieldset.add(nomChp, new FormData(450, 0));
134
 
135
		abreviationChp = new TextField<String>();
1118 jpm 136
		abreviationChp.setFieldLabel(i18nC.projetAbreviation());
981 jpm 137
		abreviationChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 138
		abreviationChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
877 aurelien 139
		generalitesFieldset.add(abreviationChp, new FormData(450, 0));
140
 
886 aurelien 141
		descriptionChp = new TextArea();
1118 jpm 142
		descriptionChp.setFieldLabel(i18nC.projetDescription());
981 jpm 143
		descriptionChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 144
		descriptionChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
877 aurelien 145
		generalitesFieldset.add(descriptionChp, new FormData(450, 0));
146
 
147
		resumeChp = new TextArea();
1118 jpm 148
		resumeChp.setFieldLabel(i18nC.projetResume());
981 jpm 149
		resumeChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 150
		resumeChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
877 aurelien 151
		generalitesFieldset.add(resumeChp, new FormData(450, 0));
152
 
153
		urlChp = new TextField<String>();
1118 jpm 154
		urlChp.setFieldLabel(i18nC.projetUrl());
877 aurelien 155
		generalitesFieldset.add(urlChp, new FormData(450, 0));
156
	}
157
 
158
	private void creerZoneComplement() {
159
		FormLayout layout = new FormLayout();
160
		layout.setLabelWidth(100);
161
 
928 jpm 162
		// Fieldset Complément
877 aurelien 163
		complementFieldset = new FieldSet();
928 jpm 164
		complementFieldset.setHeading(i18nC.projetTitreComplement());
877 aurelien 165
		complementFieldset.setCollapsible(true);
166
		complementFieldset.setLayout(layout);
167
 
168
		motsClesChp = new TextField<String>();
1115 jpm 169
		motsClesChp.setFieldLabel(i18nC.projetMotsCles());
170
		complementFieldset.add(motsClesChp, new FormData(450, 0));
877 aurelien 171
 
172
		citationChp = new TextField<String>();
1115 jpm 173
		citationChp.setFieldLabel(i18nC.projetCitation());
174
		complementFieldset.add(citationChp, new FormData(450, 0));
877 aurelien 175
 
176
		licenceChp = new TextField<String>();
1115 jpm 177
		licenceChp.setFieldLabel(i18nC.projetLicence());
178
		complementFieldset.add(licenceChp, new FormData(450, 0));
877 aurelien 179
 
1329 cyprien 180
		ModelType modelTypesLangues = new ModelType();
181
		modelTypesLangues.setRoot("valeurs");
182
		modelTypesLangues.setTotalName("nbElements");
183
		modelTypesLangues.addField("cmlv_nom");
184
		modelTypesLangues.addField("cmlv_id_valeur");
185
		modelTypesLangues.addField("cmlv_abreviation");
186
		modelTypesLangues.addField("cmlv_description");
887 aurelien 187
 
1329 cyprien 188
		String displayNameLangues = "cmlv_nom";
189
		String nomListeTypes = "langues";
190
		ProxyValeur<ModelData> proxyLangues = new ProxyValeur<ModelData>(nomListeTypes);
191
 
192
		langueChp = new ChampComboBoxRechercheTempsReelPaginable(proxyLangues, modelTypesLangues, displayNameLangues);
193
		langueChp.setWidth(100,300);
194
		langueChp.getCombo().setTabIndex(tabIndex++);
195
		langueChp.getCombo().setFieldLabel(i18nC.projetLangue());
196
		langueChp.getCombo().setForceSelection(true);
197
 
198
		complementFieldset.add(langueChp, new FormData(300, 0));
199
 
877 aurelien 200
		markPublicChp = new CheckBox();
1118 jpm 201
		markPublicChp.setFieldLabel(i18nC.projetMarkPublic());
202
		markPublicChp.addListener(Events.Change, new Listener<BaseEvent>() {
203
			public void handleEvent(BaseEvent be) {
204
				if (markPublicChp.getValue()) {
205
					indexationFieldset.show();
206
				} else {
207
					indexationFieldset.hide();
208
				}
209
			}
210
		});
877 aurelien 211
		complementFieldset.add(markPublicChp);
212
	}
213
 
214
	private void creerZoneIndexation() {
215
		FormLayout layout = new FormLayout();
216
		layout.setLabelWidth(100);
217
 
928 jpm 218
		// Fieldset Indexation
877 aurelien 219
		indexationFieldset = new FieldSet();
928 jpm 220
		indexationFieldset.setHeading(i18nC.projetTitreIndexation());
877 aurelien 221
		indexationFieldset.setCollapsible(true);
222
		indexationFieldset.setLayout(layout);
1118 jpm 223
		indexationFieldset.hide();
224
		indexationFieldset.addListener(Events.Hide, new Listener<BaseEvent>() {
225
			public void handleEvent(BaseEvent be) {
226
				indexationHeureChp.clear();
227
				indexationFrequenceChp.clear();
228
				indexationDureeChp.clear();
229
			}
230
		});
877 aurelien 231
 
232
		indexationHeureChp = new TextField<String>();
878 aurelien 233
		indexationHeureChp.setFieldLabel(i18nC.projetIndexationHeure());
1115 jpm 234
		indexationHeureChp.setToolTip(i18nC.projetMessageHeureMinute());
877 aurelien 235
		indexationFieldset.add(indexationHeureChp, new FormData(80, 0));
236
 
1115 jpm 237
		indexationFrequenceChp = new ChampComboBoxListeValeurs(i18nC.projetIndexationFrequence(), listeValeurIndexationFrequenceId);
878 aurelien 238
		indexationFieldset.add(indexationFrequenceChp, new FormData(120, 0));
239
 
1115 jpm 240
		indexationDureeChp = new ChampComboBoxListeValeurs(i18nC.projetIndexationDuree(), listeValeurIndexationDureeId);
877 aurelien 241
		indexationFieldset.add(indexationDureeChp, new FormData(80, 0));
242
 
243
	}
886 aurelien 244
 
245
	private void creerTabIndex() {
887 aurelien 246
		nomChp.setTabIndex(1);
247
		abreviationChp.setTabIndex(2);
248
		descriptionChp.setTabIndex(3);
249
		resumeChp.setTabIndex(4);
250
		urlChp.setTabIndex(5);
886 aurelien 251
 
252
		motsClesChp.setTabIndex(6);
253
		citationChp.setTabIndex(7);
254
		licenceChp.setTabIndex(8);
887 aurelien 255
		langueChp.setTabIndex(9);
256
		markPublicChp.setTabIndex(10);
886 aurelien 257
 
887 aurelien 258
		indexationHeureChp.setTabIndex(11);
259
		indexationFrequenceChp.setTabIndex(12);
260
		indexationDureeChp.setTabIndex(13);
886 aurelien 261
 
262
		nomChp.focus();
263
	}
877 aurelien 264
 
265
	public void rafraichir(Object nouvellesDonnees) {
928 jpm 266
		if (nouvellesDonnees instanceof Information) {
267
			Information info = (Information) nouvellesDonnees;
268
			rafraichirInformation(info);
1115 jpm 269
		} else {
270
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
878 aurelien 271
		}
272
 
877 aurelien 273
		if (etreValide()) {
274
			initialiserValidation();
275
			repandreRafraichissement();
1239 cyprien 276
			controlerFermeture();
877 aurelien 277
		}
278
	}
279
 
928 jpm 280
	private void rafraichirInformation(Information info) {
281
		final String type = info.getType();
282
 
283
		// Gestion des problèmes
284
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
285
			Debug.log("MESSAGES:\n"+info.getMessages().toString());
286
		}
287
 
288
		// Gestion des actions
289
		if (type.equals("selection_projet")) {
290
			if (info.getDonnee(0) != null) {
291
				projet = (Projet) info.getDonnee(0);
292
			}
293
			peuplerFormulaire();
1094 jpm 294
			genererTitreFormulaire();
1102 jpm 295
		}
296
		if (type.equals("ajout_projet") || type.equals("modif_projet")) {
928 jpm 297
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
1094 jpm 298
				projetValideOk = true;
928 jpm 299
				String projetId = (String) info.getDonnee(0);
1094 jpm 300
				if (vueExterneARafraichirApresValidation != null) {
301
					projet.setId(projetId);
302
				}
928 jpm 303
			}
304
		}
305
 
306
		// Gestion des messages
307
		if (type.equals("selection_projet")) {
1239 cyprien 308
			InfoLogger.display(i18nC.projetTitreFormModif(), info.toString());
928 jpm 309
		} else if (type.equals("modif_projet")) {
1239 cyprien 310
			InfoLogger.display(i18nC.projetTitreFormModif(), info.toString());
928 jpm 311
		} else if (type.equals("ajout_projet")) {
1094 jpm 312
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
313
				String projetId = (String) info.getDonnee(0);
1239 cyprien 314
				InfoLogger.display(i18nC.projetTitreFormAjout(), "Le projet '"+projetId+"' a bien été ajouté");
1094 jpm 315
			} else {
1239 cyprien 316
				InfoLogger.display(i18nC.projetTitreFormAjout(), info.toString(), true);
928 jpm 317
			}
318
		}
877 aurelien 319
	}
928 jpm 320
 
877 aurelien 321
	private Boolean etreValide() {
322
		Boolean valide = false;
323
		if (formulaireValideOk && projetValideOk) {
324
			valide = true;
325
		}
326
		return valide;
327
	}
328
 
329
	private void initialiserValidation() {
330
		formulaireValideOk = false;
331
		projetValideOk = false;
332
	}
333
 
334
	private void repandreRafraichissement() {
335
		if (vueExterneARafraichirApresValidation != null) {
878 aurelien 336
			String type = "projet_modifie";
877 aurelien 337
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
878 aurelien 338
				type = "projet_ajoute";
877 aurelien 339
			}
340
			Information info = new Information(type);
341
			info.setDonnee(0, projet);
342
			vueExterneARafraichirApresValidation.rafraichir(info);
343
		}
344
	}
345
 
346
	public boolean soumettreFormulaire() {
347
		formulaireValideOk = verifierFormulaire();
348
		if (formulaireValideOk) {
349
			Projet projetCollecte = collecterProjet();
350
			if (projetCollecte != null) {
351
				if (mode.equals(Formulaire.MODE_AJOUTER)) {
352
					mediateur.ajouterProjet(this, projetCollecte);
353
				} else if (mode.equals(Formulaire.MODE_MODIFIER)) {
354
					mediateur.modifierProjet(this, projetCollecte);
355
				}
356
			}
357
		}
358
		return formulaireValideOk;
359
	}
360
 
934 jpm 361
	public boolean verifierFormulaire() {
877 aurelien 362
		boolean valide = true;
363
		ArrayList<String> messages = new ArrayList<String>();
364
 
365
		String titre = nomChp.getValue();
366
		if (titre == null || titre.equals("")) {
1115 jpm 367
			messages.add(i18nC.projetMessageNom());
877 aurelien 368
		}
369
 
886 aurelien 370
		String abr = abreviationChp.getValue();
1115 jpm 371
		if (abr == null || abr.equals(i18nC.projetMessageAbreviation())) {
372
			messages.add(i18nC.projetMessageAbreviation());
886 aurelien 373
		}
374
 
375
		String desc = descriptionChp.getValue();
1115 jpm 376
		if (desc == null || desc.equals(i18nC.projetMessageDescription())) {
377
			messages.add(i18nC.projetDescription());
886 aurelien 378
		}
379
 
380
		String resume = resumeChp.getValue();
1115 jpm 381
		if (resume == null || resume.equals(i18nC.projetMessageResume())) {
382
			messages.add(i18nC.projetMessageResume());
886 aurelien 383
		}
384
 
877 aurelien 385
		String uri = urlChp.getValue();
886 aurelien 386
		if (uri != null && ! uri.trim().isEmpty() && ! uri.matches(Pattern.url)) {
1115 jpm 387
			messages.add(i18nC.messageUrlNonValide());
877 aurelien 388
		}
389
 
1118 jpm 390
		if (markPublicChp.getValue()) {
391
			String heure = indexationHeureChp.getValue();
392
			if (!UtilString.isEmpty(heure) && !heure.matches(Pattern.heureMinute)) {
1115 jpm 393
				messages.add(i18nC.projetMessageHeureMinute());
887 aurelien 394
			}
886 aurelien 395
		}
396
 
877 aurelien 397
		if (messages.size() != 0) {
398
			String[] tableauDeMessages = {};
399
			tableauDeMessages = messages.toArray(tableauDeMessages);
1115 jpm 400
			MessageBox.alert(i18nC.erreurSaisieTitre(), UtilArray.implode(tableauDeMessages, "<br />"), null);
877 aurelien 401
			valide = false;
402
		}
403
		return valide;
404
	}
405
 
406
	private void peuplerFormulaire() {
878 aurelien 407
		nomChp.setValue(projet.getNom());
408
		abreviationChp.setValue(projet.getAbreviation());
409
		descriptionChp.setValue(projet.getDescription());
410
		resumeChp.setValue(projet.getResume());
411
		urlChp.setValue(projet.getUrl());
412
 
413
		motsClesChp.setValue(projet.getMotsCles());
414
		citationChp.setValue(projet.getCitation());
415
		licenceChp.setValue(projet.getLicence());
1329 cyprien 416
		if (projet.getLangue().matches("[0-9]+")) {
417
			langueChp.getCombo().setValue(langueChp.getStore().findModel("cmlv_id_valeur", projet.getLangue()));
418
		} else {
419
			langueChp.getCombo().setRawValue(projet.getLangue());
420
		}
924 jpm 421
		if (projet.getMarkPublic().equals("1")) {
887 aurelien 422
			markPublicChp.setValue(true);
1118 jpm 423
			String[] heureTab = projet.getIndexationHeure().split(":");
424
			if (heureTab.length > 1) {
425
				String heure = heureTab[0]+":"+heureTab[1];
426
				if (heure.matches(Pattern.heureMinute)) {
427
					indexationHeureChp.setValue(heure);
428
				}
429
			}
430
			indexationFrequenceChp.peupler(projet.getIndexationFreq());
431
			indexationDureeChp.peupler(projet.getIndexationDuree());
887 aurelien 432
		} else {
433
			markPublicChp.setValue(false);
434
		}
878 aurelien 435
 
436
		doLayout(true);
877 aurelien 437
	}
438
 
439
	private Projet collecterProjet() {
887 aurelien 440
		Projet projetCollecte = (Projet) projet.cloner(new Projet());
877 aurelien 441
 
928 jpm 442
		projetCollecte.setNom(nomChp.getValue());
443
		projetCollecte.setAbreviation(abreviationChp.getValue());
444
		projetCollecte.setDescription(descriptionChp.getValue());
445
		projetCollecte.setResume(resumeChp.getValue());
446
		projetCollecte.setUrl(urlChp.getValue());
877 aurelien 447
 
928 jpm 448
		projetCollecte.setMotsCles(motsClesChp.getValue());
449
		projetCollecte.setCitation(citationChp.getValue());
450
		projetCollecte.setLicence(licenceChp.getValue());
1329 cyprien 451
		if (langueChp.getValeur() != null) {
452
			Debug.log("langueChp.getValeur()="+langueChp.getValeur());
453
			Valeur valeur = new Valeur(langueChp.getValeur());
454
			projetCollecte.setLangue(valeur.getId());
455
		} else {
456
			projetCollecte.setLangue("");
457
		}
928 jpm 458
		String markPublic = (markPublicChp.getValue()) ? "1" : "0";
459
		projetCollecte.setMarkPublic(markPublic);
887 aurelien 460
 
928 jpm 461
		projetCollecte.setIndexationHeure(indexationHeureChp.getValue());
1115 jpm 462
		projetCollecte.setIndexationFreq(indexationFrequenceChp.getValeur());
463
		projetCollecte.setIndexationDuree(indexationDureeChp.getValeur());
928 jpm 464
 
465
		Projet projetARetourner = null;
887 aurelien 466
		if (!projetCollecte.comparer(projet)) {
467
			projetARetourner = projet = projetCollecte;
928 jpm 468
			Debug.log(projetARetourner.toString());
887 aurelien 469
		}
877 aurelien 470
		return projetARetourner;
471
	}
472
 
934 jpm 473
	public void reinitialiserFormulaire() {
877 aurelien 474
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
475
			mediateur.afficherFormProjet(projet.getId());
476
		} else {
477
			mediateur.afficherFormProjet(null);
478
		}
479
	}
908 aurelien 480
 
877 aurelien 481
}