Subversion Repositories eFlore/Applications.coel

Rev

Rev 356 | Rev 386 | 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;
127 gduche 14
import org.tela_botanica.client.interfaces.Rafraichissable;
283 gduche 15
import org.tela_botanica.client.modeles.Configuration;
280 gduche 16
import org.tela_botanica.client.modeles.InterneValeur;
293 gduche 17
 
352 gduche 18
import org.tela_botanica.client.modeles.Information;
286 gduche 19
import org.tela_botanica.client.modeles.Personne;
352 gduche 20
import org.tela_botanica.client.modeles.PersonneListe;
280 gduche 21
import org.tela_botanica.client.modeles.Valeur;
283 gduche 22
import org.tela_botanica.client.modeles.ValeurListe;
127 gduche 23
 
276 gduche 24
 
25
import com.extjs.gxt.ui.client.Registry;
26
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
283 gduche 27
import com.extjs.gxt.ui.client.Style.Scroll;
376 gduche 28
import com.extjs.gxt.ui.client.binding.FieldBinding;
29
import com.extjs.gxt.ui.client.binding.FormBinding;
30
import com.extjs.gxt.ui.client.binding.SimpleComboBoxFieldBinding;
276 gduche 31
import com.extjs.gxt.ui.client.event.ComponentEvent;
32
import com.extjs.gxt.ui.client.event.KeyListener;
280 gduche 33
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
34
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 35
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 36
import com.extjs.gxt.ui.client.store.ListStore;
276 gduche 37
import com.extjs.gxt.ui.client.widget.ContentPanel;
127 gduche 38
import com.extjs.gxt.ui.client.widget.LayoutContainer;
319 gduche 39
import com.extjs.gxt.ui.client.widget.MessageBox;
338 gduche 40
 
276 gduche 41
import com.extjs.gxt.ui.client.widget.TabItem;
42
import com.extjs.gxt.ui.client.widget.TabPanel;
293 gduche 43
import com.extjs.gxt.ui.client.widget.Text;
283 gduche 44
 
356 gduche 45
import com.extjs.gxt.ui.client.widget.button.Button;
46
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
319 gduche 47
import com.extjs.gxt.ui.client.widget.button.IconButton;
280 gduche 48
import com.extjs.gxt.ui.client.widget.form.ComboBox;
49
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 50
import com.extjs.gxt.ui.client.widget.form.FieldSet;
352 gduche 51
import com.extjs.gxt.ui.client.widget.form.FormPanel;
293 gduche 52
import com.extjs.gxt.ui.client.widget.form.HiddenField;
276 gduche 53
import com.extjs.gxt.ui.client.widget.form.LabelField;
376 gduche 54
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
286 gduche 55
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 56
import com.extjs.gxt.ui.client.widget.form.TextField;
57
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
58
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
59
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
60
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
356 gduche 61
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
319 gduche 62
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 63
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
356 gduche 64
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
65
import com.extjs.gxt.ui.client.widget.layout.TableData;
293 gduche 66
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
276 gduche 67
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
68
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
339 gduche 69
import com.google.gwt.i18n.client.DateTimeFormat;
352 gduche 70
import com.google.gwt.user.client.Window;
276 gduche 71
import com.google.gwt.user.client.ui.Widget;
127 gduche 72
 
73
 
276 gduche 74
 
376 gduche 75
 
