Subversion Repositories eFlore/Applications.coel

Rev

Rev 934 | Rev 973 | 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.personne;
127 gduche 2
 
283 gduche 3
import java.util.ArrayList;
352 gduche 4
import java.util.Collection;
376 gduche 5
import java.util.Date;
276 gduche 6
import java.util.HashMap;
283 gduche 7
import java.util.Iterator;
352 gduche 8
import java.util.LinkedList;
283 gduche 9
import java.util.List;
276 gduche 10
 
11
import org.tela_botanica.client.ComposantClass;
12
import org.tela_botanica.client.Mediateur;
13
import org.tela_botanica.client.RegistreId;
692 gduche 14
import org.tela_botanica.client.composants.ChampMultiValeurs;
701 gduche 15
import org.tela_botanica.client.composants.ChampMultiValeursImage;
722 gduche 16
import org.tela_botanica.client.composants.ChampMultiValeursMultiTypes;
907 jpm 17
import org.tela_botanica.client.configuration.Configuration;
519 gduche 18
import org.tela_botanica.client.images.Images;
127 gduche 19
import org.tela_botanica.client.interfaces.Rafraichissable;
293 gduche 20
 
352 gduche 21
import org.tela_botanica.client.modeles.Information;
850 gduche 22
import org.tela_botanica.client.modeles.MenuApplicationId;
280 gduche 23
import org.tela_botanica.client.modeles.Valeur;
283 gduche 24
import org.tela_botanica.client.modeles.ValeurListe;
935 jpm 25
import org.tela_botanica.client.modeles.personne.Personne;
26
import org.tela_botanica.client.modeles.personne.PersonneListe;
27
import org.tela_botanica.client.modeles.projet.Projet;
28
import org.tela_botanica.client.modeles.projet.ProjetListe;
729 jp_milcent 29
import org.tela_botanica.client.util.Pattern;
622 gduche 30
import org.tela_botanica.client.util.UtilString;
935 jpm 31
import org.tela_botanica.client.vues.Formulaire;
127 gduche 32
 
488 gduche 33
import com.extjs.gxt.ui.client.event.Events;
276 gduche 34
import com.extjs.gxt.ui.client.Registry;
519 gduche 35
import com.extjs.gxt.ui.client.Style.IconAlign;
283 gduche 36
import com.extjs.gxt.ui.client.Style.Scroll;
821 gduche 37
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
386 gduche 38
 
376 gduche 39
import com.extjs.gxt.ui.client.binding.FormBinding;
386 gduche 40
 
488 gduche 41
import com.extjs.gxt.ui.client.event.ButtonEvent;
276 gduche 42
import com.extjs.gxt.ui.client.event.ComponentEvent;
43
import com.extjs.gxt.ui.client.event.KeyListener;
446 gduche 44
import com.extjs.gxt.ui.client.event.Listener;
280 gduche 45
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
46
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 47
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 48
import com.extjs.gxt.ui.client.store.ListStore;
127 gduche 49
import com.extjs.gxt.ui.client.widget.LayoutContainer;
319 gduche 50
import com.extjs.gxt.ui.client.widget.MessageBox;
338 gduche 51
 
386 gduche 52
import com.extjs.gxt.ui.client.widget.Info;
276 gduche 53
import com.extjs.gxt.ui.client.widget.TabItem;
54
import com.extjs.gxt.ui.client.widget.TabPanel;
283 gduche 55
 
356 gduche 56
import com.extjs.gxt.ui.client.widget.button.Button;
57
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
280 gduche 58
import com.extjs.gxt.ui.client.widget.form.ComboBox;
59
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 60
import com.extjs.gxt.ui.client.widget.form.FieldSet;
61
import com.extjs.gxt.ui.client.widget.form.LabelField;
446 gduche 62
import com.extjs.gxt.ui.client.widget.form.Radio;
63
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
286 gduche 64
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 65
import com.extjs.gxt.ui.client.widget.form.TextField;
456 gduche 66
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
850 gduche 67
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
276 gduche 68
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
69
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
319 gduche 70
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 71
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
356 gduche 72
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
821 gduche 73
import com.extjs.gxt.ui.client.widget.layout.TableData;
74
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
386 gduche 75
import com.google.gwt.core.client.GWT;
339 gduche 76
import com.google.gwt.i18n.client.DateTimeFormat;
933 gduche 77
import com.google.gwt.user.client.Window;
276 gduche 78
import com.google.gwt.user.client.ui.Widget;
127 gduche 79
 
850 gduche 80
public class PersonneForm extends Formulaire implements Rafraichissable {
127 gduche 81
 
730 jp_milcent 82
	// VARIABLES
276 gduche 83
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
283 gduche 84
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
376 gduche 85
	private Personne personneSelectionnee, personneSauvegarde = null;
276 gduche 86
 
657 gduche 87
	//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite
88
	private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();
89
	private HashMap<String, Widget>hmAdresse = new HashMap<String, Widget>();
90
	private HashMap<String, Widget>hmInfosNat = new HashMap<String, Widget>();
730 jp_milcent 91
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
829 gduche 92
	private FormData fd100 = new FormData("95%");
657 gduche 93
 
668 gduche 94
	private Button enregistrer, enregistrerEtRevenir;
95
 
875 jpm 96
	private Personne personne = null;
97
	private String personneId = null;
376 gduche 98
	private FormBinding binding = null;
99
 
730 jp_milcent 100
	// CONSTRUCTEUR
915 jpm 101
	public PersonneForm(Mediateur mediateurCourrant, String personneId) {
875 jpm 102
		initialiserPersonneForm(mediateurCourrant, personneId);
103
	}
446 gduche 104
 
875 jpm 105
	public PersonneForm(Mediateur mediateurCourrant, String personneId, Rafraichissable vueARafraichirApresValidation) {
106
		vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
107
		initialiserPersonneForm(mediateurCourrant, personneId);
108
	}
850 gduche 109
 
875 jpm 110
	private void initialiserPersonneForm(Mediateur mediateurCourrant, String personneIdCourrant) {
111
		personne = new Personne();
112
		personne.setId(personneIdCourrant);
113
		personneId = personneIdCourrant;
850 gduche 114
 
884 jpm 115
		String modeDeCreation = (UtilString.isEmpty(personneId) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
875 jpm 116
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.PERSONNE);
117
 
386 gduche 118
		initialiserComposants();
875 jpm 119
		genererTitreFormulaire();
850 gduche 120
 
875 jpm 121
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
122
			mediateur.selectionnerPersonne(this, personne, null);
850 gduche 123
		}
352 gduche 124
	}
125
 
875 jpm 126
	private void genererTitreFormulaire() {
127
		String titre = i18nC.personneModeAjout();
128
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
129
			 titre = i18nC.personneModeModifier()+" - "+i18nC.id()+": "+personneId;
130
		}
