Subversion Repositories eFlore/Applications.coel

Rev

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

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