76
public class FormPersonneVue extends FormPanel implements Rafraichissable {
276 gduche 77
 
78
 
79
	/*--------------------------------------------------------------------------------------
80
	 * 		VARIABLES
81
	 * -------------------------------------------------------------------------------------
82
	 */
83
 
84
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
283 gduche 85
	private Mediateur mediateur = Registry.get(RegistreId.MEDIATEUR);
86
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
376 gduche 87
	private Personne personneSelectionnee, personneSauvegarde = null;
276 gduche 88
 
376 gduche 89
 
90
	private FormBinding binding = null;
91
 
276 gduche 92
	/*--------------------------------------------------------------------------------------
93
	 * 		CONSTRUCTEUR
94
	 * -------------------------------------------------------------------------------------
95
	 */
96
	/**
97
	 * Constructeur du panneau
98
	 *
99
	 * Initialise le panneau et ajoute une barre d'outils à deux boutons (réinitialiser le
100
	 * formulaire et annuler la saisie).
101
	 *
102
	 * */
103
	public FormPersonneVue() {
352 gduche 104
		initialiserComposants(null);
105
	}
106
 
107
	public FormPersonneVue(Personne personne)	{
108
 
109
		initialiserComposants(personne);
110
	}
111
 
112
	public void initialiserComposants(Personne personne)	{
113
 
376 gduche 114
		personneSelectionnee = new Personne();
115
		personneSauvegarde = new Personne();
116
 
283 gduche 117
		initialiserPanneau();
276 gduche 118
 
356 gduche 119
		ButtonBar barreOutilsBas = new ButtonBar();
120
		barreOutilsBas.setButtonAlign(HorizontalAlignment.CENTER);
276 gduche 121
 
352 gduche 122
		ajouterBoutonEnregistrer(barreOutilsBas);
123
		ajouterBoutonEnregistrerEtRevenir(barreOutilsBas);
124
		ajouterBoutonAnnuler(barreOutilsBas);
276 gduche 125
 
352 gduche 126
		setBottomComponent(barreOutilsBas);
276 gduche 127
 
352 gduche 128
		ToolBar barreOutilsHaut = new ToolBar();
129
		ajouterBoutonReinitialiser(barreOutilsHaut);
130
		setTopComponent(barreOutilsHaut);
338 gduche 131
 
352 gduche 132
 
276 gduche 133
		initialiserOnglets();
134
 
135
		creerComposantsIdentite();
293 gduche 136
		creerComposantsAdresse();
280 gduche 137
 
352 gduche 138
		layout();
338 gduche 139
 
352 gduche 140
		rafraichir(personne);
376 gduche 141
		binderPersonne(personneSelectionnee);
142
 
276 gduche 143
	}
144
 
145
 
146
	/*---------------------------------------------------------------------------------------
147
	 * 		SOUS-METHODES
148
	 * --------------------------------------------------------------------------------------
149
	 */
150
	/**
151
	 * Inialise le panneau donné
152
	 *
153
	 * @param contentPanel le panneau à initialiser
154
	 * */
283 gduche 155
	public void initialiserPanneau()	{
276 gduche 156
 
376 gduche 157
 
283 gduche 158
		setIconStyle("icone-form-ajouter");
159
		setCollapsible(false);
160
		setHeading("Ajouter une personne");
161
		setButtonAlign(HorizontalAlignment.CENTER);
162
		setLayout(new FormLayout());
376 gduche 163
		setBodyBorder(false);
164
		setBorders(false);
165
 
166
 
167
		setPadding(0);
168
		setWidth("100%");
276 gduche 169
	}
170
 
171
	/**
172
	 * Crée les onglets identité, adresse et informations naturaliste
173
	 *
174
	 * */
175
	public void initialiserOnglets()	{
176
		//TabPanel
177
		TabPanel formulaireOnglets = new TabPanel();
376 gduche 178
		formulaireOnglets.setBodyBorder(true);
276 gduche 179
 
376 gduche 180
 
276 gduche 181
		//Tab 1 : identite
182
		tiIdentite = new TabItem("Identité");
183
		tiIdentite.setLayout(new FormLayout());
283 gduche 184
		tiIdentite.setScrollMode(Scroll.AUTO);
276 gduche 185
		formulaireOnglets.add(tiIdentite);
186
 
293 gduche 187
		hmIdentite.put("tiIdentite", tiIdentite);
276 gduche 188
 
283 gduche 189
 
276 gduche 190
		//Tab 2 : Adresse
191
		tiAdresses = new TabItem("Adresse");
304 gduche 192
		tiAdresses.setLayout(new FormLayout());
283 gduche 193
		tiAdresses.setScrollMode(Scroll.AUTO);
276 gduche 194
		formulaireOnglets.add(tiAdresses);
195
 
196
		//Tab 3 : Infos Naturalistes
197
		tiInfosNat = new TabItem("Informations Naturalistes");
198
		tiInfosNat.setLayout(new FormLayout());
283 gduche 199
		tiInfosNat.setScrollMode(Scroll.AUTO);
276 gduche 200
		formulaireOnglets.add(tiInfosNat);
201
 
202
		add(formulaireOnglets);
203
	}
204
 
205
	/**
206
	 * Crée les widgets pour l'onglet identité
207
	 *
208
	 * */
209
 
293 gduche 210
	//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite
276 gduche 211
	private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();
293 gduche 212
	private HashMap<String, Widget>hmAdresse = new HashMap<String, Widget>();
213
	private HashMap<String, Widget>hmInfosNat = new HashMap<String, Widget>();
319 gduche 214
	private FormData fd100 = new FormData("1");
276 gduche 215
 
216
	public void creerComposantsIdentite()	{
217
 
376 gduche 218
			// Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite
276 gduche 219
			LayoutContainer left = new LayoutContainer();
220
			left.setLayout(new FormLayout());
221
 
222
			LayoutContainer right = new LayoutContainer();
223
			right.setLayout(new FormLayout());
224
 
225
			LayoutContainer main = new LayoutContainer();
226
			main.setLayout(new ColumnLayout());
227
 
293 gduche 228
			main.add(left, new ColumnData(.49));
229
			main.add(right, new ColumnData(.49));
276 gduche 230
 
231
			// Création des champs
232
			FormLayout formLayout = new FormLayout();
233
			formLayout.setLabelAlign(LabelAlign.LEFT);
234
 
376 gduche 235
				FieldSet fsNoms = new FieldSet();
236
				fsNoms.setHeading("Noms");
237
				fsNoms.setLayout(formLayout);
276 gduche 238
 
376 gduche 239
					// Nom complet : Affiché que si valeurs saisies
240
					LabelField nomComplet = new LabelField();
241
					nomComplet.setFieldLabel("Nom complet:");
242
					nomComplet.hide();
243
 
244
					fsNoms.add(nomComplet);
245
					hmIdentite.put("nomComplet", nomComplet);
276 gduche 246
 
376 gduche 247
					//Préfixe
248
					ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
249
					ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
250
					cbPrefixe.setStore(storePrefixe);
251
					cbPrefixe.setDisplayField("nom");
252
					cbPrefixe.setEmptyText("Choisissez le préfixe:");
253
					cbPrefixe.setFieldLabel("Prefix");
254
 
255
 
256
					fsNoms.add(cbPrefixe);
257
					hmIdentite.put("cbPrefixe", cbPrefixe);
258
 
259
					mediateur.obtenirListeValeurEtRafraichir(this, "prefixe");
352 gduche 260
 
376 gduche 261
					//Prénom
262
					TextField<String> tfPrenom = new TextField<String>();
263
					tfPrenom.setFieldLabel("Prénom");
264
					tfPrenom.setName("prenom");
352 gduche 265
 
376 gduche 266
					fsNoms.add(tfPrenom);
267
					hmIdentite.put("tfPrenom", tfPrenom);
352 gduche 268
 
376 gduche 269
					//Nom
270
					TextField<String> tfNom = new TextField<String>();
271
					tfNom.setFieldLabel("Nom");
272
					tfNom.setName("nom");
273
 
274
					fsNoms.add(tfNom);
275
					hmIdentite.put("tfNom", tfNom);
276
 
352 gduche 277
 
376 gduche 278
					//Suffixe
279
					ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
280
					ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
281
					cbSuffixe.setStore(storeSuffixe);
282
					cbSuffixe.setFieldLabel("Suffixe");
283
					cbSuffixe.setDisplayField("nom");
284
					cbSuffixe.setEmptyText("Choisissez un suffixe:");
285
 
286
					fsNoms.add(cbSuffixe);
287
					hmIdentite.put("cbSuffixe", cbSuffixe);
288
 
289
					mediateur.obtenirListeValeurEtRafraichir(this, "suffixes");
352 gduche 290
 
376 gduche 291
 
292
					TextField<String> tfNomAutre = new TextField();
293
					tfNomAutre.setFieldLabel("Autres noms");
294
 
295
					fsNoms.add(tfNomAutre);
296
					hmIdentite.put("tfNomAutre", tfNomAutre);
297
 
298
					TextField<String> tfAbreviation = new TextField<String>();
299
					tfAbreviation.setFieldLabel("Abréviation");
300
					tfAbreviation.setName("abreviation");
301
 
302
					fsNoms.add(tfAbreviation);
303
					hmIdentite.put("tfAbreviation", tfAbreviation);
304
 
305
 
306
					//Abréviation autres
307
					TextField<String> tfAbreviationAutre = new TextField<String>();
308
					tfAbreviationAutre.setFieldLabel("Autres Abrév.");
309
					tfAbreviationAutre.setName("truk_abreviation_autre");
310
 
311
					fsNoms.add(tfAbreviationAutre);
312
					hmIdentite.put("tfAbreviationAutre", tfAbreviationAutre);
313
 
314
				left.add(fsNoms);
276 gduche 315
 
376 gduche 316
				formLayout = new FormLayout();
317
				formLayout.setLabelAlign(LabelAlign.LEFT);
276 gduche 318
 
283 gduche 319
 
376 gduche 320
				FieldSet fsNaissance = new FieldSet();
321
				fsNaissance.setHeading("Naissance");
322
				fsNaissance.setLayout(formLayout);
352 gduche 323
 
376 gduche 324
					DateField dfDateNaissance = new DateField();
325
					dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
326
					dfDateNaissance.setFieldLabel("Date");
327
					dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
328
 
329
					fsNaissance.add(dfDateNaissance);
330
					hmIdentite.put("dfDateNaissance", dfDateNaissance);
331
 
332
					// Lieu naissance
333
					TextField<String> tfLieuNaissance = new TextField();
334
					tfLieuNaissance.setFieldLabel("Lieu");
335
					tfLieuNaissance.setName("naissance_lieu");
336
 
337
					fsNaissance.add(tfLieuNaissance);
338
					hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
339
 
340
				left.add(fsNaissance);
276 gduche 341
 
376 gduche 342
				formLayout = new FormLayout();
343
				formLayout.setLabelAlign(LabelAlign.LEFT);
276 gduche 344
 
376 gduche 345
				FieldSet fsDeces = new FieldSet();
346
				fsDeces.setHeading("Décès");
347
				fsDeces.setLayout(formLayout);
276 gduche 348
 
376 gduche 349
					DateField dfDateDeces = new DateField();
350
					dfDateDeces.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
351
					dfDateDeces.setFormatValue(true);
352
					dfDateDeces.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
353
					dfDateDeces.setFieldLabel("Date");
276 gduche 354
 
376 gduche 355
					fsDeces.add(dfDateDeces);
356
					hmIdentite.put("dfDateDeces", dfDateDeces);
357
 
358
 
359
					TextField<String> tfLieuDeces = new TextField();
360
					tfLieuDeces.setFieldLabel("Lieu");
361
					tfLieuDeces.setName("deces_lieu");
362
 
363
					fsDeces.add(tfLieuDeces);
364
					hmIdentite.put("tfLieuDeces", tfLieuDeces);
365
 
366
				left.add(fsDeces);
276 gduche 367
 
376 gduche 368
			tiIdentite.add(main);
283 gduche 369
 
376 gduche 370
				FieldSet fsContactTel = new FieldSet();
371
				fsContactTel.setHeading("Contact - Téléphones");
372
				fsContactTel.setLayout(new RowLayout());
373
 
374
				right.add(fsContactTel);
375
				hmIdentite.put("fsContactTel", fsContactTel);
376
 
377
					LayoutContainer lcTelephone = new LayoutContainer();
378
					lcTelephone.setLayout(new ColumnLayout());
379
 
380
						TextField tfTelephone = new TextField();
381
						tfTelephone.setFieldLabel("tel");
382
						lcTelephone.add(tfTelephone, new ColumnData(0.40));
383
 
384
						hmIdentite.put("tfTelephone", tfTelephone);
385
 
386
						ListStore<Valeur> storeTel = new ListStore<Valeur>();
387
						ComboBox<Valeur> cbTelephone = new ComboBox<Valeur>();
388
						cbTelephone.setDisplayField("nom");
389
						cbTelephone.setEmptyText("Choisissez:");
390
						cbTelephone.setStore(storeTel);
391
 
392
						lcTelephone.add(cbTelephone, new ColumnData(0.40));
393
						hmIdentite.put("cbTelephone", cbTelephone);
283 gduche 394
 
376 gduche 395
						mediateur.obtenirListeValeurEtRafraichir(this, "tel");
276 gduche 396
 
376 gduche 397
						IconButton bAjouter = new IconButton(ComposantClass.ICONE_AJOUTER);
398
						bAjouter.addSelectionListener(
399
								new SelectionListener<ComponentEvent>() {
400
 
401
									public void componentSelected(ComponentEvent ce) {
402
 
403
										String strTelephone = ((TextField<String>) hmIdentite.get("tfTelephone")).getValue();
404
										if ((strTelephone==null)||(strTelephone.trim().equals("")))	{
405
											MessageBox.alert("Erreur de saisie", "Vous devez saisir un numéro de téléphone", null);
406
										} else if (hmIdentite.get("tel-" + strTelephone) != null){
407
											MessageBox.alert("Erreur de saisie", "Le numéro saisi est déjà présent dans la liste", null);
408
										} else {
409
 
410
												String strValeurTypeTel = "";
411
												String idTel = "";
412
												Valeur valeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getValue();
413
 
414
												if (valeurTypeTel != null)	{
415
													strValeurTypeTel = valeurTypeTel.getNom();
416
													idTel = valeurTypeTel.get("abreviation");
417
												}	else {
418
													strValeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getRawValue();
419
													idTel = strValeurTypeTel;
420
												}
421
 
422
 
423
												if (strValeurTypeTel.trim().equals(""))	{
424
													MessageBox.alert("Erreur de saisie", "Vous devez saisir un type de téléphone", null);
425
												}	else {
426
													ajouterTelephone(strTelephone, strValeurTypeTel, idTel);
427
												}
428
											}
429
										}
430
									}
431
								);
276 gduche 432
 
376 gduche 433
						lcTelephone.add(bAjouter, new ColumnData(0.15));
434
 
435
						HiddenField<String> hfTelephone = new HiddenField<String>();
436
						add(hfTelephone);
437
						hmIdentite.put("hfTelephone", hfTelephone);
438
 
439
					fsContactTel.add(lcTelephone);
276 gduche 440
 
441
 
376 gduche 442
					FieldSet fsContact = new FieldSet();
443
					fsContact.setHeading("Contact - Autres");
444
					fsContact.setId("fsContact");
445
					fsContact.setLayout(new RowLayout());
276 gduche 446
 
376 gduche 447
					right.add(fsContact);
448
					hmIdentite.put("fsContact", fsContact);
276 gduche 449
 
376 gduche 450
 
451
					LabelField lfCourriel = new LabelField();
452
					lfCourriel.setText("<b>Courriels:</b>");
276 gduche 453
 
376 gduche 454
					fsContact.add(lfCourriel);
276 gduche 455
 
456
 
376 gduche 457
					LayoutContainer lcCourriel = new LayoutContainer();
458
					lcCourriel.setLayout(new ColumnLayout());
276 gduche 459
 
376 gduche 460
						TextField tfCourriel = new TextField();
461
						lcCourriel.add(tfCourriel, new ColumnData(0.80));
462
 
463
						HiddenField hfHiddenCourriel = new HiddenField();
464
						hfHiddenCourriel.setId("tfHiddenCourriel");
465
						hfHiddenCourriel.setValue("");
466
						add(hfHiddenCourriel);
467
						hmIdentite.put("hfHiddenCourriel", hfHiddenCourriel);
468
 
469
						//tfHiddenCourriel.setVisible(true);
470
 
471
 
472
 
473
						hmIdentite.put("tfCourriel", tfCourriel);
276 gduche 474
 
376 gduche 475
						IconButton bAjouterCourriel = new IconButton(ComposantClass.ICONE_AJOUTER);
476
						bAjouterCourriel.addSelectionListener(
477
								new SelectionListener<ComponentEvent>() {
478
 
479
									public void componentSelected(ComponentEvent ce) {
480
 
481
										String strEmail = ((TextField<String>) hmIdentite.get("tfCourriel")).getValue();
482
 
483
										if ((strEmail==null)||(strEmail.trim().equals("")))	{
484
											MessageBox.alert("Erreur de saisie", "Vous devez saisir une adresse", null);
485
										} else if (hmIdentite.get("email-" + strEmail) != null){
486
											MessageBox.alert("Erreur de saisie", "L'adresse saisie est déjà dans la liste", null);
487
										} else {
488
 
489
											if (!strEmail.matches("(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*"))	{
490
												MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: me@domain.com)", null);
491
											} else if (strEmail.length()>255){
492
												MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
493
											} else {
494
												ajouterCourriel(strEmail);
495
											}
496
 
497
										}
498
 
499
 
500
									}
501
								});
276 gduche 502
 
376 gduche 503
						lcCourriel.add(bAjouterCourriel, new ColumnData(0.15));
504
 
505
					fsContact.add(lcCourriel);
276 gduche 506
 
376 gduche 507
					LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout());
