Subversion Repositories eFlore/Applications.coel

Rev

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