131
		panneauFormulaire.setHeading(titre);
132
	}
133
 
386 gduche 134
	public void initialiserComposants()	{
376 gduche 135
		personneSelectionnee = new Personne();
136
		personneSauvegarde = new Personne();
137
 
276 gduche 138
		initialiserOnglets();
139
 
140
		creerComposantsIdentite();
293 gduche 141
		creerComposantsAdresse();
821 gduche 142
		creerComposantsInfosNat();
338 gduche 143
 
376 gduche 144
		binderPersonne(personneSelectionnee);
276 gduche 145
	}
146
 
147
	/**
148
	 * Crée les onglets identité, adresse et informations naturaliste
149
	 *
150
	 * */
151
	public void initialiserOnglets()	{
152
		//TabPanel
153
		TabPanel formulaireOnglets = new TabPanel();
154
 
155
		//Tab 1 : identite
875 jpm 156
		tiIdentite = new TabItem(i18nC.personneIdentite());
276 gduche 157
		tiIdentite.setLayout(new FormLayout());
283 gduche 158
		tiIdentite.setScrollMode(Scroll.AUTO);
446 gduche 159
 
276 gduche 160
		formulaireOnglets.add(tiIdentite);
293 gduche 161
		hmIdentite.put("tiIdentite", tiIdentite);
276 gduche 162
 
163
		//Tab 2 : Adresse
875 jpm 164
		tiAdresses = new TabItem(i18nC.adresse());
304 gduche 165
		tiAdresses.setLayout(new FormLayout());
283 gduche 166
		tiAdresses.setScrollMode(Scroll.AUTO);
276 gduche 167
		formulaireOnglets.add(tiAdresses);
168
 
169
		//Tab 3 : Infos Naturalistes
875 jpm 170
		tiInfosNat = new TabItem(i18nC.personneInfoNat());
276 gduche 171
		tiInfosNat.setLayout(new FormLayout());
283 gduche 172
		tiInfosNat.setScrollMode(Scroll.AUTO);
446 gduche 173
 
276 gduche 174
		formulaireOnglets.add(tiInfosNat);
850 gduche 175
		getFormulaire().add(formulaireOnglets);
276 gduche 176
	}
177
 
178
	/**
179
	 * Crée les widgets pour l'onglet identité
180
	 *
181
	 * */
182
 
183
 
