Subversion Repositories eFlore/Applications.coel

Rev

Rev 776 | Rev 829 | 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;
286 gduche 22
import org.tela_botanica.client.modeles.Personne;
352 gduche 23
import org.tela_botanica.client.modeles.PersonneListe;
456 gduche 24
import org.tela_botanica.client.modeles.Projet;
25
import org.tela_botanica.client.modeles.ProjetListe;
668 gduche 26
import org.tela_botanica.client.modeles.Utilisateur;
280 gduche 27
import org.tela_botanica.client.modeles.Valeur;
283 gduche 28
import org.tela_botanica.client.modeles.ValeurListe;
729 jp_milcent 29
import org.tela_botanica.client.util.Pattern;
622 gduche 30
import org.tela_botanica.client.util.UtilString;
127 gduche 31
 
488 gduche 32
import com.extjs.gxt.ui.client.event.Events;
276 gduche 33
import com.extjs.gxt.ui.client.Registry;
34
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
519 gduche 35
import com.extjs.gxt.ui.client.Style.IconAlign;
283 gduche 36
import com.extjs.gxt.ui.client.Style.Scroll;
821 gduche 37
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
386 gduche 38
 
376 gduche 39
import com.extjs.gxt.ui.client.binding.FormBinding;
386 gduche 40
 
488 gduche 41
import com.extjs.gxt.ui.client.event.ButtonEvent;
276 gduche 42
import com.extjs.gxt.ui.client.event.ComponentEvent;
43
import com.extjs.gxt.ui.client.event.KeyListener;
446 gduche 44
import com.extjs.gxt.ui.client.event.Listener;
280 gduche 45
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
46
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 47
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 48
import com.extjs.gxt.ui.client.store.ListStore;
127 gduche 49
import com.extjs.gxt.ui.client.widget.LayoutContainer;
319 gduche 50
import com.extjs.gxt.ui.client.widget.MessageBox;
338 gduche 51
 
386 gduche 52
import com.extjs.gxt.ui.client.widget.Info;
276 gduche 53
import com.extjs.gxt.ui.client.widget.TabItem;
54
import com.extjs.gxt.ui.client.widget.TabPanel;
283 gduche 55
 
356 gduche 56
import com.extjs.gxt.ui.client.widget.button.Button;
57
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
280 gduche 58
import com.extjs.gxt.ui.client.widget.form.ComboBox;
59
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 60
import com.extjs.gxt.ui.client.widget.form.FieldSet;
352 gduche 61
import com.extjs.gxt.ui.client.widget.form.FormPanel;
276 gduche 62
import com.extjs.gxt.ui.client.widget.form.LabelField;
446 gduche 63
import com.extjs.gxt.ui.client.widget.form.Radio;
64
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
286 gduche 65
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 66
import com.extjs.gxt.ui.client.widget.form.TextField;
456 gduche 67
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
276 gduche 68
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
69
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
70
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
319 gduche 71
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 72
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
356 gduche 73
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
821 gduche 74
import com.extjs.gxt.ui.client.widget.layout.TableData;
75
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
276 gduche 76
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
386 gduche 77
import com.google.gwt.core.client.GWT;
339 gduche 78
import com.google.gwt.i18n.client.DateTimeFormat;
276 gduche 79
import com.google.gwt.user.client.ui.Widget;
127 gduche 80
 
