Subversion Repositories eFlore/Applications.coel

Rev

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