184
	public void creerComposantsIdentite()	{
676 gduche 185
		// Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite
186
		LayoutContainer left = new LayoutContainer();
187
		left.setLayout(new FormLayout());
829 gduche 188
		left.setStyleAttribute("padding", "15px");
189
 
676 gduche 190
		LayoutContainer right = new LayoutContainer();
191
		right.setLayout(new FormLayout());
829 gduche 192
		right.setStyleAttribute("padding", "15px");
456 gduche 193
 
676 gduche 194
		LayoutContainer main = new LayoutContainer();
195
 
196
		main.add(left, new ColumnData(.45));
197
		main.add(right, new ColumnData(.45));
198
 
199
		main.setLayout(new ColumnLayout());
200
		main.setHeight("100%");
201
		main.setScrollMode(Scroll.AUTO);
202
 
203
		// Création des champs
204
		FormLayout formLayout = new FormLayout();
205
		formLayout.setLabelAlign(LabelAlign.LEFT);
206
 
207
		FieldSet fsProjet = new FieldSet();
875 jpm 208
		fsProjet.setHeading(i18nC.menuProjet());
676 gduche 209
		fsProjet.setLayout(new FormLayout());
210
 
211
		ListStore<Projet> storeProjets = new ListStore<Projet>();
212
		ComboBox cbProjets = new ComboBox<Projet>();
875 jpm 213
		cbProjets.setFieldLabel(i18nC.personneProjet()+ " :");
214
		cbProjets.setEmptyText(i18nC.txtListeProjetDefaut());
676 gduche 215
		cbProjets.setLabelSeparator("");
216
		cbProjets.setDisplayField("nom");
217
		cbProjets.setEditable(false);
218
		cbProjets.setTriggerAction(TriggerAction.ALL);
219
		cbProjets.setStore(storeProjets);
220
		cbProjets.setAllowBlank(false);
221
		fsProjet.add(cbProjets);
222
 
223
		hmIdentite.put("cbProjets", cbProjets);
224
 
928 jpm 225
		mediateur.selectionnerProjet(this, null);
456 gduche 226
 
676 gduche 227
		left.add(fsProjet);
456 gduche 228
 
676 gduche 229
		FieldSet fsNoms = new FieldSet();
230
		fsNoms.setHeading("Noms");
231
		fsNoms.setLayout(formLayout);
456 gduche 232
 
676 gduche 233
		// Nom complet : Affiché que si valeurs saisies
234
		LabelField nomComplet = new LabelField();
875 jpm 235
		nomComplet.setFieldLabel(i18nC.personneNomComplet() +" :");
676 gduche 236
		nomComplet.hide();
456 gduche 237
 
676 gduche 238
		fsNoms.add(nomComplet);
239
		hmIdentite.put("nomComplet", nomComplet);
276 gduche 240
 
676 gduche 241
		//Préfixe
242
		ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
243
		ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
244
		cbPrefixe.setStore(storePrefixe);
245
		cbPrefixe.setDisplayField("nom");
246
		cbPrefixe.setEmptyText("Choisissez le préfixe:");
247
		cbPrefixe.setFieldLabel("Prefix");
248
 
249
		fsNoms.add(cbPrefixe);
250
		hmIdentite.put("cbPrefixe", cbPrefixe);
251
 
252
		mediateur.obtenirListeValeurEtRafraichir(this, "prefixe");
253
 
254
		//Prénom
255
		TextField<String> tfPrenom = new TextField<String>();
256
		tfPrenom.setFieldLabel("Prénom");
257
		tfPrenom.setName("prenom");
258
 
259
		fsNoms.add(tfPrenom);
260
		hmIdentite.put("tfPrenom", tfPrenom);
261
 
262
		//Nom
263
		TextField<String> tfNom = new TextField<String>();
264
		tfNom.setFieldLabel("Nom");
265
		tfNom.setAllowBlank(false);
266
		tfNom.setName("nom");
267
 
268
		fsNoms.add(tfNom);
269
		hmIdentite.put("tfNom", tfNom);
270
 
271
		//Suffixe
272
		ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
273
		ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
274
		cbSuffixe.setStore(storeSuffixe);
275
		cbSuffixe.setFieldLabel("Suffixe");
276
		cbSuffixe.setDisplayField("nom");
277
		cbSuffixe.setEmptyText("Choisissez un suffixe:");
278
 
279
		fsNoms.add(cbSuffixe);
280
		hmIdentite.put("cbSuffixe", cbSuffixe);
281
 
282
		mediateur.obtenirListeValeurEtRafraichir(this, "suffixes");
283
 
284
		TextField<String> tfAbreviation = new TextField<String>();
285
		tfAbreviation.setFieldLabel("Abréviation");
286
		tfAbreviation.setName("abreviation");
287
 
288
		fsNoms.add(tfAbreviation);
289
		hmIdentite.put("tfAbreviation", tfAbreviation);
290
 
821 gduche 291
		TableLayout layoutAutreNoms = new TableLayout(2);
292
		layoutAutreNoms.setCellVerticalAlign(VerticalAlignment.TOP);
293
		LayoutContainer autresNoms = new LayoutContainer(layoutAutreNoms);
294
		ChampMultiValeurs nomAutre = new ChampMultiValeurs("Autres noms",150);
295
		hmIdentite.put("nomAutre", nomAutre);
296
		autresNoms.add(nomAutre, new TableData("200px", "15px"));
676 gduche 297
 
821 gduche 298
		ChampMultiValeurs abreviationAutre = new ChampMultiValeurs("Autres abréviation",150);
299
		hmIdentite.put("abreviationAutre", abreviationAutre);
300
		autresNoms.add(abreviationAutre, new TableData("200px", "15px"));
301
		fsNoms.add(autresNoms);
376 gduche 302
 
676 gduche 303
		left.add(fsNoms);
304
 
305
		formLayout = new FormLayout();
306
		formLayout.setLabelAlign(LabelAlign.LEFT);
307
 
308
		FieldSet fsNaissance = new FieldSet();
309
		fsNaissance.setHeading("Naissance");
310
		fsNaissance.setLayout(formLayout);
311
 
312
		DateField dfDateNaissance = new DateField();
313
		dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
314
		dfDateNaissance.setFieldLabel("Date");
315
		dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
316
 
317
		fsNaissance.add(dfDateNaissance);
318
		hmIdentite.put("dfDateNaissance", dfDateNaissance);
319
 
320
		// Lieu naissance
730 jp_milcent 321
		TextField<String> tfLieuNaissance = new TextField<String>();
676 gduche 322
		tfLieuNaissance.setFieldLabel("Lieu");
323
		tfLieuNaissance.setName("naissance_lieu");
324
 
325
		fsNaissance.add(tfLieuNaissance);
326
		hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
276 gduche 327
 
676 gduche 328
		left.add(fsNaissance);
329
 
330
		formLayout = new FormLayout();
331
		formLayout.setLabelAlign(LabelAlign.LEFT);
332
 
333
		FieldSet fsDeces = new FieldSet();
334
		fsDeces.setHeading("Décès");
335
		fsDeces.setLayout(formLayout);
276 gduche 336
 
676 gduche 337
		Radio rbEstDecedee = new Radio();
338
		rbEstDecedee.setBoxLabel("oui");
829 gduche 339
		rbEstDecedee.setValueAttribute("1");
676 gduche 340
 
341
		rbEstDecedee.addListener(Events.Change, new Listener<ComponentEvent>() {
446 gduche 342
 
676 gduche 343
			public void handleEvent(ComponentEvent be) {
344
				if(((Radio) be.getComponent()).getValue().equals(true))	{
345
					((DateField) hmIdentite.get("dfDateDeces")).setVisible(true);
346
					((TextField) hmIdentite.get("tfLieuDeces")).setVisible(true);
347
				} else	{
829 gduche 348
					DateField dfDateDeces = ((DateField) hmIdentite.get("dfDateDeces"));
349
					dfDateDeces.setValue(null);
350
					dfDateDeces.setVisible(false);
351
 
352
					TextField tfLieuDeces = ((TextField) hmIdentite.get("tfLieuDeces"));
353
					tfLieuDeces.setValue(null);
354
					tfLieuDeces.setVisible(false);
676 gduche 355
				}
356
			}
357
		});
446 gduche 358
 
676 gduche 359
		hmIdentite.put("rbEstDecedee", rbEstDecedee);
360
 
361
		Radio rbNestPasDecedee = new Radio();
829 gduche 362
		rbNestPasDecedee.setValueAttribute("0");
676 gduche 363
		rbNestPasDecedee.setBoxLabel("non");
364
		rbNestPasDecedee.setValue(true);
365
 
829 gduche 366
	/*	Radio rbDecesInconnu = new Radio();
821 gduche 367
		rbDecesInconnu.setBoxLabel("Ne sais pas");
829 gduche 368
		rbDecesInconnu.setValue(true);*/
821 gduche 369
 
676 gduche 370
		RadioGroup rbgDeces = new RadioGroup();
371
		rbgDeces.setFieldLabel("Est décédée");
372
		rbgDeces.add(rbEstDecedee);
373
		rbgDeces.add(rbNestPasDecedee);
374
 
375
		fsDeces.add(rbgDeces);
376
 
377
		DateField dfDateDeces = new DateField();
378
		dfDateDeces.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
379
		dfDateDeces.setFormatValue(true);
380
		dfDateDeces.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
381
		dfDateDeces.setFieldLabel("Date");
382
		dfDateDeces.setVisible(false);
383
 
384
		fsDeces.add(dfDateDeces);
385
		hmIdentite.put("dfDateDeces", dfDateDeces);
386
 
730 jp_milcent 387
		TextField<String> tfLieuDeces = new TextField<String>();
676 gduche 388
		tfLieuDeces.setFieldLabel("Lieu");
389
		tfLieuDeces.setName("deces_lieu");
390
		tfLieuDeces.setVisible(false);
391
 
392
		fsDeces.add(tfLieuDeces);
393
		hmIdentite.put("tfLieuDeces", tfLieuDeces);
376 gduche 394
 
676 gduche 395
		left.add(fsDeces);
276 gduche 396
 
676 gduche 397
		tiIdentite.add(main);
283 gduche 398
 
676 gduche 399
		FieldSet fsContactTel = new FieldSet();
400
		fsContactTel.setHeading("Contact - Téléphones");
401
		fsContactTel.setLayout(new RowLayout());
402
 
722 gduche 403
 
404
		ChampMultiValeursMultiTypes telephones = new ChampMultiValeursMultiTypes("Téléphones");
405
		hmIdentite.put("telephones", telephones);
857 jpm 406
		telephones.initialiserType("tel");
722 gduche 407
		fsContactTel.add(telephones);
676 gduche 408
		right.add(fsContactTel);
409
		hmIdentite.put("fsContactTel", fsContactTel);
376 gduche 410
 
676 gduche 411
 
412
		FieldSet fsContact = new FieldSet();
413
		fsContact.setHeading("Contact - Autres");
414
		fsContact.setId("fsContact");
415
		fsContact.setLayout(new RowLayout());
416
 
417
		right.add(fsContact);
418
		hmIdentite.put("fsContact", fsContact);
419
 
692 gduche 420
		ChampMultiValeurs courriels = new ChampMultiValeurs("Courriels");
729 jp_milcent 421
		courriels.setValidation(Pattern.email, "moi@domaine.fr");
692 gduche 422
		fsContact.add(courriels);
423
		hmIdentite.put("courriels", courriels);
676 gduche 424
 
425
		LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout());