446 gduche 81
public class PersonneForm extends FormPanel implements Rafraichissable {
127 gduche 82
 
730 jp_milcent 83
	// VARIABLES
276 gduche 84
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
283 gduche 85
	private Mediateur mediateur = Registry.get(RegistreId.MEDIATEUR);
86
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
376 gduche 87
	private Personne personneSelectionnee, personneSauvegarde = null;
456 gduche 88
	private String mode = "";
276 gduche 89
 
657 gduche 90
	//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite
91
	private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();
92
	private HashMap<String, Widget>hmAdresse = new HashMap<String, Widget>();
93
	private HashMap<String, Widget>hmInfosNat = new HashMap<String, Widget>();
730 jp_milcent 94
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
657 gduche 95
	private FormData fd100 = new FormData("1");
96
 
668 gduche 97
	private Button enregistrer, enregistrerEtRevenir;
98
 
456 gduche 99
	public static final String MODE_AJOUTER = "AJOUT";
100
	public static final String MODE_MODIFIER = "MODIF";
730 jp_milcent 101
 
376 gduche 102
	private FormBinding binding = null;
103
 
730 jp_milcent 104
	// CONSTRUCTEUR
446 gduche 105
 
456 gduche 106
	public PersonneForm(String mode) {
107
		this.mode = mode;
386 gduche 108
		initialiserComposants();
352 gduche 109
	}
110
 
386 gduche 111
	public void initialiserComposants()	{
376 gduche 112
		personneSelectionnee = new Personne();
113
		personneSauvegarde = new Personne();
114
 
283 gduche 115
		initialiserPanneau();
276 gduche 116
 
356 gduche 117
		ButtonBar barreOutilsBas = new ButtonBar();
488 gduche 118
		//barreOutilsBas.setButtonAlign(HorizontalAlignment.CENTER);
119
		barreOutilsBas.setAlignment(HorizontalAlignment.CENTER);
276 gduche 120
 
352 gduche 121
		ajouterBoutonEnregistrer(barreOutilsBas);
122
		ajouterBoutonEnregistrerEtRevenir(barreOutilsBas);
123
		ajouterBoutonAnnuler(barreOutilsBas);
668 gduche 124
		gererEtatActivationBouton();
276 gduche 125
 
352 gduche 126
		setBottomComponent(barreOutilsBas);
276 gduche 127
 
352 gduche 128
		ToolBar barreOutilsHaut = new ToolBar();
129
		ajouterBoutonReinitialiser(barreOutilsHaut);
130
		setTopComponent(barreOutilsHaut);
338 gduche 131
 
276 gduche 132
		initialiserOnglets();
133
 
134
		creerComposantsIdentite();
293 gduche 135
		creerComposantsAdresse();
821 gduche 136
		creerComposantsInfosNat();
352 gduche 137
		layout();
338 gduche 138
 
376 gduche 139
		binderPersonne(personneSelectionnee);
276 gduche 140
	}
141
 
730 jp_milcent 142
	// SOUS-METHODES
143
 
283 gduche 144
	public void initialiserPanneau()	{
145
		setCollapsible(false);
461 gduche 146
		if (this.mode.equals(MODE_AJOUTER))	{
147
			setHeading(mediateur.i18nC.personneModeAjout());
519 gduche 148
			setIcon(Images.ICONES.ajouter());
461 gduche 149
		} else 	{
150
			setHeading(mediateur.i18nC.personneModeModifier());
519 gduche 151
			setIcon(Images.ICONES.formModifier());
461 gduche 152
		}
283 gduche 153
		setButtonAlign(HorizontalAlignment.CENTER);
386 gduche 154
		setLayout(new FitLayout());
376 gduche 155
		setBodyBorder(false);
156
		setBorders(false);
157
		setPadding(0);
158
		setWidth("100%");
446 gduche 159
 
276 gduche 160
	}
161
 
162
	/**
163
	 * Crée les onglets identité, adresse et informations naturaliste
164
	 *
165
	 * */
166
	public void initialiserOnglets()	{
167
		//TabPanel
168
		TabPanel formulaireOnglets = new TabPanel();
169
 
170
		//Tab 1 : identite
461 gduche 171
		tiIdentite = new TabItem(mediateur.i18nC.personneIdentite());
276 gduche 172
		tiIdentite.setLayout(new FormLayout());
283 gduche 173
		tiIdentite.setScrollMode(Scroll.AUTO);
446 gduche 174
 
276 gduche 175
		formulaireOnglets.add(tiIdentite);
293 gduche 176
		hmIdentite.put("tiIdentite", tiIdentite);
276 gduche 177
 
178
		//Tab 2 : Adresse
461 gduche 179
		tiAdresses = new TabItem(mediateur.i18nC.adresse());
304 gduche 180
		tiAdresses.setLayout(new FormLayout());
283 gduche 181
		tiAdresses.setScrollMode(Scroll.AUTO);
276 gduche 182
		formulaireOnglets.add(tiAdresses);
183
 
184
		//Tab 3 : Infos Naturalistes
461 gduche 185
		tiInfosNat = new TabItem(mediateur.i18nC.personneInfoNat());
276 gduche 186
		tiInfosNat.setLayout(new FormLayout());
283 gduche 187
		tiInfosNat.setScrollMode(Scroll.AUTO);
446 gduche 188
 
276 gduche 189
		formulaireOnglets.add(tiInfosNat);
190
		add(formulaireOnglets);
191
	}
192
 
193
	/**
194
	 * Crée les widgets pour l'onglet identité
195
	 *
196
	 * */
197
 
198
 
199
	public void creerComposantsIdentite()	{
676 gduche 200
		// Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite
201
		LayoutContainer left = new LayoutContainer();
202
		left.setLayout(new FormLayout());
203
		LayoutContainer right = new LayoutContainer();
204
		right.setLayout(new FormLayout());
456 gduche 205
 
676 gduche 206
		LayoutContainer main = new LayoutContainer();
207
 
208
		main.add(left, new ColumnData(.45));
209
		main.add(right, new ColumnData(.45));
210
 
211
		main.setLayout(new ColumnLayout());
212
		main.setHeight("100%");
213
		main.setScrollMode(Scroll.AUTO);
214
 
215
		// Création des champs
216
		FormLayout formLayout = new FormLayout();
217
		formLayout.setLabelAlign(LabelAlign.LEFT);
218
 
219
		FieldSet fsProjet = new FieldSet();
220
		fsProjet.setHeading(mediateur.i18nC.menuProjet());
221
		fsProjet.setLayout(new FormLayout());
222
 
223
		ListStore<Projet> storeProjets = new ListStore<Projet>();
224
		ComboBox cbProjets = new ComboBox<Projet>();
225
		cbProjets.setFieldLabel(mediateur.i18nC.personneProjet()+ " :");
226
		cbProjets.setEmptyText(mediateur.i18nC.txtListeProjetDefaut());
227
		cbProjets.setLabelSeparator("");
228
		cbProjets.setDisplayField("nom");
229
		cbProjets.setEditable(false);
230
		cbProjets.setTriggerAction(TriggerAction.ALL);
231
		cbProjets.setStore(storeProjets);
232
		cbProjets.setAllowBlank(false);
233
		fsProjet.add(cbProjets);
234
 
235
		hmIdentite.put("cbProjets", cbProjets);
236
 
237
		mediateur.selectionnerProjets(this);
456 gduche 238
 
676 gduche 239
		left.add(fsProjet);
456 gduche 240
 
676 gduche 241
		FieldSet fsNoms = new FieldSet();
242
		fsNoms.setHeading("Noms");
243
		fsNoms.setLayout(formLayout);
456 gduche 244
 
676 gduche 245
		// Nom complet : Affiché que si valeurs saisies
246
		LabelField nomComplet = new LabelField();
247
		nomComplet.setFieldLabel(mediateur.i18nC.personneNomComplet() +" :");
248
		nomComplet.hide();
456 gduche 249
 
676 gduche 250
		fsNoms.add(nomComplet);
251
		hmIdentite.put("nomComplet", nomComplet);
276 gduche 252
 
676 gduche 253
		//Préfixe
254
		ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
255
		ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
256
		cbPrefixe.setStore(storePrefixe);
257
		cbPrefixe.setDisplayField("nom");
258
		cbPrefixe.setEmptyText("Choisissez le préfixe:");
259
		cbPrefixe.setFieldLabel("Prefix");
260
 
261
		fsNoms.add(cbPrefixe);
262
		hmIdentite.put("cbPrefixe", cbPrefixe);
263
 
264
		mediateur.obtenirListeValeurEtRafraichir(this, "prefixe");
265
 
266
		//Prénom
267
		TextField<String> tfPrenom = new TextField<String>();
268
		tfPrenom.setFieldLabel("Prénom");
269
		tfPrenom.setName("prenom");
270
 
271
		fsNoms.add(tfPrenom);
272
		hmIdentite.put("tfPrenom", tfPrenom);
273
 
274
		//Nom
275
		TextField<String> tfNom = new TextField<String>();
276
		tfNom.setFieldLabel("Nom");
277
		tfNom.setAllowBlank(false);
278
		tfNom.setName("nom");
279
 
280
		fsNoms.add(tfNom);
281
		hmIdentite.put("tfNom", tfNom);
282
 
283
		//Suffixe
284
		ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
285
		ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
286
		cbSuffixe.setStore(storeSuffixe);
287
		cbSuffixe.setFieldLabel("Suffixe");
288
		cbSuffixe.setDisplayField("nom");
289
		cbSuffixe.setEmptyText("Choisissez un suffixe:");
290
 
291
		fsNoms.add(cbSuffixe);
292
		hmIdentite.put("cbSuffixe", cbSuffixe);
293
 
294
		mediateur.obtenirListeValeurEtRafraichir(this, "suffixes");
295
 
296
		TextField<String> tfAbreviation = new TextField<String>();
297
		tfAbreviation.setFieldLabel("Abréviation");
298
		tfAbreviation.setName("abreviation");
299
 
300
		fsNoms.add(tfAbreviation);
301
		hmIdentite.put("tfAbreviation", tfAbreviation);
302
 
821 gduche 303
		TableLayout layoutAutreNoms = new TableLayout(2);
304
		layoutAutreNoms.setCellVerticalAlign(VerticalAlignment.TOP);
305
		LayoutContainer autresNoms = new LayoutContainer(layoutAutreNoms);
306
		ChampMultiValeurs nomAutre = new ChampMultiValeurs("Autres noms",150);
307
		hmIdentite.put("nomAutre", nomAutre);
308
		autresNoms.add(nomAutre, new TableData("200px", "15px"));
676 gduche 309
 
821 gduche 310
		ChampMultiValeurs abreviationAutre = new ChampMultiValeurs("Autres abréviation",150);
311
		hmIdentite.put("abreviationAutre", abreviationAutre);
312
		autresNoms.add(abreviationAutre, new TableData("200px", "15px"));
313
		fsNoms.add(autresNoms);
376 gduche 314
 
676 gduche 315
		left.add(fsNoms);
316
 
317
		formLayout = new FormLayout();
318
		formLayout.setLabelAlign(LabelAlign.LEFT);
319
 
320
		FieldSet fsNaissance = new FieldSet();
321
		fsNaissance.setHeading("Naissance");
322
		fsNaissance.setLayout(formLayout);
323
 
324
		DateField dfDateNaissance = new DateField();
325
		dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
326
		dfDateNaissance.setFieldLabel("Date");
327
		dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
328
 
329
		fsNaissance.add(dfDateNaissance);
330
		hmIdentite.put("dfDateNaissance", dfDateNaissance);
331
 
332
		// Lieu naissance
730 jp_milcent 333
		TextField<String> tfLieuNaissance = new TextField<String>();
676 gduche 334
		tfLieuNaissance.setFieldLabel("Lieu");
335
		tfLieuNaissance.setName("naissance_lieu");
336
 
337
		fsNaissance.add(tfLieuNaissance);
338
		hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
276 gduche 339
 
676 gduche 340
		left.add(fsNaissance);
341
 
342
		formLayout = new FormLayout();
343
		formLayout.setLabelAlign(LabelAlign.LEFT);
344
 
345
		FieldSet fsDeces = new FieldSet();
346
		fsDeces.setHeading("Décès");
347
		fsDeces.setLayout(formLayout);
276 gduche 348
 
676 gduche 349
		Radio rbEstDecedee = new Radio();
350
		rbEstDecedee.setBoxLabel("oui");
351
 
352
		rbEstDecedee.addListener(Events.Change, new Listener<ComponentEvent>() {
446 gduche 353
 
676 gduche 354
			public void handleEvent(ComponentEvent be) {
355
				if(((Radio) be.getComponent()).getValue().equals(true))	{
356
					((DateField) hmIdentite.get("dfDateDeces")).setVisible(true);
357
					((TextField) hmIdentite.get("tfLieuDeces")).setVisible(true);
358
				} else	{
359
					((DateField) hmIdentite.get("dfDateDeces")).setVisible(false);
360
					((TextField) hmIdentite.get("tfLieuDeces")).setVisible(false);
361
				}
362
			}
363
		});
446 gduche 364
 
676 gduche 365
		hmIdentite.put("rbEstDecedee", rbEstDecedee);
366
 
367
		Radio rbNestPasDecedee = new Radio();
368
		rbNestPasDecedee.setBoxLabel("non");
369
		rbNestPasDecedee.setValue(true);
370
 
821 gduche 371
		Radio rbDecesInconnu = new Radio();
372
		rbDecesInconnu.setBoxLabel("Ne sais pas");
373
		rbDecesInconnu.setValue(true);
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);
411
		telephones.initialiserType("tel", mediateur);
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
 
676 gduche 461
		lcAutreInformations1.add(cbSexe, fd100);
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
 
821 gduche 482
		ChampMultiValeursImage logo = new ChampMultiValeursImage(mediateur.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
 
619
		ChampMultiValeurs specialite = new ChampMultiValeurs(mediateur.i18nC.personneSpecialite());
620
		fsInfosNat.add(specialite);
621
		hmInfosNat.put("specialite", specialite);
622
 
623
		ChampMultiValeursMultiTypes recolte = new ChampMultiValeursMultiTypes(mediateur.i18nC.personneRecolte());
624
		recolte.initialiserType("pays", mediateur);
625
		hmInfosNat.put("recolte", recolte);
626
 
627
		fsInfosNat.add(recolte);
628
		tiInfosNat.add(fsInfosNat);
629
	}
630
 
276 gduche 631
	/**
632
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
633
	 *
634
	 * @param barreOutils la barre d'outils à modifier
635
	 * */
376 gduche 636
	public void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
276 gduche 637
 
638
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
488 gduche 639
		Button reinitialiser = new Button("Réinitialiser le formulaire");
519 gduche 640
		reinitialiser.setIcon(Images.ICONES.rafraichir());
488 gduche 641
		reinitialiser.addSelectionListener(new SelectionListener<ButtonEvent>() {
642
			public void componentSelected(ButtonEvent ce) {
376 gduche 643
				//((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
644
				reinitialiser();
276 gduche 645
			}
646
		});
647
		barreOutils.add(reinitialiser);
648
	}