508
 
509
					fsContact.add(lcCourrielContainer);
510
					hmIdentite.put("lcCourrielContainer", lcCourrielContainer);
280 gduche 511
 
376 gduche 512
 
513
					LabelField lfUrl = new LabelField();
514
					lfUrl.setText("<b>Sites Web:</b>");
515
 
516
					fsContact.add(lfUrl);
280 gduche 517
 
376 gduche 518
					LayoutContainer lcUrl = new LayoutContainer(new ColumnLayout());
519
					hmIdentite.put("lcUrl", lcUrl);
286 gduche 520
 
376 gduche 521
						TextField tfUrl = new TextField();
522
						tfUrl.setValue("http://");
286 gduche 523
 
376 gduche 524
						lcUrl.add(tfUrl, new ColumnData(0.8));
525
						hmIdentite.put("tfUrl", tfUrl);
286 gduche 526
 
376 gduche 527
						IconButton ibAjouterUrl = new IconButton(ComposantClass.ICONE_AJOUTER);
528
						ibAjouterUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
529
 
530
							public void componentSelected(ComponentEvent ce) {
293 gduche 531
 
376 gduche 532
								TextField<String> tfUrl = (TextField) hmIdentite.get("tfUrl");
533
								String strUrl = tfUrl.getValue();
293 gduche 534
 
376 gduche 535
								if ((strUrl == null)||(strUrl.trim().equals("http://"))||(strUrl.trim().equals("")))	{
536
									MessageBox.alert("Erreur de saisie", "Vous devez saisir un URL", null);
537
								} else if(hmIdentite.get("url-" + strUrl) != null)	{
538
									MessageBox.alert("Erreur de saisie", "L'url est déjà présente dans la liste.", null);
539
								}	else	{
540
									tfUrl.setValue("");
541
										if (!strUrl.matches("[a-z]{3,}://[a-z0-9-]+.[.a-z0-9-]+(?::[0-9]*)?"))	{
542
											MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: http://www.domain.com)", null);
543
										} else if (strUrl.length()>255){
544
											MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
545
										} else {
546
											ajouterUrl(strUrl);
547
										}
548
 
293 gduche 549
								}
550
 
551
							}