426
 
427
		fsContact.add(lcCourrielContainer);
428
		hmIdentite.put("lcCourrielContainer", lcCourrielContainer);
429
 
692 gduche 430
		ChampMultiValeurs sites = new ChampMultiValeurs("Sites web");
695 gduche 431
		sites.setValeurParDefaut("http://");
729 jp_milcent 432
		sites.setValidation(Pattern.url, "http://www.monsite.com");
692 gduche 433
		fsContact.add(sites);
434
		hmIdentite.put("sites", sites);
286 gduche 435
 
676 gduche 436
		FieldSet fsAutresInfos = new FieldSet();
437
		fsAutresInfos.setHeading("Autres informations");
438
 
439
		formLayout = new FormLayout();
440
		formLayout.setLabelAlign(LabelAlign.LEFT);
441
		fsAutresInfos.setLayout(formLayout);
356 gduche 442
 
386 gduche 443
 
676 gduche 444
		formLayout = new FormLayout();
445
		formLayout.setLabelAlign(LabelAlign.TOP);
446
		LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout);
447
 
448
		//Civilité
449
		ListStore<Valeur> storeSexe = new ListStore<Valeur>();
450
		ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
451
		cbSexe.setStore(storeSexe);
452
		cbSexe.setFieldLabel("Sexe");
453
		cbSexe.setDisplayField("nom");
454
		cbSexe.setEmptyText("Choisissez le sexe:");
386 gduche 455
 
933 gduche 456
		lcAutreInformations1.add(cbSexe, new FormData(100, 10));
676 gduche 457
		hmIdentite.put("cbSexe", cbSexe);
386 gduche 458
 
676 gduche 459
		mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
460
 
461
		//Description
462
		TextArea taDescription = new TextArea();
463
		taDescription.setEmptyText("Saisissez une description");
464
		taDescription.setFieldLabel("Description");
465
		taDescription.setWidth("100%");
466
		taDescription.setName("description");
467
 
468
		lcAutreInformations1.add(taDescription, fd100);
469
		hmIdentite.put("taDescription", taDescription);
470
 
471
		fsAutresInfos.add(lcAutreInformations1);
472
 
473
		// Logo
689 gduche 474
		LayoutContainer lcLogoUrl = new LayoutContainer();
475
		hmIdentite.put("lcLogoUrl", lcLogoUrl);
676 gduche 476
 
875 jpm 477
		ChampMultiValeursImage logo = new ChampMultiValeursImage(i18nC.personneLogos());
701 gduche 478
		logo.setImageHeight("150px");
479
		logo.setValeurParDefaut("http://");
729 jp_milcent 480
		logo.setValidation(Pattern.url, "http://www.monsite.com/mon_image.jpg");
701 gduche 481
		logo.setValeurBoutonSupprimer("Supprimer");
482
		hmIdentite.put("logos", logo);
676 gduche 483
 
701 gduche 484
		lcLogoUrl.add(logo);
676 gduche 485
 
701 gduche 486
		fsAutresInfos.add(logo);
689 gduche 487
 
488
		LayoutContainer lcAutreInformations2 = new LayoutContainer(new ColumnLayout());
489
		hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
676 gduche 490
		fsAutresInfos.add(lcAutreInformations2);
386 gduche 491
 
676 gduche 492
		right.add(fsAutresInfos);
293 gduche 493
 
676 gduche 494
		// Ajout des évènements saisi
495
		KeyListener klNoms = new KeyListener()	{
496
			public void componentKeyUp(ComponentEvent ev)	{
497
				rafraichir(null);
498
			}
499
		};
500
 
501
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
502
			public void selectionChanged(SelectionChangedEvent se) {
730 jp_milcent 503
				rafraichir(null);
504
			}
676 gduche 505
		};
283 gduche 506
 
676 gduche 507
		cbPrefixe.addSelectionChangedListener(selectionChange);
508
		cbPrefixe.addKeyListener(klNoms);
509
		tfPrenom.addKeyListener(klNoms);
510
		tfNom.addKeyListener(klNoms);
511
		cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 512
 
513
	}
514
 
293 gduche 515
	public void creerComposantsAdresse()	{
516
		// Gauche
517
		LayoutContainer left = new LayoutContainer();
518
		left.setLayout(new FormLayout());
821 gduche 519
		left.setStyleAttribute("padding", "15px");
293 gduche 520
		// Droite
521
		LayoutContainer right = new LayoutContainer();
522
		right.setLayout(new FormLayout());
523
 
524
		// Principal
525
		LayoutContainer main = new LayoutContainer();
821 gduche 526
		main.setLayout(new TableLayout(2));
293 gduche 527
 
528
		// Ajout au principal
821 gduche 529
		main.add(left);
530
		main.add(right);
293 gduche 531
 
532
		TextField<String> tfAdresse1 = new TextField();
533
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 534
		tfAdresse1.setName("adresse_01");
319 gduche 535
		left.add(tfAdresse1, fd100);
293 gduche 536
		hmAdresse.put("tfAdresse1", tfAdresse1);
537
 
538
		TextField<String> tfAdresse2 = new TextField();
539
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 540
		tfAdresse2.setName("adresse_02");
319 gduche 541
		left.add(tfAdresse2, fd100);
293 gduche 542
		hmAdresse.put("tfAdresse2", tfAdresse2);
543
 
544
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
545
		cbPays.setFieldLabel("Pays");
546
		cbPays.setDisplayField("nom");
547
		cbPays.setEmptyText("Sélectionnez le pays:");
548
 
549
		ListStore<Valeur> storePays = new ListStore<Valeur>();
550
		cbPays.setStore(storePays);
551
 
319 gduche 552
		right.add(cbPays, fd100);
293 gduche 553
		hmAdresse.put("cbPays", cbPays);
554
 
555
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
556
			public void selectionChanged(SelectionChangedEvent se) {
730 jp_milcent 557
				// Rafraichir avec le pays sélectionné
558
				obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
559
			}
293 gduche 560
		};
561
 
562
		cbPays.addSelectionChangedListener(selectionChange);
563
 
564
 
565
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
566
		cbRegion.setFieldLabel("Region");
567
		cbRegion.setDisplayField("nom");
568
		cbRegion.setEmptyText("Sélectionnez la région:");
569
		cbRegion.setVisible(false);
570
 
571
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
572
		cbRegion.setStore(storeRegion);
573
 
352 gduche 574
 
319 gduche 575
		right.add(cbRegion, fd100);