649
 
650
	/**
338 gduche 651
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
652
	 *
653
	 * @param barreOutils la barre d'outils à modifier
654
	 * */
456 gduche 655
	private void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils)	{
338 gduche 656
 
657
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 658
		enregistrerEtRevenir = new Button("Enregistrer et revenir à la liste");
659
		enregistrerEtRevenir.setIcon(Images.ICONES.scriptGo());
660
		enregistrerEtRevenir.setIconAlign(IconAlign.LEFT);
661
		enregistrerEtRevenir.addSelectionListener(new SelectionListener<ButtonEvent>() {
488 gduche 662
			public void componentSelected(ButtonEvent ce) {
676 gduche 663
				if (enregistrer() == true)	{
664
					((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
665
				}
338 gduche 666
			}
667
		});
456 gduche 668
 
668 gduche 669
		hmIdentite.put("btnEnregistrerRevenir", enregistrerEtRevenir);
670
		barreOutils.add(enregistrerEtRevenir);
671
		enregistrerEtRevenir.setEnabled(false);
456 gduche 672
 
338 gduche 673
	}
674
 
675
	/**
276 gduche 676
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
677
	 *
678
	 * @param barreOutils la barre d'outils à modifier
679
	 * */
456 gduche 680
	private void ajouterBoutonEnregistrer(ButtonBar barreOutils)	{
276 gduche 681
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 682
		enregistrer = new Button("Enregistrer");
519 gduche 683
		enregistrer.setIcon(Images.ICONES.scriptSave());
684
		enregistrer.setIconAlign(IconAlign.LEFT);
352 gduche 685
		enregistrer.setId("main-button");
488 gduche 686
		enregistrer.addSelectionListener(new SelectionListener<ButtonEvent>() {
687
			public void componentSelected(ButtonEvent ce) {
376 gduche 688
				enregistrer();
276 gduche 689
			}
690
		});
456 gduche 691
		enregistrer.setEnabled(false);
692
		hmIdentite.put("btnEnregistrer", enregistrer);
286 gduche 693
		barreOutils.add(enregistrer);
276 gduche 694
	}
695
 
696
	/**
697
	 * Ajouter le bouton annuler à la barre d'outils donnée
698
	 *
699
	 * @param barreOutils la barre d'outils à modifier
700
	 * */
356 gduche 701
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 702
 
703
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 704
		Button annuler = new Button("Revenir à la liste");
488 gduche 705
		annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {
706
			public void componentSelected(ButtonEvent ce) {
276 gduche 707
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
708
			}
709
		});
710
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
711
		barreOutils.add(annuler);
712
	}
