Subversion Repositories eFlore/Applications.coel

Rev

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