293 gduche 576
		hmAdresse.put("cbRegion", cbRegion);
577
 
578
		TextField<String> tfBoitePostale = new TextField<String>();
579
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 580
		tfBoitePostale.setName("bp");
581
 
319 gduche 582
		left.add(tfBoitePostale, fd100);
293 gduche 583
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
584
 
585
		TextField<Integer> tfCodePostal = new TextField<Integer>();
586
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 587
		tfCodePostal.setName("code_postal");
588
 
319 gduche 589
		right.add(tfCodePostal, fd100);
293 gduche 590
		hmAdresse.put("tfCodePostal", tfCodePostal);
591
 
592
		TextField tfVille = new TextField();
593
		tfVille.setFieldLabel("Ville");
376 gduche 594
		tfVille.setName("ville");
293 gduche 595
 
319 gduche 596
		right.add(tfVille, fd100);
293 gduche 597
		hmAdresse.put("tfVille", tfVille);
598
 
599
		// MAJ ComboBox
600
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
601
 
304 gduche 602
		FieldSet fsAdresse = new FieldSet();
603
		fsAdresse.setHeading("Adresse personnelle");
604
		fsAdresse.add(main);
293 gduche 605
 
304 gduche 606
		tiAdresses.add(fsAdresse);
293 gduche 607
	}
821 gduche 608
 
609
	public void creerComposantsInfosNat()	{
338 gduche 610
 
821 gduche 611
		FieldSet fsInfosNat = new FieldSet();
612
		fsInfosNat.setTitle("Informations Naturaliste");
613
 
875 jpm 614
		ChampMultiValeurs specialite = new ChampMultiValeurs(i18nC.personneSpecialite());
821 gduche 615
		fsInfosNat.add(specialite);
616
		hmInfosNat.put("specialite", specialite);
617
 
875 jpm 618
		ChampMultiValeursMultiTypes recolte = new ChampMultiValeursMultiTypes(i18nC.personneRecolte());
857 jpm 619
		recolte.initialiserType("pays");
821 gduche 620
		hmInfosNat.put("recolte", recolte);
621
 
622
		fsInfosNat.add(recolte);
623
		tiInfosNat.add(fsInfosNat);
624
	}
625
 
276 gduche 626
 
850 gduche 627
 
276 gduche 628
	/**
338 gduche 629
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
630
	 *
631
	 * @param barreOutils la barre d'outils à modifier
632
	 * */
456 gduche 633
	private void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils)	{
338 gduche 634
 
635
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 636
		enregistrerEtRevenir = new Button("Enregistrer et revenir à la liste");
637
		enregistrerEtRevenir.setIcon(Images.ICONES.scriptGo());
638
		enregistrerEtRevenir.setIconAlign(IconAlign.LEFT);
639
		enregistrerEtRevenir.addSelectionListener(new SelectionListener<ButtonEvent>() {
488 gduche 640
			public void componentSelected(ButtonEvent ce) {
676 gduche 641
				if (enregistrer() == true)	{
642
					((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
643
				}
338 gduche 644
			}
645
		});
456 gduche 646
 
668 gduche 647
		hmIdentite.put("btnEnregistrerRevenir", enregistrerEtRevenir);
648
		barreOutils.add(enregistrerEtRevenir);
649
		enregistrerEtRevenir.setEnabled(false);
456 gduche 650
 
338 gduche 651
	}
652
 
653
	/**
276 gduche 654
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
655
	 *
656
	 * @param barreOutils la barre d'outils à modifier
657
	 * */
456 gduche 658
	private void ajouterBoutonEnregistrer(ButtonBar barreOutils)	{
276 gduche 659
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 660
		enregistrer = new Button("Enregistrer");
519 gduche 661
		enregistrer.setIcon(Images.ICONES.scriptSave());
662
		enregistrer.setIconAlign(IconAlign.LEFT);
352 gduche 663
		enregistrer.setId("main-button");
488 gduche 664
		enregistrer.addSelectionListener(new SelectionListener<ButtonEvent>() {
665
			public void componentSelected(ButtonEvent ce) {
376 gduche 666
				enregistrer();
276 gduche 667
			}
668
		});
456 gduche 669
		enregistrer.setEnabled(false);
670
		hmIdentite.put("btnEnregistrer", enregistrer);
286 gduche 671
		barreOutils.add(enregistrer);
276 gduche 672
	}
673
 
674
	/**
675
	 * Ajouter le bouton annuler à la barre d'outils donnée
676
	 *
677
	 * @param barreOutils la barre d'outils à modifier
678
	 * */
356 gduche 679
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 680
 
681
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 682
		Button annuler = new Button("Revenir à la liste");
488 gduche 683
		annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {
684
			public void componentSelected(ButtonEvent ce) {
276 gduche 685
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
686
			}
687
		});
688
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
689
		barreOutils.add(annuler);
690
	}
691
 
293 gduche 692
	public void obtenirListeRegionParPays(String strPays)	{
693
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
694
	}
276 gduche 695
 
730 jp_milcent 696
	// RAFRAICHISSEMENT DU PANNEAU
697
 
283 gduche 698
	public void rafraichir(Object nouvellesDonnees) {
456 gduche 699
		if (nouvellesDonnees instanceof ValeurListe) {
283 gduche 700
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
701
 
702
			// Créer une liste de valeurs
703
			List<Valeur> liste = new ArrayList<Valeur>();
704
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
705
				liste.add(listeValeurs.get(it.next()));
706
			}
707
 
933 gduche 708
 
283 gduche 709
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
319 gduche 710
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 711
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
712
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
713
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
714
				remplirCombobox("cbSexe", liste, "hmIdentite");
715
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
716
				remplirCombobox("cbTelephone", liste, "hmIdentite");
730 jp_milcent 717
 
319 gduche 718
				//Préselection du tél
719
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
720
				cbTelephone.setValue(liste.get(1));
293 gduche 721
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
722
				remplirCombobox("cbPays", liste, "hmAdresse");
723
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
724
				remplirCombobox("cbRegion", liste, "hmAdresse");
731 jp_milcent 725
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 726
			}