713
 
293 gduche 714
	public void obtenirListeRegionParPays(String strPays)	{
715
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
716
	}
276 gduche 717
 
730 jp_milcent 718
	// RAFRAICHISSEMENT DU PANNEAU
719
 
283 gduche 720
	public void rafraichir(Object nouvellesDonnees) {
456 gduche 721
		if (nouvellesDonnees instanceof ValeurListe) {
283 gduche 722
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
723
 
724
			// Créer une liste de valeurs
725
			List<Valeur> liste = new ArrayList<Valeur>();
726
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
727
				liste.add(listeValeurs.get(it.next()));
728
			}
729
 
730
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
319 gduche 731
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 732
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
733
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
734
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
735
				remplirCombobox("cbSexe", liste, "hmIdentite");
736
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
737
				remplirCombobox("cbTelephone", liste, "hmIdentite");
730 jp_milcent 738
 
319 gduche 739
				//Préselection du tél
740
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
741
				cbTelephone.setValue(liste.get(1));
293 gduche 742
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
743
				remplirCombobox("cbPays", liste, "hmAdresse");
744
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
745
				remplirCombobox("cbRegion", liste, "hmAdresse");
731 jp_milcent 746
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 747
			}
456 gduche 748
		} else if (nouvellesDonnees instanceof ProjetListe) {
749
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
730 jp_milcent 750
			List<Projet> liste = projets.toList();
456 gduche 751
 
731 jp_milcent 752
			ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
456 gduche 753
			ListStore<Projet> storeProjets= cbProjets.getStore();
754
			storeProjets.removeAll();
755
			storeProjets.add(liste);
756
			cbProjets.setStore(storeProjets);
352 gduche 757
		} else if (nouvellesDonnees instanceof Information)	{
758
			Information info = (Information) nouvellesDonnees;
386 gduche 759
			if (info.getType().equals("ajout_personne"))	{
760
				GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
461 gduche 761
				Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
433 gduche 762
			} else if (info.getType().equals("modification_personne"))	{
763
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
668 gduche 764
			}
765
			else if (info.getType().equals("maj_utilisateur"))	{
766
				gererEtatActivationBouton();
386 gduche 767
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
776 gduche 768
 
730 jp_milcent 769
				Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
770
				Iterator itPersonneListe = colPersonneListe.iterator();
771
				Personne personne = (Personne) itPersonneListe.next();
772
 
773
				personneSauvegarde = new Personne();
774
				personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
775
 
776
				binderPersonne(personne);
777
 
776 gduche 778
				mettreAJourPersonne(personne);
730 jp_milcent 779
 
780
				nouvellesDonnees = null;
781
			} else {
782
				Info.display("messages", info.getMessages().toString());
783
			}
776 gduche 784
		}