376 gduche 552
						});
286 gduche 553
 
376 gduche 554
						lcUrl.add(ibAjouterUrl, new ColumnData(0.15));
555
					fsContact.add(lcUrl);
286 gduche 556
 
376 gduche 557
					LayoutContainer lcUrlContainer = new LayoutContainer(new RowLayout());
558
 
559
					fsContact.add(lcUrlContainer);
560
					hmIdentite.put("lcUrlContainer", lcUrlContainer);
561
 
562
					FieldSet fsAutresInfos = new FieldSet();
563
					fsAutresInfos.setHeading("Autres informations");
286 gduche 564
 
376 gduche 565
					formLayout = new FormLayout();
566
					formLayout.setLabelAlign(LabelAlign.LEFT);
567
					fsAutresInfos.setLayout(formLayout);
286 gduche 568
 
376 gduche 569
 
570
				//Civilité
571
				ListStore<Valeur> storeSexe = new ListStore<Valeur>();
572
				ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
573
				cbSexe.setStore(storeSexe);
574
				cbSexe.setFieldLabel("Sexe");
575
				cbSexe.setDisplayField("nom");
576
				cbSexe.setEmptyText("Choisissez le sexe:");
356 gduche 577
 
376 gduche 578
				fsAutresInfos.add(cbSexe, fd100);
579
				hmIdentite.put("cbSexe", cbSexe);
356 gduche 580
 
376 gduche 581
				mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
356 gduche 582
 
293 gduche 583
			//Description
584
			TextArea taDescription = new TextArea();
585
			taDescription.setEmptyText("Saisissez une description");
586
			taDescription.setFieldLabel("Description");
319 gduche 587
			taDescription.setWidth("100%");
376 gduche 588
			taDescription.setName("description");
319 gduche 589
			fsAutresInfos.add(taDescription, fd100);
293 gduche 590
 
591
			hmIdentite.put("taDescription", taDescription);
592
 
376 gduche 593
 
293 gduche 594
			// Logo
595
			TextArea taLogo = new TextArea();
596
			taLogo.setFieldLabel("Logos");
319 gduche 597
			taLogo.setWidth("100%");
293 gduche 598
			taLogo.setEmptyText("Saisissez les adresses des logos séparées par un saut de ligne");
319 gduche 599
			fsAutresInfos.add(taLogo, fd100);
293 gduche 600
 
601
			hmIdentite.put("taLogo", taLogo);
602
 
376 gduche 603
			right.add(fsAutresInfos);
293 gduche 604
 
276 gduche 605
			// Ajout des évènements saisi
606
			KeyListener klNoms = new KeyListener()	{
607
				public void componentKeyUp(ComponentEvent ev)	{
283 gduche 608
					rafraichir(null);
280 gduche 609
				}
276 gduche 610
			};
611
 
283 gduche 612
			SelectionChangedListener<InterneValeur> selectionChange = new SelectionChangedListener<InterneValeur>() {
613
				public void selectionChanged(SelectionChangedEvent se) {
614
						rafraichir(null);
615
					}
616
			};
617
 
319 gduche 618
			cbPrefixe.addSelectionChangedListener(selectionChange);
