Subversion Repositories eFlore/Applications.coel

Rev

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