283 gduche 785
 
730 jp_milcent 786
		if (nouvellesDonnees == null) {
319 gduche 787
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 788
 
789
			//Met à jour le nom Complet du formulaire
283 gduche 790
			String valeurRetour = "";
791
 
792
			// Prefixe
793
			String prefixe = "";
319 gduche 794
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 795
 
796
			if (valPrefixe != null)	{
797
				prefixe = valPrefixe.getNom();
293 gduche 798
			} else 	{
319 gduche 799
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 800
			}
283 gduche 801
 
802
			// Prénom
803
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
804
 
805
			// Nom
806
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
807
 
808
			// Suffixe
809
			String suffixe = "";
810
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
811
 
812
			if (valSuffixe != null)	{
813
				suffixe = valSuffixe.getNom();
293 gduche 814
			} else 	{
815
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 816
			}
817
 
818
			// Mettre à jour la valeur
819
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
820
			valeurRetour = valeurRetour.replaceAll("null", "");
821
 
822
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
823
 
824
			if (!valeurRetour.trim().equals(""))	{
825
				((LabelField) hmIdentite.get("nomComplet")).show();
826
			} else {
827
				((LabelField) hmIdentite.get("nomComplet")).hide();
828
			}
829
		}
338 gduche 830
 
831
		mediateur.masquerPopinChargement();
