Subversion Repositories eFlore/Applications.coel

Rev

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

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