Subversion Repositories eFlore/Applications.coel

Rev

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