456 gduche 832
 
461 gduche 833
		if (this.mode.equals(MODE_AJOUTER))	{
668 gduche 834
			gererEtatActivationBouton();
456 gduche 835
		}
127 gduche 836
	}
837
 
776 gduche 838
	private void mettreAJourPersonne(Personne personne)	{
839
 
840
 
841
		//Mise à jour de la personne
842
		//Personne personne = (Personne) nouvellesDonnees;
843
 
844
		ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
845
		cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
846
 
847
		//Prefixe
848
		String prefixe = personne.get("ce_truk_prefix");
849
		ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
850
 
851
 
852
		String prefixeCourant = personne.get("ce_truk_prefix");
853
		if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
854
			cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
855
		}	else	{
856
			cbPrefixe.setRawValue(prefixeCourant);
857
		}
858
 
859
 
860
		((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
861
		((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
862
 
863
		//Suffixe
864
		String suffixe = personne.get("ce_truk_suffixe");
865
		ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
866
 
867
		String suffixeCourant = personne.get("ce_truk_suffix");
868
		if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
869
			cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
870
		}	else	{
871
			cbSuffixe.setRawValue(suffixeCourant);
872
		}
873
 
821 gduche 874
		((ChampMultiValeurs) hmIdentite.get("nomAutre")).peupler(personne.getString("truk_nom_autre"));
776 gduche 875
		((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
821 gduche 876
		((ChampMultiValeurs) hmIdentite.get("abreviationAutre")).peupler(personne.getString("truk_abreviation_autre"));
776 gduche 877
 
878
 
879
		(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
880
		((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
881
 
882
		(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
883
		((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
884
 
885
		((ChampMultiValeursMultiTypes) hmIdentite.get("telephones")).peupler(personne.getString("truk_telephone"));
886
 
887
		//Courriel
888
		((ChampMultiValeurs) hmIdentite.get("courriels")).peupler(personne.getCourriel());
889
 
890
		//Sites web
891
		((ChampMultiValeurs) hmIdentite.get("sites")).peupler(personne.getString("truk_url"));
892
 
893
 
894
		// Sexe
895
		String strSexe = personne.get("ce_sexe");
896
		ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
897
 
898
		if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)	{
899
			cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
900
		}	else	{
901
			cbSexe.setRawValue(strSexe);
902
		}
903
 
904
		((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
905
 
906
		//Logo
907
		((ChampMultiValeurs) hmIdentite.get("logos")).peupler(personne.getString("truk_logo"));
908
 
909
		/*--------------------------------------------------
910
		                      Adresse
911
		 ---------------------------------------------------*/
912
 
913
		// Adresse
914
		((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
915
 
916
		// Complément
917
		((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
918
 
919
		//Boite postale
920
		((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
921
 
922
		//Pays
923
		String strPays = personne.get("pays");
924
		ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
925
 
926
 
927
		if (cbPays.getStore().findModel("nom", strPays) != null)	{
928
			cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
929
		}	else	{
930
			cbPays.setRawValue(strPays);
931
		}
932
 
933
		//Région
934
		String strRegion = personne.get("region");
935
		if ((strRegion!=null)&&(!strRegion.equals("")))	{
936
			ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
937
			cbRegion.setVisible(true);
938
 
939
			if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
940
				cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
941
			}	else	{
942
				cbRegion.setRawValue(strRegion);
943
			}
944
		}
945
 
946
		//Cp
947
		((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
948
 
949
		//Ville
950
		((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
951
 
821 gduche 952
		/*--------------------------------------------------------
953
		 * 					Infos naturalistes
954
		 * -----------------------------------------------------*/
955
 
956
		((ChampMultiValeurs) hmInfosNat.get("specialite")).peupler(personne.getString("ce_truk_specialite"));
957
		System.out.println(personne.getString("truk_recolte"));
958
		((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).peupler(personne.getString("truk_recolte"));
959
 
776 gduche 960
		gererEtatActivationBouton();
961
 
962
	}
730 jp_milcent 963
 
293 gduche 964
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
965
		HashMap hm = null;
966
		if (hashMapId.equals("hmIdentite"))	{
967
			hm = hmIdentite;
968
		} else if (hashMapId.equals("hmAdresse")){
969
			hm = hmAdresse;
970
		} else {
971
			hm = hmInfosNat;
972
		}
973
 
974
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 975
 
293 gduche 976
		store.removeAll();
977
		store.add(liste);
978
		((ComboBox) hm.get(idComboBox)).setStore(store);
979
	}
130 gduche 980
 
668 gduche 981
	private void gererEtatActivationBouton()	{
982
		if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
983
			enregistrer.setEnabled(false);
984
			enregistrerEtRevenir.setEnabled(false);
985
		} else	{
986
			enregistrer.setEnabled(true);
987
			enregistrerEtRevenir.setEnabled(true);
988
		}
989
	}
990
 
376 gduche 991
	public void reinitialiser()	{
461 gduche 992
		mediateur.afficherPopinChargement();
376 gduche 993
 
776 gduche 994
		mettreAJourPersonne(personneSauvegarde);
376 gduche 995
 
996
		mediateur.masquerPopinChargement();
776 gduche 997
 
376 gduche 998
	}
999
 
1000
	public void binderPersonne(Personne personne)	{
731 jp_milcent 1001
		binding = new FormBinding(this);
1002
 
376 gduche 1003
		personneSelectionnee = personne;
1004
		binding.autoBind();
1005
		binding.bind(personneSelectionnee);
1006
 
1007
		layout();
1008
	}
130 gduche 1009
 
376 gduche 1010
	/**
1011
	 * Enregistre les information de la personne en cours
1012
	 *
1013
	 */
676 gduche 1014
	public boolean enregistrer()	{
1015
		boolean success = false;
376 gduche 1016
		LinkedList lstMessageErreur = new LinkedList<String>();
1017
 
456 gduche 1018
		ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");
1019
		Projet projet = cbProjets.getValue();
1020
		if (projet == null)	{
1021
			lstMessageErreur.add("Le projet n'a pas été renseigné");
681 gduche 1022
		} else {
1023
			personneSelectionnee.set("ce_projet", projet.getId());
456 gduche 1024
		}
461 gduche 1025
 
1026
		String strTfNom = ((TextField<String>) hmIdentite.get("tfNom")).getValue();
1027
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1028
			lstMessageErreur.add("Le nom n'a pas été saisi");
622 gduche 1029
		} else {
1030
			strTfNom = UtilString.ucFirst(strTfNom);
1031
			personneSelectionnee.set("nom", strTfNom);
461 gduche 1032
		}
456 gduche 1033
 
622 gduche 1034
		String strTfPrenom = ((TextField<String>) hmIdentite.get("tfPrenom")).getValue();
1035
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1036
 
376 gduche 1037
		//Préparer les données
1038
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1039
		Valeur valeur;
1040
		String strValeur = "";
1041
 
678 gduche 1042
		valeur = (Valeur) combo.getValue();
1043
		if (valeur!=null)	{
1044
			personneSelectionnee.set("ce_sexe", valeur.getId());
1045
		}
376 gduche 1046
 
1047
		strValeur = obtenirValeurCombo("cbPrefixe");
1048
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1049
 
1050
		strValeur = obtenirValeurCombo("cbSuffixe");
1051
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1052
 
821 gduche 1053
		String nomAutre = ((ChampMultiValeurs) hmIdentite.get("nomAutre")).getValeurs();
1054
		personneSelectionnee.set("truk_nom_autre", nomAutre);
1055
 
1056
		String abreviationAutre = ((ChampMultiValeurs) hmIdentite.get("abreviationAutre")).getValeurs();
1057
		personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);
1058
 
692 gduche 1059
		personneSelectionnee.set("truk_courriel", ((ChampMultiValeurs) hmIdentite.get("courriels")).getValeurs());
376 gduche 1060
 
386 gduche 1061
 
1062
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1063
		String strPrefixe = "";
1064
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1065
		valeur = (Valeur) combo.getValue();
1066
		if (valeur != null)	{
1067
			strPrefixe = valeur.getNom();
1068
		} else {
1069
			strPrefixe = combo.getRawValue();
1070
		}
1071
 
1072
		String strSuffixe = "";
1073
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1074
		valeur = (Valeur) combo.getValue();
1075
		if (valeur != null)	{
456 gduche 1076
			strSuffixe = valeur.getNom() + " ";
386 gduche 1077
		} else {
456 gduche 1078
			strSuffixe = combo.getRawValue() +" ";
386 gduche 1079
		}
376 gduche 1080
 
456 gduche 1081
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
376 gduche 1082
 
456 gduche 1083
		DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");
1084
		Date naissanceDate = dfDateNaissance.getValue();
1085
		personneSelectionnee.setNaissanceDate(naissanceDate);
376 gduche 1086
 
456 gduche 1087
		Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");
1088
		if (rbEstDecedee.getValue().equals(true))	{
1089
 
1090
			DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");
1091
			Date decesDate = dfDecesDate.getValue();
1092
			if (decesDate == null)	{
1093
				decesDate = new Date();
1094
			}
1095
			personneSelectionnee.setDecesDate(decesDate);
1096
			personneSelectionnee.set("deces_lieu", ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue());
1097
		}
1098
 
1099
		personneSelectionnee.setDecesDate(new Date());
1100
 
376 gduche 1101
		strValeur = obtenirValeurCombo("cbPays");
676 gduche 1102
		personneSelectionnee.set("ce_truk_pays", strValeur);
376 gduche 1103
 
1104
		strValeur = obtenirValeurCombo("cbRegion");
676 gduche 1105
		personneSelectionnee.set("ce_truk_region", strValeur);
376 gduche 1106
 
722 gduche 1107
		personneSelectionnee.set("truk_telephone", ((ChampMultiValeursMultiTypes) hmIdentite.get("telephones")).getValeurs());
376 gduche 1108
 
701 gduche 1109
		String logoUrls = ((ChampMultiValeursImage) hmIdentite.get("logos")).getValeurs();
386 gduche 1110
		personneSelectionnee.set("truk_logo", logoUrls);
376 gduche 1111
 
692 gduche 1112
		personneSelectionnee.set("truk_url", ((ChampMultiValeurs) hmIdentite.get("sites")).getValeurs());
376 gduche 1113
 
821 gduche 1114
		//Infos Naturalistes
1115
		String recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs();
1116
		personneSelectionnee.set("truk_recolte", recolte);
1117
 
1118
		String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();
1119
		personneSelectionnee.set("ce_truk_specialite", specialite);
1120
 
461 gduche 1121
		if (lstMessageErreur.size() == 0)	{
386 gduche 1122
			mediateur.enregistrerPersonne(this, personneSelectionnee);
676 gduche 1123
			success = true;
456 gduche 1124
		} else {
1125
			String strMessagesErreur = "<span><br />";
386 gduche 1126
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1127
			while (itMessagesErreur.hasNext())	{
456 gduche 1128
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
386 gduche 1129
			}
456 gduche 1130
			strMessagesErreur += "</span>";
386 gduche 1131
 
1132
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
676 gduche 1133
 			success = false;
456 gduche 1134
		}
676 gduche 1135
 
1136
		return success;
376 gduche 1137
	}
1138
 
1139
	private String obtenirValeurCombo(String strComboName)	{
1140
		String strValeur = "";
1141
		Valeur valeur;
1142
 
1143
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1144
		if (combo == null)	{
1145
			combo = (ComboBox) hmAdresse.get(strComboName);
1146
		}
1147
		if (combo.getValue()!=null)	{
1148
			valeur = (Valeur) combo.getValue();
1149
			strValeur = valeur.getId();
1150
		} else {
1151
			strValeur = combo.getRawValue();
1152
		}
1153
 
1154
		return strValeur;
1155
	}
127 gduche 1156
}