Subversion Repositories eFlore/Applications.coel

Rev

Rev 857 | Rev 883 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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