Subversion Repositories eFlore/Applications.coel

Rev

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