Subversion Repositories eFlore/Applications.coel

Rev

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