Subversion Repositories eFlore/Applications.coel

Rev

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