Subversion Repositories eFlore/Applications.coel

Rev

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