456 gduche 727
		} else if (nouvellesDonnees instanceof ProjetListe) {
728
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
730 jp_milcent 729
			List<Projet> liste = projets.toList();
456 gduche 730
 
731 jp_milcent 731
			ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
456 gduche 732
			ListStore<Projet> storeProjets= cbProjets.getStore();
733
			storeProjets.removeAll();
734
			storeProjets.add(liste);
735
			cbProjets.setStore(storeProjets);
352 gduche 736
		} else if (nouvellesDonnees instanceof Information)	{
737
			Information info = (Information) nouvellesDonnees;
386 gduche 738
			if (info.getType().equals("ajout_personne"))	{
884 jpm 739
				if (info.getDonnee(0) != null) {
740
					personneSelectionnee.setId(info.getDonnee(0).toString());
741
					GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
742
					Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
743
					repandreRafraichissement();
744
					if (clicBoutonvalidation)	{
745
						mediateur.clicMenu(menuIdCourant);
746
					}
747
				} else {
748
					Info.display("Enregistrement", info.getMessages().toString());
852 gduche 749
				}
433 gduche 750
			} else if (info.getType().equals("modification_personne"))	{
751
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
884 jpm 752
				repandreRafraichissement();
852 gduche 753
				if (clicBoutonvalidation)	{
754
					mediateur.clicMenu(menuIdCourant);
755
				}
884 jpm 756
			} else if (info.getType().equals("maj_utilisateur"))	{
668 gduche 757
				gererEtatActivationBouton();
386 gduche 758
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
776 gduche 759
 
730 jp_milcent 760
				Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
761
				Iterator itPersonneListe = colPersonneListe.iterator();
762
				Personne personne = (Personne) itPersonneListe.next();
763
 
764
				personneSauvegarde = new Personne();
765
				personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
766
 
767
				binderPersonne(personne);
768
 
776 gduche 769
				mettreAJourPersonne(personne);
730 jp_milcent 770
 
771
				nouvellesDonnees = null;
772
			} else {
773
				Info.display("messages", info.getMessages().toString());
774
			}
776 gduche 775
		}
283 gduche 776
 
730 jp_milcent 777
		if (nouvellesDonnees == null) {
319 gduche 778
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 779
 
780
			//Met à jour le nom Complet du formulaire
283 gduche 781
			String valeurRetour = "";
782
 
783
			// Prefixe
784
			String prefixe = "";
319 gduche 785
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 786
 
787
			if (valPrefixe != null)	{
788
				prefixe = valPrefixe.getNom();
293 gduche 789
			} else 	{
319 gduche 790
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 791
			}
283 gduche 792
 
793
			// Prénom
794
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
795
 
796
			// Nom
797
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
798
 
799
			// Suffixe
800
			String suffixe = "";
801
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
802
 
803
			if (valSuffixe != null)	{
804
				suffixe = valSuffixe.getNom();
293 gduche 805
			} else 	{
806
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 807
			}
808
 
809
			// Mettre à jour la valeur
810
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
811
			valeurRetour = valeurRetour.replaceAll("null", "");
812
 
813
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
814
 
815
			if (!valeurRetour.trim().equals(""))	{
816
				((LabelField) hmIdentite.get("nomComplet")).show();
817
			} else {
818
				((LabelField) hmIdentite.get("nomComplet")).hide();
819
			}
820
		}
338 gduche 821
 
822
		mediateur.masquerPopinChargement();
456 gduche 823
 
461 gduche 824
		if (this.mode.equals(MODE_AJOUTER))	{
668 gduche 825
			gererEtatActivationBouton();
456 gduche 826
		}
127 gduche 827
	}
828
 
884 jpm 829
	private void repandreRafraichissement() {
830
		if (vueExterneARafraichirApresValidation != null) {
831
			String type = "personne_modifiee";
832
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
833
				type = "personne_ajoutee";
834
			}
835
			Information info = new Information(type);
836
			info.setDonnee(0, personneSelectionnee);
837
			vueExterneARafraichirApresValidation.rafraichir(info);
838
		}
839
	}
840
 
776 gduche 841
	private void mettreAJourPersonne(Personne personne)	{
842
		//Mise à jour de la personne
843
		//Personne personne = (Personne) nouvellesDonnees;
844
 
845
		ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
846
		cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
847
 
848
		//Prefixe
849
		String prefixe = personne.get("ce_truk_prefix");
850
		ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
851
 
852
 
853
		String prefixeCourant = personne.get("ce_truk_prefix");
854
		if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
855
			cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
856
		}	else	{
857
			cbPrefixe.setRawValue(prefixeCourant);
858
		}
859
 
860
 
