Subversion Repositories eFlore/Applications.coel

Rev

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

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