619
			cbPrefixe.addKeyListener(klNoms);
276 gduche 620
			tfPrenom.addKeyListener(klNoms);
621
			tfNom.addKeyListener(klNoms);
283 gduche 622
			cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 623
 
624
	}
625
 
293 gduche 626
	public void creerComposantsAdresse()	{
627
 
628
		// Gauche
629
		LayoutContainer left = new LayoutContainer();
630
		left.setLayout(new FormLayout());
631
 
632
		// Droite
633
		LayoutContainer right = new LayoutContainer();
634
		right.setLayout(new FormLayout());
635
 
636
		// Principal
637
		LayoutContainer main = new LayoutContainer();
638
		main.setLayout(new ColumnLayout());
639
 
640
		// Ajout au principal
641
		main.add(left, new ColumnData(.49));
642
		main.add(right, new ColumnData(.49));
643
 
644
		TextField<String> tfAdresse1 = new TextField();
645
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 646
		tfAdresse1.setName("adresse_01");
319 gduche 647
		left.add(tfAdresse1, fd100);
293 gduche 648
		hmAdresse.put("tfAdresse1", tfAdresse1);
649
 
650
		TextField<String> tfAdresse2 = new TextField();
651
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 652
		tfAdresse2.setName("adresse_02");
319 gduche 653
		left.add(tfAdresse2, fd100);
293 gduche 654
		hmAdresse.put("tfAdresse2", tfAdresse2);
655
 
656
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
657
		cbPays.setFieldLabel("Pays");
658
		cbPays.setDisplayField("nom");
659
		cbPays.setEmptyText("Sélectionnez le pays:");
660
 
661
		ListStore<Valeur> storePays = new ListStore<Valeur>();
662
		cbPays.setStore(storePays);
663
 
319 gduche 664
		right.add(cbPays, fd100);
293 gduche 665
		hmAdresse.put("cbPays", cbPays);
666
 
667
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
668
			public void selectionChanged(SelectionChangedEvent se) {
669
					// Rafraichir avec le pays sélectionné
670
					obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
671
 
672
				}
673
		};
674
 
675
		cbPays.addSelectionChangedListener(selectionChange);
676
 
677
 
678
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
679
		cbRegion.setFieldLabel("Region");
680
		cbRegion.setDisplayField("nom");
681
		cbRegion.setEmptyText("Sélectionnez la région:");
682
		cbRegion.setVisible(false);
683
 
684
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
685
		cbRegion.setStore(storeRegion);
686
 
352 gduche 687
 
319 gduche 688
		right.add(cbRegion, fd100);
293 gduche 689
		hmAdresse.put("cbRegion", cbRegion);
690
 
691
		TextField<String> tfBoitePostale = new TextField<String>();
692
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 693
		tfBoitePostale.setName("bp");
694
 
319 gduche 695
		left.add(tfBoitePostale, fd100);
293 gduche 696
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
697
 
698
		TextField<Integer> tfCodePostal = new TextField<Integer>();
699
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 700
		tfCodePostal.setName("code_postal");
701
 
319 gduche 702
		right.add(tfCodePostal, fd100);
293 gduche 703
		hmAdresse.put("tfCodePostal", tfCodePostal);
704
 
705
		TextField tfVille = new TextField();
706
		tfVille.setFieldLabel("Ville");
376 gduche 707
		tfVille.setName("ville");
293 gduche 708
 
319 gduche 709
		right.add(tfVille, fd100);
293 gduche 710
		hmAdresse.put("tfVille", tfVille);
711
 
712
		// MAJ ComboBox
713
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
714
 
304 gduche 715
		FieldSet fsAdresse = new FieldSet();
716
		fsAdresse.setHeading("Adresse personnelle");
717
		fsAdresse.add(main);
293 gduche 718
 
304 gduche 719
		tiAdresses.add(fsAdresse);
720
 
352 gduche 721
		((ComboBox) hmIdentite.get("cbPrefixe")).setRawValue("ljkhlkj");
722
 
723
 
293 gduche 724
	}
338 gduche 725
 
276 gduche 726
	/**
727
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
728
	 *
729
	 * @param barreOutils la barre d'outils à modifier
730
	 * */
376 gduche 731
	public void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
276 gduche 732
 
733
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
352 gduche 734
		TextToolItem reinitialiser = new TextToolItem("Réinitialiser le formulaire");
276 gduche 735
		reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
736
		reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
737
			public void componentSelected(ComponentEvent ce) {
376 gduche 738
				//((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
739
				reinitialiser();
740
				//System.out.println(personneSelectionnee);
276 gduche 741
			}
742
		});
743
		barreOutils.add(reinitialiser);
744
	}
745
 
746
	/**
338 gduche 747
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
748
	 *
749
	 * @param barreOutils la barre d'outils à modifier
750
	 * */
356 gduche 751
	public static void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils)	{
338 gduche 752
 
753
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
356 gduche 754
		Button enregistrer = new Button("Enregistrer et revenir à la liste");
338 gduche 755
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
756
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
757
			public void componentSelected(ComponentEvent ce) {
758
				// TODO : Enregistrer le formulaire
759
			}
760
		});
761
		barreOutils.add(enregistrer);
762
	}
763
 
764
	/**
276 gduche 765
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
766
	 *
767
	 * @param barreOutils la barre d'outils à modifier
768
	 * */
376 gduche 769
	public void ajouterBoutonEnregistrer(ButtonBar barreOutils)	{
276 gduche 770
 
771
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
356 gduche 772
		Button enregistrer = new Button("Enregistrer");
286 gduche 773
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
352 gduche 774
		enregistrer.setId("main-button");
286 gduche 775
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
276 gduche 776
			public void componentSelected(ComponentEvent ce) {
376 gduche 777
				enregistrer();
778
 
779
 
276 gduche 780
			}
781
		});
286 gduche 782
		barreOutils.add(enregistrer);
276 gduche 783
	}
784
 
785
	/**
786
	 * Ajouter le bouton annuler à la barre d'outils donnée
787
	 *
788
	 * @param barreOutils la barre d'outils à modifier
789
	 * */
356 gduche 790
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 791
 
792
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 793
		Button annuler = new Button("Revenir à la liste");
276 gduche 794
		annuler.addSelectionListener(new SelectionListener<ComponentEvent>() {
795
			public void componentSelected(ComponentEvent ce) {
796
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
797
			}
798
		});
799
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
800
		barreOutils.add(annuler);
801
	}
802
 
293 gduche 803
	public void obtenirListeRegionParPays(String strPays)	{
804
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
805
	}
276 gduche 806
 
807
 
293 gduche 808
 
