Subversion Repositories eFlore/Applications.coel

Rev

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