861
		((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
862
		((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
863
 
864
		//Suffixe
865
		String suffixe = personne.get("ce_truk_suffixe");
866
		ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
867
 
868
		String suffixeCourant = personne.get("ce_truk_suffix");
869
		if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
870
			cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
871
		}	else	{
872
			cbSuffixe.setRawValue(suffixeCourant);
873
		}
874
 
821 gduche 875
		((ChampMultiValeurs) hmIdentite.get("nomAutre")).peupler(personne.getString("truk_nom_autre"));
776 gduche 876
		((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
821 gduche 877
		((ChampMultiValeurs) hmIdentite.get("abreviationAutre")).peupler(personne.getString("truk_abreviation_autre"));
776 gduche 878
 
879
 
880
		(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
881
		((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
882
 
829 gduche 883
		if (personne.estDecedee())	{
884
			(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
885
			((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
886
			Radio rbEstDecede = (Radio) hmIdentite.get("rbEstDecedee");
887
			rbEstDecede.setValue(true);
888
 
889
		}
776 gduche 890
 
829 gduche 891
		((ChampMultiValeurs) hmIdentite.get("telephones")).peupler(personne.getString("truk_telephone"));
776 gduche 892
 
893
		//Courriel
894
		((ChampMultiValeurs) hmIdentite.get("courriels")).peupler(personne.getCourriel());
895
 
896
		//Sites web
897
		((ChampMultiValeurs) hmIdentite.get("sites")).peupler(personne.getString("truk_url"));
898
 
899
 
900
		// Sexe
901
		String strSexe = personne.get("ce_sexe");
902
		ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
903
 
904
		if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)	{
905
			cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
906
		}	else	{
907
			cbSexe.setRawValue(strSexe);
908
		}
909
 
910
		((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
911
 
912
		//Logo
913
		((ChampMultiValeurs) hmIdentite.get("logos")).peupler(personne.getString("truk_logo"));
914
 
915
		/*--------------------------------------------------
916
		                      Adresse
917
		 ---------------------------------------------------*/
918
 
919
		// Adresse
920
		((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
921
 
922
		// Complément
923
		((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
924
 
925
		//Boite postale
926
		((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
927
 
928
		//Pays
929
		String strPays = personne.get("pays");
930
		ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
931
 
932
 
933
		if (cbPays.getStore().findModel("nom", strPays) != null)	{
934
			cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
935
		}	else	{
936
			cbPays.setRawValue(strPays);
937
		}
938
 
939
		//Région
940
		String strRegion = personne.get("region");
941
		if ((strRegion!=null)&&(!strRegion.equals("")))	{
942
			ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
943
			cbRegion.setVisible(true);
944
 
945
			if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
946
				cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
947
			}	else	{
948
				cbRegion.setRawValue(strRegion);
949
			}
950
		}
951
 
952
		//Cp
953
		((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
954
 
955
		//Ville
956
		((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
957
 
821 gduche 958
		/*--------------------------------------------------------
959
		 * 					Infos naturalistes
960
		 * -----------------------------------------------------*/
961
 
962
		((ChampMultiValeurs) hmInfosNat.get("specialite")).peupler(personne.getString("ce_truk_specialite"));
963
		((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).peupler(personne.getString("truk_recolte"));
964
 
776 gduche 965
		gererEtatActivationBouton();
966
	}
730 jp_milcent 967
 
293 gduche 968
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
969
		HashMap hm = null;
970
		if (hashMapId.equals("hmIdentite"))	{
971
			hm = hmIdentite;
972
		} else if (hashMapId.equals("hmAdresse")){
973
			hm = hmAdresse;
974
		} else {
975
			hm = hmInfosNat;
976
		}
977
 
978
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 979
 
293 gduche 980
		store.removeAll();
981
		store.add(liste);
982
		((ComboBox) hm.get(idComboBox)).setStore(store);
983
	}
130 gduche 984
 
668 gduche 985
	private void gererEtatActivationBouton()	{
850 gduche 986
	/*	if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
668 gduche 987
			enregistrer.setEnabled(false);
988
			enregistrerEtRevenir.setEnabled(false);
989
		} else	{
990
			enregistrer.setEnabled(true);
991
			enregistrerEtRevenir.setEnabled(true);
850 gduche 992
		}*/
668 gduche 993
	}
994
 
850 gduche 995
	public void reinitialiserFormulaire()	{
461 gduche 996
		mediateur.afficherPopinChargement();
776 gduche 997
		mettreAJourPersonne(personneSauvegarde);
376 gduche 998
		mediateur.masquerPopinChargement();
999
	}
1000
 
1001
	public void binderPersonne(Personne personne)	{
850 gduche 1002
		binding = new FormBinding(getFormulaire());
731 jp_milcent 1003
 
376 gduche 1004
		personneSelectionnee = personne;
1005
		binding.autoBind();
1006
		binding.bind(personneSelectionnee);
1007
		layout();
1008
	}
130 gduche 1009
 
376 gduche 1010
	/**
1011
	 * Enregistre les information de la personne en cours
1012
	 *
1013
	 */
676 gduche 1014
	public boolean enregistrer()	{
1015
		boolean success = false;
376 gduche 1016
		LinkedList lstMessageErreur = new LinkedList<String>();
1017
 
456 gduche 1018
		ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");
1019
		Projet projet = cbProjets.getValue();
1020
		if (projet == null)	{
1021
			lstMessageErreur.add("Le projet n'a pas été renseigné");
681 gduche 1022
		} else {
1023
			personneSelectionnee.set("ce_projet", projet.getId());
456 gduche 1024
		}
461 gduche 1025
 
1026
		String strTfNom = ((TextField<String>) hmIdentite.get("tfNom")).getValue();
1027
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1028
			lstMessageErreur.add("Le nom n'a pas été saisi");
622 gduche 1029
		} else {
1030
			strTfNom = UtilString.ucFirst(strTfNom);
1031
			personneSelectionnee.set("nom", strTfNom);
461 gduche 1032
		}
456 gduche 1033
 
622 gduche 1034
		String strTfPrenom = ((TextField<String>) hmIdentite.get("tfPrenom")).getValue();
1035
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1036
 
376 gduche 1037
		//Préparer les données
1038
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1039
		Valeur valeur;
1040
		String strValeur = "";
1041
 
678 gduche 1042
		valeur = (Valeur) combo.getValue();
1043
		if (valeur!=null)	{
1044
			personneSelectionnee.set("ce_sexe", valeur.getId());
1045
		}
376 gduche 1046
 
1047
		strValeur = obtenirValeurCombo("cbPrefixe");
1048
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1049
 
1050
		strValeur = obtenirValeurCombo("cbSuffixe");
1051
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1052
 
821 gduche 1053
		String nomAutre = ((ChampMultiValeurs) hmIdentite.get("nomAutre")).getValeurs();
1054
		personneSelectionnee.set("truk_nom_autre", nomAutre);
1055
 
1056
		String abreviationAutre = ((ChampMultiValeurs) hmIdentite.get("abreviationAutre")).getValeurs();
1057
		personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);
1058
 
692 gduche 1059
		personneSelectionnee.set("truk_courriel", ((ChampMultiValeurs) hmIdentite.get("courriels")).getValeurs());
376 gduche 1060
 
386 gduche 1061
 
1062
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1063
		String strPrefixe = "";
1064
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1065
		valeur = (Valeur) combo.getValue();
1066
		if (valeur != null)	{
1067
			strPrefixe = valeur.getNom();
1068
		} else {
1069
			strPrefixe = combo.getRawValue();
1070
		}
1071
 
1072
		String strSuffixe = "";
1073
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1074
		valeur = (Valeur) combo.getValue();
1075
		if (valeur != null)	{
456 gduche 1076
			strSuffixe = valeur.getNom() + " ";
386 gduche 1077
		} else {
456 gduche 1078
			strSuffixe = combo.getRawValue() +" ";
386 gduche 1079
		}
376 gduche 1080
 
456 gduche 1081
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
376 gduche 1082
 
456 gduche 1083
		DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");
1084
		Date naissanceDate = dfDateNaissance.getValue();
1085
		personneSelectionnee.setNaissanceDate(naissanceDate);
376 gduche 1086
 
456 gduche 1087
		Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");
829 gduche 1088
		if (rbEstDecedee.getValue() == true)	{
456 gduche 1089
			DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");
829 gduche 1090
			String decesLieu = ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue();
1091
			personneSelectionnee.setDeces(dfDecesDate.getValue(), decesLieu);
1092
		}	else	{
1093
			personneSelectionnee.setNonDecedee();
456 gduche 1094
		}
1095
 
376 gduche 1096
		strValeur = obtenirValeurCombo("cbPays");
676 gduche 1097
		personneSelectionnee.set("ce_truk_pays", strValeur);
376 gduche 1098
 
1099
		strValeur = obtenirValeurCombo("cbRegion");
676 gduche 1100
		personneSelectionnee.set("ce_truk_region", strValeur);
376 gduche 1101
 
722 gduche 1102
		personneSelectionnee.set("truk_telephone", ((ChampMultiValeursMultiTypes) hmIdentite.get("telephones")).getValeurs());
376 gduche 1103
 
701 gduche 1104
		String logoUrls = ((ChampMultiValeursImage) hmIdentite.get("logos")).getValeurs();
386 gduche 1105
		personneSelectionnee.set("truk_logo", logoUrls);
376 gduche 1106
 
692 gduche 1107
		personneSelectionnee.set("truk_url", ((ChampMultiValeurs) hmIdentite.get("sites")).getValeurs());
376 gduche 1108
 
821 gduche 1109
		//Infos Naturalistes
1110
		String recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs();
1111
		personneSelectionnee.set("truk_recolte", recolte);
1112
 
1113
		String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();
1114
		personneSelectionnee.set("ce_truk_specialite", specialite);
1115
 
829 gduche 1116
 
461 gduche 1117
		if (lstMessageErreur.size() == 0)	{
386 gduche 1118
			mediateur.enregistrerPersonne(this, personneSelectionnee);
676 gduche 1119
			success = true;
456 gduche 1120
		} else {
1121
			String strMessagesErreur = "<span><br />";
386 gduche 1122
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1123
			while (itMessagesErreur.hasNext())	{
456 gduche 1124
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
386 gduche 1125
			}
456 gduche 1126
			strMessagesErreur += "</span>";
386 gduche 1127
 
1128
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
676 gduche 1129
 			success = false;
456 gduche 1130
		}
676 gduche 1131
 
1132
		return success;
376 gduche 1133
	}
1134
 
1135
	private String obtenirValeurCombo(String strComboName)	{
1136
		String strValeur = "";
1137
		Valeur valeur;
1138
 
1139
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1140
		if (combo == null)	{
1141
			combo = (ComboBox) hmAdresse.get(strComboName);
1142
		}
829 gduche 1143
		strValeur = combo.getRawValue();
1144
		valeur = (Valeur) combo.getStore().findModel(strValeur);
1145
		if (valeur != null)	{
1146
			strValeur = valeur.getId();
1147
		}
1148
 
1149
		/*if (combo.getValue()!=null)	{
376 gduche 1150
			valeur = (Valeur) combo.getValue();
1151
			strValeur = valeur.getId();
1152
		} else {
1153
			strValeur = combo.getRawValue();
829 gduche 1154
		}*/
376 gduche 1155
 
1156
		return strValeur;
1157
	}
850 gduche 1158
 
934 jpm 1159
	public boolean soumettreFormulaire() {
850 gduche 1160
		if (verifierFormulaire())	{
1161
			mediateur.enregistrerPersonne(this, personneSelectionnee);
1162
		}
1163
		return true;
1164
	}
1165
 
934 jpm 1166
	public boolean verifierFormulaire() {
884 jpm 1167
		boolean success = true;
1168
		LinkedList<String> lstMessageErreur = new LinkedList<String>();
850 gduche 1169
 
1170
		ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");
1171
		Projet projet = cbProjets.getValue();
1172
		if (projet == null)	{
1173
			lstMessageErreur.add("Le projet n'a pas été renseigné");
1174
		} else {
1175
			personneSelectionnee.set("ce_projet", projet.getId());
1176
		}
1177
 
1178
		String strTfNom = ((TextField<String>) hmIdentite.get("tfNom")).getValue();
1179
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1180
			lstMessageErreur.add("Le nom n'a pas été saisi");
1181
		} else {
1182
			strTfNom = UtilString.ucFirst(strTfNom);
1183
			personneSelectionnee.set("nom", strTfNom);
1184
		}
1185
 
1186
		String strTfPrenom = ((TextField<String>) hmIdentite.get("tfPrenom")).getValue();
1187
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1188
 
1189
		//Préparer les données
1190
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1191
		Valeur valeur;
1192
		String strValeur = "";
1193
 
1194
		valeur = (Valeur) combo.getValue();
1195
		if (valeur!=null)	{
1196
			personneSelectionnee.set("ce_sexe", valeur.getId());
1197
		}
1198
 
1199
		strValeur = obtenirValeurCombo("cbPrefixe");
1200
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1201
 
1202
		strValeur = obtenirValeurCombo("cbSuffixe");
1203
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1204
 
1205
		String nomAutre = ((ChampMultiValeurs) hmIdentite.get("nomAutre")).getValeurs();
1206
		personneSelectionnee.set("truk_nom_autre", nomAutre);
1207
 
1208
		String abreviationAutre = ((ChampMultiValeurs) hmIdentite.get("abreviationAutre")).getValeurs();
1209
		personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);
1210
 
1211
		personneSelectionnee.set("truk_courriel", ((ChampMultiValeurs) hmIdentite.get("courriels")).getValeurs());
1212
 
1213
 
1214
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1215
		String strPrefixe = "";
1216
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1217
		valeur = (Valeur) combo.getValue();
1218
		if (valeur != null)	{
1219
			strPrefixe = valeur.getNom();
1220
		} else {
1221
			strPrefixe = combo.getRawValue();
1222
		}
1223
 
1224
		String strSuffixe = "";
1225
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1226
		valeur = (Valeur) combo.getValue();
1227
		if (valeur != null)	{
1228
			strSuffixe = valeur.getNom() + " ";
1229
		} else {
1230
			strSuffixe = combo.getRawValue() +" ";
1231
		}
1232
 
1233
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
1234
 
1235
		DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");
1236
		Date naissanceDate = dfDateNaissance.getValue();
1237
		personneSelectionnee.setNaissanceDate(naissanceDate);
1238
 
1239
		Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");
1240
		if (rbEstDecedee.getValue() == true)	{
1241
			DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");
1242
			String decesLieu = ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue();
1243
			personneSelectionnee.setDeces(dfDecesDate.getValue(), decesLieu);
1244
		}	else	{
1245
			personneSelectionnee.setNonDecedee();
1246
		}
1247
 
1248
		strValeur = obtenirValeurCombo("cbPays");
1249
		personneSelectionnee.set("ce_truk_pays", strValeur);
1250
 
1251
		strValeur = obtenirValeurCombo("cbRegion");
1252
		personneSelectionnee.set("ce_truk_region", strValeur);
1253
 
1254
		personneSelectionnee.set("truk_telephone", ((ChampMultiValeursMultiTypes) hmIdentite.get("telephones")).getValeurs());
1255
 
1256
		String logoUrls = ((ChampMultiValeursImage) hmIdentite.get("logos")).getValeurs();
1257
		personneSelectionnee.set("truk_logo", logoUrls);
1258
 
1259
		personneSelectionnee.set("truk_url", ((ChampMultiValeurs) hmIdentite.get("sites")).getValeurs());
1260
 
1261
		//Infos Naturalistes
1262
		String recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs();
1263
		personneSelectionnee.set("truk_recolte", recolte);
1264
 
1265
		String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();
1266
		personneSelectionnee.set("ce_truk_specialite", specialite);
1267
 
1268
 
884 jpm 1269
		if (lstMessageErreur.size() != 0)	{
850 gduche 1270
			String strMessagesErreur = "<span><br />";
1271
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1272
			while (itMessagesErreur.hasNext())	{
1273
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
1274
			}
1275
			strMessagesErreur += "</span>";
1276
 
1277
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
1278
 			success = false;
1279
		}
1280
 
1281
		return success;
1282
	}
127 gduche 1283
}