276 gduche 809
	/*---------------------------------------------------------------------------------------
810
	 * 		RAFRAICHISSEMENT DU PANNEAU
811
	 * --------------------------------------------------------------------------------------
812
	 */
283 gduche 813
	public void rafraichir(Object nouvellesDonnees) {
814
		if (nouvellesDonnees instanceof ValeurListe){
815
 
816
 
817
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
818
 
819
			// Créer une liste de valeurs
820
			List<Valeur> liste = new ArrayList<Valeur>();
821
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
822
				liste.add(listeValeurs.get(it.next()));
823
			}
824
 
825
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
826
 
319 gduche 827
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 828
 
829
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
830
 
831
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
832
 
833
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
834
 
835
				remplirCombobox("cbSexe", liste, "hmIdentite");
283 gduche 836
 
293 gduche 837
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
838
 
839
				remplirCombobox("cbTelephone", liste, "hmIdentite");
319 gduche 840
 
841
				//Préselection du tél
842
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
843
				cbTelephone.setValue(liste.get(1));
293 gduche 844
 
845
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
283 gduche 846
 
293 gduche 847
				remplirCombobox("cbPays", liste, "hmAdresse");
283 gduche 848
 
293 gduche 849
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
283 gduche 850
 
293 gduche 851
				remplirCombobox("cbRegion", liste, "hmAdresse");
283 gduche 852
 
293 gduche 853
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 854
			}
293 gduche 855
 
856
 
