Subversion Repositories eFlore/Applications.coel

Rev

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

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