352 gduche 857
		} else if (nouvellesDonnees instanceof Information)	{
286 gduche 858
 
376 gduche 859
 
352 gduche 860
			Information info = (Information) nouvellesDonnees;
286 gduche 861
 
352 gduche 862
			if (info.getDonnee(0) instanceof PersonneListe)	{
286 gduche 863
 
352 gduche 864
				Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
865
				Iterator itPersonneListe = colPersonneListe.iterator();
866
				Personne personne = (Personne) itPersonneListe.next();
867
 
376 gduche 868
				personneSauvegarde = new Personne();
869
				personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
870
 
871
 
872
 
873
				binderPersonne(personne);
352 gduche 874
				//Mise à jour de la personne
875
				//Personne personne = (Personne) nouvellesDonnees;
876
 
376 gduche 877
 
878
 
352 gduche 879
				//Prefixe
880
				String prefixe = personne.get("ce_truk_prefix");
881
				ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
882
 
376 gduche 883
 
352 gduche 884
				String prefixeCourant = personne.get("ce_truk_prefix");
376 gduche 885
				if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
886
					cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
352 gduche 887
				}	else	{
888
					cbPrefixe.setRawValue(prefixeCourant);
889
				}
890
 
891
 
892
				((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
893
				((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
894
 
895
				//Suffixe
896
				String suffixe = personne.get("ce_truk_suffixe");
897
				ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
898
 
899
				String suffixeCourant = personne.get("ce_truk_suffix");
376 gduche 900
				if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
901
					cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
352 gduche 902
				}	else	{
903
					cbSuffixe.setRawValue(suffixeCourant);
904
				}
905
 
906
				((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
907
				((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
908
				((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
909
 
910
 
911
				(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
912
				((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
913
 
914
				(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
915
				((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
916
 
917
				// Telephone
918
				HashMap<String, String> hmTelephone = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
376 gduche 919
				if (hmTelephone!=null)	{
920
 
921
 
922
					ListStore storeTelephone = ((ComboBox) hmIdentite.get("cbTelephone")).getStore();
923
					List lstModelsTelephone = storeTelephone.getModels();
924
					Iterator<Valeur> itStore = lstModelsTelephone.iterator();
925
					HashMap<String, String> hmTel = new HashMap();
926
					while (itStore.hasNext())	{
927
						Valeur v = itStore.next();
928
						hmTel.put(v.getAbreviation(), v.getNom());
929
					}
930
 
931
 
932
					Collection<String> colTelephone = hmTelephone.keySet();
933
					Iterator<String> itTelephone = colTelephone.iterator();
352 gduche 934
 
376 gduche 935
					while (itTelephone.hasNext())	{
936
						String strTypeTelephone = itTelephone.next();
937
						String strTelephone = hmTelephone.get(strTypeTelephone);
938
						String idTel = hmTel.get(strTypeTelephone);
939
						if (idTel == null)	{
940
							idTel = strTypeTelephone;
941
						}
942
 
943
						ajouterTelephone(strTelephone, idTel, strTypeTelephone);
944
					}
352 gduche 945
				}
946
 
947
				//Courriel
948
				LinkedList<String> lCourriels = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
949
				Iterator<String> itCourriels = lCourriels.iterator();
950
 
951
				while (itCourriels.hasNext())	{
376 gduche 952
					String strEmail = itCourriels.next();
953
					ajouterCourriel(strEmail);
352 gduche 954
				}
955
 
956
				// Sites
957
				LinkedList<String> lUrl = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_url");
958
				Iterator<String> itUrl = lUrl.iterator();
959
 
376 gduche 960
 
352 gduche 961
				while (itUrl.hasNext())	{
376 gduche 962
					String strUrl = itUrl.next();
963
					ajouterUrl(strUrl);
352 gduche 964
				}
965
 
966
				// Sexe
967
				String strSexe = personne.get("ce_sexe");
968
				ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
969
 
970
 
971
				//FIXME : le lien avec la bdd ne peut pas se faire
972
				if (cbSexe.getStore().findModel("abreviation", strSexe) != null)	{
973
					cbSexe.setValue(cbSexe.getStore().findModel("abreviation", strSexe));
974
				}	else	{
975
					cbSexe.setRawValue(strSexe);
976
				}
977
 
978
				((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
979
 
980
				// Logos
981
				TextArea taLogo = (TextArea) hmIdentite.get("taLogo");
982
				LinkedList<String> lLogo = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
983
				Iterator<String> itLogo = lLogo.iterator();
984
 
985
				String strValeurLogo = "";
986
				while (itLogo.hasNext())	{
987
					strValeurLogo += itLogo.next() + "\n";
988
				}
989
 
990
				if (!strValeurLogo.trim().equals(""))	{
991
					taLogo.setRawValue(strValeurLogo);
992
				}
993
 
994
 
995
				/*--------------------------------------------------
996
				                      Adresse
997
				 ---------------------------------------------------*/
998
 
999
				// Adresse
1000
				((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
1001
 
1002
				// Complément
1003
				((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
1004
 
1005
				//Boite postale
1006
				((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
1007
 
1008
				//Pays
1009
				String strPays = personne.get("pays");
1010
				ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
1011
 
1012
 
1013
				if (cbPays.getStore().findModel("nom", strPays) != null)	{
1014
					cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
1015
				}	else	{
1016
					cbPays.setRawValue(strPays);
1017
				}
1018
 
1019
 
1020
				//Région
1021
				String strRegion = personne.get("region");
1022
				if ((strRegion!=null)&&(!strRegion.equals("")))	{
1023
					ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
1024
					cbRegion.setVisible(true);
1025
 
1026
					if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
1027
						cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
1028
					}	else	{
1029
						cbRegion.setRawValue(strRegion);
1030
					}
1031
				}
1032
 
1033
				//Cp
1034
				((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
1035
 
1036
				//Ville
1037
				((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
376 gduche 1038
 
1039
 
352 gduche 1040
			}
293 gduche 1041
		}
283 gduche 1042
 
1043
		if (nouvellesDonnees == null)
1044
		{
319 gduche 1045
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 1046
 
1047
			//Met à jour le nom Complet du formulaire
283 gduche 1048
			String valeurRetour = "";
1049
 
1050
			// Prefixe
1051
			String prefixe = "";
319 gduche 1052
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 1053
 
1054
			if (valPrefixe != null)	{
1055
				prefixe = valPrefixe.getNom();
293 gduche 1056
			} else 	{
319 gduche 1057
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 1058
			}
283 gduche 1059
 
293 gduche 1060
 
283 gduche 1061
			// Prénom
1062
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
1063
 
1064
			// Nom
1065
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
1066
 
1067
			// Suffixe
1068
			String suffixe = "";
1069
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
1070
 
1071
			if (valSuffixe != null)	{
1072
				suffixe = valSuffixe.getNom();
293 gduche 1073
			} else 	{
1074
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 1075
			}
1076
 
1077
			// Mettre à jour la valeur
1078
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
1079
			valeurRetour = valeurRetour.replaceAll("null", "");
1080
 
1081
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
1082
 
1083
			if (!valeurRetour.trim().equals(""))	{
1084
				((LabelField) hmIdentite.get("nomComplet")).show();
1085
			} else {
1086
				((LabelField) hmIdentite.get("nomComplet")).hide();
1087
			}
1088
		}
338 gduche 1089
 
1090
		mediateur.masquerPopinChargement();
127 gduche 1091
	}
1092
 
352 gduche 1093
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
293 gduche 1094
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
352 gduche 1095
 
293 gduche 1096
		HashMap hm = null;
1097
		if (hashMapId.equals("hmIdentite"))	{
1098
			hm = hmIdentite;
1099
		} else if (hashMapId.equals("hmAdresse")){
1100
			hm = hmAdresse;
1101
		} else {
1102
			hm = hmInfosNat;
1103
		}
1104
 
1105
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1106
 
293 gduche 1107
		store.removeAll();
1108
		store.add(liste);
1109
		((ComboBox) hm.get(idComboBox)).setStore(store);
376 gduche 1110
 
293 gduche 1111
	}
130 gduche 1112
 
352 gduche 1113
 
376 gduche 1114
	public void ajouterTelephone(String strTelephone, String strValeurTypeTel, String idTel) 	{
352 gduche 1115
 
1116
 
1117
				//Ajout d'un champ à la liste
376 gduche 1118
				String strIdTelephone =  idTel + "##" + strTelephone + ";;";
352 gduche 1119
 
1120
				FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1121
 
356 gduche 1122
				LayoutContainer lcTelephone = new LayoutContainer();
1123
				lcTelephone.setLayout(new ColumnLayout());
1124
 
352 gduche 1125
				Text tTypeTelephone = new Text();
1126
				tTypeTelephone.setText(strValeurTypeTel+":");
1127
 
376 gduche 1128
				hmIdentite.put("type-" + strIdTelephone, tTypeTelephone);
356 gduche 1129
				lcTelephone.add(tTypeTelephone, new ColumnData(0.40));
352 gduche 1130
 
1131
				Text tTelephone = new Text();
1132
				tTelephone.setText(strTelephone);
376 gduche 1133
				hmIdentite.put("tel-" + strIdTelephone, tTelephone);
356 gduche 1134
				lcTelephone.add(tTelephone, new ColumnData(0.40));
352 gduche 1135
 
1136
				IconButton bSupprimer = new IconButton(ComposantClass.ICONE_SUPPRIMER);
376 gduche 1137
				bSupprimer.setId(strIdTelephone);
352 gduche 1138
 
1139
				bSupprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
1140
						public void componentSelected(ComponentEvent ce) {
1141
 
376 gduche 1142
							String strIdTelephone = ce.component.getId();
1143
							LayoutContainer lcContactTel = (LayoutContainer) hmIdentite.get("lc-"+strIdTelephone);
352 gduche 1144
 
376 gduche 1145
							lcContactTel.remove(hmIdentite.get("type-" + strIdTelephone));
1146
							hmIdentite.remove("type-" + strIdTelephone);
352 gduche 1147
 
376 gduche 1148
							lcContactTel.remove(hmIdentite.get("tel-" + strIdTelephone));
1149
							hmIdentite.remove("tel-" + strIdTelephone);
352 gduche 1150
 
356 gduche 1151
							lcContactTel.remove(ce.component);
352 gduche 1152
 
356 gduche 1153
							FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1154
							fsContactTel.remove(lcContactTel);
1155
 
376 gduche 1156
							HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1157
							String strValeurTelephone = hfTelephone.getValue();
1158
							strValeurTelephone = strValeurTelephone.replace(strIdTelephone, "");
1159
							hfTelephone.setValue(strValeurTelephone);
1160
 
352 gduche 1161
							layout();
1162
 
1163
						}
1164
				});
1165
 
356 gduche 1166
				lcTelephone.add(bSupprimer, new ColumnData(0.15));
352 gduche 1167
 
376 gduche 1168
				hmIdentite.put("lc-"+strIdTelephone, lcTelephone);
356 gduche 1169
				fsContactTel.add(lcTelephone);
1170
 
376 gduche 1171
				HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1172
				String strValeurTelephone = hfTelephone.getValue();
1173
				if (strValeurTelephone==null)	{
1174
					strValeurTelephone = "";
1175
				}
1176
				strValeurTelephone += strIdTelephone;
1177
				hfTelephone.setValue(strValeurTelephone);
352 gduche 1178
 
1179
				layout();
1180
 
1181
 
1182
 
1183
 
1184
	}
1185
 
376 gduche 1186
	public void ajouterCourriel(String strEmail)	{
1187
 
1188
			TextField<String> tfCourriel = (TextField<String>) hmIdentite.get("tfCourriel");
1189
			tfCourriel.setValue("");
1190
 
1191
			//Ajouter adresse email
1192
			LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1193
 
1194
			LayoutContainer lcCourriel = new LayoutContainer();
1195
			lcCourriel.setLayout(new ColumnLayout());
1196
 
1197
			LabelField lfCourriel = new LabelField();
1198
			lfCourriel.setText(strEmail);
1199
 
1200
			lcCourriel.add(lfCourriel, new ColumnData(0.8));
1201
			hmIdentite.put("lc-" + strEmail, lcCourriel);
1202
 
1203
			//Bouton supprimer
1204
			IconButton btnSupprimerCourriel = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1205
			btnSupprimerCourriel.setId(strEmail);
1206
			btnSupprimerCourriel.addSelectionListener(new SelectionListener<ComponentEvent>() {
1207
 
1208
				public void componentSelected(ComponentEvent ce) {
1209
					//Suppression de l'adresse email
1210
					String strEmail = ce.component.getId();
1211
					LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1212
					LayoutContainer lcCourriel = (LayoutContainer) hmIdentite.get("lc-" + strEmail);
1213
					lcCourrielContainer.remove(lcCourriel);
1214
 
1215
					hmIdentite.remove("lc-" + strEmail);
1216
					hmIdentite.remove("email-" + strEmail);
1217
 
1218
						HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1219
					String strValeurCourriel = hfHiddenCourriel.getValue();
1220
					strValeurCourriel = strValeurCourriel.replace(strEmail + ";;", "");
1221
					hfHiddenCourriel.setValue(strValeurCourriel);
1222
 
1223
				}
1224
 
1225
			});
1226
 
1227
			lcCourriel.add(btnSupprimerCourriel);
1228
 
1229
 
1230
 
1231
			lcCourrielContainer.add(lcCourriel);
1232
			hmIdentite.put("email-" + strEmail, lfCourriel);
1233
 
1234
			HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1235
			String strHiddenCourrielValue = hfHiddenCourriel.getValue();
1236
			if (strHiddenCourrielValue == null) {
1237
				strHiddenCourrielValue = "";
1238
			}
1239
			hfHiddenCourriel.setRawValue(strHiddenCourrielValue + strEmail + ";;");
1240
 
1241
 
1242
			layout();
1243
 
1244
	}
1245
 
1246
	public void ajouterUrl(String strUrl)	{
1247
 
1248
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1249
 
1250
		LayoutContainer lcUrl = new LayoutContainer();
1251
		lcUrl.setLayout(new ColumnLayout());
1252
		hmIdentite.put("lc-" + strUrl, lcUrl);
1253
 
1254
 
1255
		Text tUrl = new Text(strUrl);
1256
		hmIdentite.put("url-"+strUrl, tUrl);
1257
 
1258
		lcUrl.add(tUrl, new ColumnData(0.8));
1259
 
1260
		IconButton ibSupprimerUrl = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1261
		ibSupprimerUrl.setId(strUrl);
1262
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
130 gduche 1263
 
376 gduche 1264
			public void componentSelected(ComponentEvent ce) {
1265
 
1266
				//Suppression url
1267
				String strUrl = ce.component.getId();
1268
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1269
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1270
 
1271
				lcUrlContainer.remove(lcUrl);
1272
 
1273
			}
1274
		});
1275
 
1276
		lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
1277
		lcUrlContainer.add(lcUrl);
1278
 
1279
		layout();
1280
 
1281
 
1282
 
1283
	}
1284
 
1285
	public void reinitialiser()	{
1286
 
1287
		mediateur.afficherPopinChargement();
1288
 
1289
 
1290
		binderPersonne(personneSauvegarde);
1291
 
1292
 
1293
		layout();
1294
 
1295
		mediateur.masquerPopinChargement();
1296
	}
1297
 
1298
 
1299
 
1300
	public void binderPersonne(Personne personne)	{
1301
 
1302
		binding = new FormBinding(this);
1303
 
1304
		personneSelectionnee = personne;
1305
		binding.autoBind();
1306
		binding.bind(personneSelectionnee);
1307
 
1308
		layout();
1309
	}
130 gduche 1310
 
376 gduche 1311
	/**
1312
	 * Enregistre les information de la personne en cours
1313
	 *
1314
	 */
1315
	public void enregistrer()	{
1316
 
1317
		LinkedList lstMessageErreur = new LinkedList<String>();
1318
 
1319
		//Préparer les données
1320
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1321
		Valeur valeur;
1322
		String strValeur = "";
1323
 
1324
		if (combo.getValue()!=null)	{
1325
			valeur = (Valeur) combo.getValue();
1326
			strValeur = valeur.getId();
1327
		}
1328
 
1329
		if (!strValeur.trim().equals(""))	{
1330
			personneSelectionnee.set("sexe", strValeur);
1331
		} else {
1332
			lstMessageErreur.add("Le champ Sexe n'a pas été renseigné");
1333
		}
1334
 
1335
		strValeur = obtenirValeurCombo("cbPrefixe");
1336
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1337
 
1338
		strValeur = obtenirValeurCombo("cbSuffixe");
1339
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1340
 
1341
		personneSelectionnee.set("truk_courriel", ((HiddenField<String>) hmIdentite.get("hfHiddenCourriel")).getValue());
1342
 
1343
		strValeur = personneSelectionnee.get("truk_prefix")
1344
					+ " " + personneSelectionnee.get("prenom")
1345
					+ " " + personneSelectionnee.get("nom")
1346
					+ " " + personneSelectionnee.get("truk_suffix");
1347
 
1348
		personneSelectionnee.set("fmt_nom_complet", strValeur);
1349
 
1350
		personneSelectionnee.set("naissance_date", (Date) ((DateField) hmIdentite.get("dfDateNaissance")).getValue());
1351
 
1352
 
1353
		strValeur = obtenirValeurCombo("cbPays");
1354
		personneSelectionnee.set("pays", strValeur);
1355
 
1356
		strValeur = obtenirValeurCombo("cbRegion");
1357
		personneSelectionnee.set("region", strValeur);
1358
 
1359
		personneSelectionnee.set("truk_telephone", ((HiddenField<String>) hmIdentite.get("hfTelephone")).getValue());
1360
 
1361
 
1362
		System.out.println(personneSelectionnee);
1363
 
1364
		//tel
1365
		//fax
1366
		//logo
1367
		//url
1368
 
1369
 
1370
	}
1371
 
1372
	private String obtenirValeurCombo(String strComboName)	{
1373
 
1374
		String strValeur = "";
1375
		Valeur valeur;
1376
 
1377
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1378
		if (combo == null)	{
1379
			combo = (ComboBox) hmAdresse.get(strComboName);
1380
		}
1381
		if (combo.getValue()!=null)	{
1382
			valeur = (Valeur) combo.getValue();
1383
			strValeur = valeur.getId();
1384
		} else {
1385
			strValeur = combo.getRawValue();
1386
		}
1387
 
1388
		return strValeur;
1389
	}
127 gduche 1390
}