Subversion Repositories eFlore/Applications.coel

Rev

Rev 304 | Rev 338 | 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;
286 gduche 4
import java.util.Date;
276 gduche 5
import java.util.HashMap;
283 gduche 6
import java.util.Iterator;
7
import java.util.List;
276 gduche 8
 
9
import org.tela_botanica.client.ComposantClass;
10
import org.tela_botanica.client.Mediateur;
11
import org.tela_botanica.client.RegistreId;
127 gduche 12
import org.tela_botanica.client.interfaces.Rafraichissable;
283 gduche 13
import org.tela_botanica.client.modeles.Configuration;
280 gduche 14
import org.tela_botanica.client.modeles.InterneValeur;
293 gduche 15
 
286 gduche 16
import org.tela_botanica.client.modeles.Personne;
280 gduche 17
import org.tela_botanica.client.modeles.Valeur;
283 gduche 18
import org.tela_botanica.client.modeles.ValeurListe;
127 gduche 19
 
276 gduche 20
 
21
import com.extjs.gxt.ui.client.Registry;
22
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
283 gduche 23
import com.extjs.gxt.ui.client.Style.Scroll;
276 gduche 24
import com.extjs.gxt.ui.client.event.ComponentEvent;
25
import com.extjs.gxt.ui.client.event.KeyListener;
280 gduche 26
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
27
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 28
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 29
import com.extjs.gxt.ui.client.store.ListStore;
276 gduche 30
import com.extjs.gxt.ui.client.widget.ContentPanel;
127 gduche 31
import com.extjs.gxt.ui.client.widget.LayoutContainer;
319 gduche 32
import com.extjs.gxt.ui.client.widget.MessageBox;
276 gduche 33
import com.extjs.gxt.ui.client.widget.TabItem;
34
import com.extjs.gxt.ui.client.widget.TabPanel;
293 gduche 35
import com.extjs.gxt.ui.client.widget.Text;
283 gduche 36
 
293 gduche 37
import com.extjs.gxt.ui.client.widget.button.Button;
319 gduche 38
import com.extjs.gxt.ui.client.widget.button.IconButton;
280 gduche 39
import com.extjs.gxt.ui.client.widget.form.ComboBox;
40
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 41
import com.extjs.gxt.ui.client.widget.form.FieldSet;
293 gduche 42
import com.extjs.gxt.ui.client.widget.form.HiddenField;
276 gduche 43
import com.extjs.gxt.ui.client.widget.form.LabelField;
286 gduche 44
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 45
import com.extjs.gxt.ui.client.widget.form.TextField;
46
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
47
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
48
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
319 gduche 49
import com.extjs.gxt.ui.client.widget.layout.FillData;
50
import com.extjs.gxt.ui.client.widget.layout.FitData;
276 gduche 51
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
52
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
319 gduche 53
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 54
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
293 gduche 55
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
276 gduche 56
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
57
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
283 gduche 58
import com.google.gwt.user.client.Window;
276 gduche 59
import com.google.gwt.user.client.ui.Widget;
127 gduche 60
 
61
 
276 gduche 62
 
63
public class FormPersonneVue extends ContentPanel implements Rafraichissable {
64
 
65
 
66
	/*--------------------------------------------------------------------------------------
67
	 * 		VARIABLES
68
	 * -------------------------------------------------------------------------------------
69
	 */
70
 
71
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
283 gduche 72
	private Mediateur mediateur = Registry.get(RegistreId.MEDIATEUR);
73
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
286 gduche 74
	private Personne personneSelectionnee = null;
276 gduche 75
 
76
	/*--------------------------------------------------------------------------------------
77
	 * 		CONSTRUCTEUR
78
	 * -------------------------------------------------------------------------------------
79
	 */
80
	/**
81
	 * Constructeur du panneau
82
	 *
83
	 * Initialise le panneau et ajoute une barre d'outils à deux boutons (réinitialiser le
84
	 * formulaire et annuler la saisie).
85
	 *
86
	 * */
87
	public FormPersonneVue() {
88
 
283 gduche 89
		initialiserPanneau();
276 gduche 90
 
91
		ToolBar barreOutils = new ToolBar();
92
 
93
		ajouterBoutonEnregistrer(barreOutils);
94
		ajouterBoutonReinitialiser(barreOutils);
95
		ajouterBoutonAnnuler(barreOutils);
96
 
97
		setTopComponent(barreOutils);
98
 
99
		initialiserOnglets();
100
 
101
		creerComposantsIdentite();
293 gduche 102
		creerComposantsAdresse();
280 gduche 103
 
276 gduche 104
	}
105
 
106
 
107
	/*---------------------------------------------------------------------------------------
108
	 * 		SOUS-METHODES
109
	 * --------------------------------------------------------------------------------------
110
	 */
111
	/**
112
	 * Inialise le panneau donné
113
	 *
114
	 * @param contentPanel le panneau à initialiser
115
	 * */
283 gduche 116
	public void initialiserPanneau()	{
276 gduche 117
 
283 gduche 118
		setLayout(new FitLayout());
119
		setIconStyle("icone-form-ajouter");
120
		setCollapsible(false);
121
		setHeading("Ajouter une personne");
122
		setButtonAlign(HorizontalAlignment.CENTER);
123
		setLayout(new FormLayout());
276 gduche 124
	}
125
 
126
	/**
127
	 * Crée les onglets identité, adresse et informations naturaliste
128
	 *
129
	 * */
130
	public void initialiserOnglets()	{
131
		//TabPanel
132
		TabPanel formulaireOnglets = new TabPanel();
133
 
134
		//Tab 1 : identite
135
		tiIdentite = new TabItem("Identité");
136
		tiIdentite.setLayout(new FormLayout());
283 gduche 137
		tiIdentite.setScrollMode(Scroll.AUTO);
276 gduche 138
		formulaireOnglets.add(tiIdentite);
139
 
293 gduche 140
		hmIdentite.put("tiIdentite", tiIdentite);
276 gduche 141
 
283 gduche 142
 
276 gduche 143
		//Tab 2 : Adresse
144
		tiAdresses = new TabItem("Adresse");
304 gduche 145
		tiAdresses.setLayout(new FormLayout());
283 gduche 146
		tiAdresses.setScrollMode(Scroll.AUTO);
276 gduche 147
		formulaireOnglets.add(tiAdresses);
148
 
149
		//Tab 3 : Infos Naturalistes
150
		tiInfosNat = new TabItem("Informations Naturalistes");
151
		tiInfosNat.setLayout(new FormLayout());
283 gduche 152
		tiInfosNat.setScrollMode(Scroll.AUTO);
276 gduche 153
		formulaireOnglets.add(tiInfosNat);
154
 
155
		add(formulaireOnglets);
156
	}
157
 
158
	/**
159
	 * Crée les widgets pour l'onglet identité
160
	 *
161
	 * */
162
 
293 gduche 163
	//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite
276 gduche 164
	private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();
293 gduche 165
	private HashMap<String, Widget>hmAdresse = new HashMap<String, Widget>();
166
	private HashMap<String, Widget>hmInfosNat = new HashMap<String, Widget>();
319 gduche 167
	private FormData fd100 = new FormData("1");
276 gduche 168
 
319 gduche 169
 
276 gduche 170
	public void creerComposantsIdentite()	{
171
 
283 gduche 172
		// Gestion de l'affichage en colonnes
276 gduche 173
			// On crée 3 Layout container : un principal, un pour la colonne de gauche, un pour la colonne de droite
174
 
175
			// Gauche
176
			LayoutContainer left = new LayoutContainer();
177
			left.setLayout(new FormLayout());
178
 
179
			// Droite
180
			LayoutContainer right = new LayoutContainer();
181
			right.setLayout(new FormLayout());
182
 
183
			// Principal
184
			LayoutContainer main = new LayoutContainer();
185
			main.setLayout(new ColumnLayout());
186
 
187
			// Ajout au principal
293 gduche 188
			main.add(left, new ColumnData(.49));
189
			main.add(right, new ColumnData(.49));
276 gduche 190
 
191
			// Création des champs
192
 
193
			//FormLayout sera utilisé à plusieurs reprises
194
			FormLayout formLayout = new FormLayout();
195
 
196
			FieldSet fsNoms = new FieldSet();
197
			fsNoms.setHeading("Noms");
198
 
199
			formLayout.setLabelAlign(LabelAlign.LEFT);
200
			fsNoms.setLayout(formLayout);
201
 
202
			// Nom complet
203
			// Affiché que si valeurs saisies
204
			LabelField nomComplet = new LabelField();
205
			nomComplet.setFieldLabel("Nom complet:");
206
			nomComplet.hide();
207
			fsNoms.add(nomComplet);
208
 
209
			hmIdentite.put("nomComplet", nomComplet);
210
 
211
			//Préfixe
319 gduche 212
			ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
280 gduche 213
			ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
319 gduche 214
			cbPrefixe.setStore(storePrefixe);
215
			cbPrefixe.setDisplayField("nom");
216
			cbPrefixe.setEmptyText("Choisissez le préfixe:");
217
			cbPrefixe.setFieldLabel("Prefix");
218
			fsNoms.add(cbPrefixe);
276 gduche 219
 
319 gduche 220
			hmIdentite.put("cbPrefixe", cbPrefixe);
276 gduche 221
 
283 gduche 222
			// Remplir la liste des préfixe
223
			mediateur.obtenirListeValeurEtRafraichir(this, "prefixe");
224
 
276 gduche 225
			//Prénom
226
			TextField<String> tfPrenom = new TextField<String>();
227
			tfPrenom.setFieldLabel("Prénom");
228
			fsNoms.add(tfPrenom);
229
 
230
			hmIdentite.put("tfPrenom", tfPrenom);
231
 
232
			//Nom
233
			TextField<String> tfNom = new TextField<String>();
234
			tfNom.setFieldLabel("Nom");
235
			fsNoms.add(tfNom);
236
 
237
			hmIdentite.put("tfNom", tfNom);
238
 
283 gduche 239
			//Suffixe
280 gduche 240
			ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
241
			ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
242
			cbSuffixe.setStore(storeSuffixe);
243
			cbSuffixe.setFieldLabel("Suffixe");
283 gduche 244
			cbSuffixe.setDisplayField("nom");
245
			cbSuffixe.setEmptyText("Choisissez un suffixe:");
280 gduche 246
			fsNoms.add(cbSuffixe);
276 gduche 247
 
280 gduche 248
			hmIdentite.put("cbSuffixe", cbSuffixe);
283 gduche 249
 
250
			// Remplir la liste des suffixes:
251
			mediateur.obtenirListeValeurEtRafraichir(this, "suffixes");
252
 
276 gduche 253
			// Nom : autre
254
			TextField<String> tfNomAutre = new TextField();
255
			tfNomAutre.setFieldLabel("Autres noms");
256
			fsNoms.add(tfNomAutre);
257
 
258
			hmIdentite.put("tfNomAutre", tfNomAutre);
259
 
260
			//Abréviation
261
			TextField<String> tfAbreviation = new TextField<String>();
262
			tfAbreviation.setFieldLabel("Abréviation");
263
			fsNoms.add(tfAbreviation);
264
 
265
			hmIdentite.put("tfAbreviation", tfAbreviation);
266
 
267
			//Abréviation autres
268
			TextField<String> tfAbreviationAutre = new TextField<String>();
269
			tfAbreviationAutre.setFieldLabel("Autres Abrév.");
270
			fsNoms.add(tfAbreviationAutre);
271
 
286 gduche 272
			hmIdentite.put("tfAbreviationAutre", tfAbreviationAutre);
276 gduche 273
 
274
 
275
			left.add(fsNoms);
276
 
286 gduche 277
			// Naissance
278
			FieldSet fsNaissance = new FieldSet();
279
			fsNaissance.setHeading("Naissance");
276 gduche 280
 
281
			formLayout = new FormLayout();
286 gduche 282
			formLayout.setLabelAlign(LabelAlign.LEFT);
283
			fsNaissance.setLayout(formLayout);
276 gduche 284
 
285
			// Date naissance
280 gduche 286
			DateField dfDateNaissance = new DateField();
276 gduche 287
 
286 gduche 288
			dfDateNaissance.setFieldLabel("Date");
289
			fsNaissance.add(dfDateNaissance);
276 gduche 290
 
280 gduche 291
			hmIdentite.put("dfDateNaissance", dfDateNaissance);
276 gduche 292
 
280 gduche 293
			// Lieu naissance
294
			TextField<String> tfLieuNaissance = new TextField();
286 gduche 295
			tfLieuNaissance.setFieldLabel("Lieu");
296
			fsNaissance.add(tfLieuNaissance);
280 gduche 297
 
298
			hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
299
 
286 gduche 300
			left.add(fsNaissance);
301
 
302
			// Deces
303
			FieldSet fsDeces = new FieldSet();
304
			fsDeces.setHeading("Décès");
305
 
306
			formLayout = new FormLayout();
307
			formLayout.setLabelAlign(LabelAlign.LEFT);
308
			fsDeces.setLayout(formLayout);
309
 
280 gduche 310
			// Date décès
311
			DateField dfDateDeces = new DateField();
286 gduche 312
			dfDateDeces.setFieldLabel("Date");
313
			fsDeces.add(dfDateDeces);
280 gduche 314
 
315
			hmIdentite.put("dfDateDeces", dfDateDeces);
316
 
317
			// Lieu décès
318
			TextField<String> tfLieuDeces = new TextField();
286 gduche 319
			tfLieuDeces.setFieldLabel("Lieu");
320
			fsDeces.add(tfLieuDeces);
280 gduche 321
 
322
			hmIdentite.put("tfLieuDeces", tfLieuDeces);
323
 
286 gduche 324
			left.add(fsDeces);
280 gduche 325
 
276 gduche 326
			tiIdentite.add(main);
327
 
293 gduche 328
			// Contact - Téléphone
329
			FieldSet fsContactTel = new FieldSet();
330
			fsContactTel.setHeading("Contact - Téléphones");
331
			fsContactTel.setLayout(new TableLayout(3));
332
			hmIdentite.put("fsContactTel", fsContactTel);
276 gduche 333
 
293 gduche 334
			right.add(fsContactTel);
286 gduche 335
 
293 gduche 336
			//Téléphone
337
			TextField tfTelephone = new TextField();
338
			tfTelephone.setFieldLabel("tel");
339
			fsContactTel.add(tfTelephone);
286 gduche 340
 
293 gduche 341
			hmIdentite.put("tfTelephone", tfTelephone);
286 gduche 342
 
293 gduche 343
			//Type de téléphone
344
			ComboBox<Valeur> cbTelephone = new ComboBox<Valeur>();
286 gduche 345
 
293 gduche 346
			cbTelephone.setDisplayField("nom");
347
			cbTelephone.setEmptyText("Choisissez:");
348
			ListStore<Valeur> storeTel = new ListStore<Valeur>();
349
			cbTelephone.setStore(storeTel);
286 gduche 350
 
293 gduche 351
			fsContactTel.add(cbTelephone);
286 gduche 352
 
293 gduche 353
			hmIdentite.put("cbTelephone", cbTelephone);
286 gduche 354
 
293 gduche 355
			mediateur.obtenirListeValeurEtRafraichir(this, "tel");
286 gduche 356
 
293 gduche 357
			// Bouton ajouter
319 gduche 358
			IconButton bAjouter = new IconButton(ComposantClass.ICONE_AJOUTER);
286 gduche 359
 
293 gduche 360
			// Evenement bouton
361
			bAjouter.addSelectionListener(
362
					new SelectionListener<ComponentEvent>() {
363
 
364
						public void componentSelected(ComponentEvent ce) {
365
 
366
							String strTelephone = ((TextField<String>) hmIdentite.get("tfTelephone")).getValue();
367
							if ((strTelephone==null)||(strTelephone.trim().equals("")))	{
319 gduche 368
								MessageBox.alert("Erreur de saisie", "Vous devez saisir un numéro de téléphone", null);
293 gduche 369
							} else if (hmIdentite.get("tel-" + strTelephone) != null){
319 gduche 370
								MessageBox.alert("Erreur de saisie", "Le numéro saisi est déjà présent dans la liste", null);
293 gduche 371
							} else {
372
 
373
								String strValeurTypeTel = "";
374
								Valeur valeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getValue();
375
 
376
								if (valeurTypeTel != null)	{
377
									strValeurTypeTel = valeurTypeTel.getNom();
378
								}	else {
379
									strValeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getRawValue();
380
								}
381
 
382
 
383
								if (strValeurTypeTel.trim().equals(""))	{
319 gduche 384
									MessageBox.alert("Erreur de saisie", "Vous devez saisir un type de téléphone", null);
293 gduche 385
								}	else {
386
 
387
									//Ajout d'un champ à la liste
388
									HiddenField<String> hfTelephone = new HiddenField<String>();
389
									hfTelephone.setId("hidden-" + strTelephone);
390
									hfTelephone.setFieldLabel(strValeurTypeTel);
391
									hfTelephone.setValue(strTelephone);
392
									hmIdentite.put("hidden-" + strTelephone, hfTelephone);
393
 
394
									FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
395
 
396
									Text tTypeTelephone = new Text();
397
									tTypeTelephone.setText(strValeurTypeTel+":");
398
 
399
									hmIdentite.put("type-" + strTelephone, tTypeTelephone);
400
									fsContactTel.add(tTypeTelephone);
401
 
402
									Text tTelephone = new Text();
403
									tTelephone.setText(strTelephone);
404
									hmIdentite.put("tel-" + strTelephone, tTelephone);
405
									fsContactTel.add(tTelephone);
406
 
319 gduche 407
									IconButton bSupprimer = new IconButton(ComposantClass.ICONE_SUPPRIMER);
293 gduche 408
									bSupprimer.setId(strTelephone);
409
 
410
									bSupprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
411
											public void componentSelected(ComponentEvent ce) {
412
 
413
												String strTelephone = ce.component.getId();
414
												FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
415
 
416
												fsContactTel.remove(hmIdentite.get("type-" + strTelephone));
417
												hmIdentite.remove("type-" + strTelephone);
418
 
419
												fsContactTel.remove(hmIdentite.get("tel-" + strTelephone));
420
												hmIdentite.remove("tel-" + strTelephone);
421
 
422
												((TabItem) hmIdentite.get("tiIdentite")).remove(hmIdentite.get("hidden-" + strTelephone));
423
												hmIdentite.remove("hidden-" + strTelephone);
424
 
425
												fsContactTel.remove(ce.component);
426
 
427
												layout();
319 gduche 428
 
293 gduche 429
											}
430
									});
431
 
432
									fsContactTel.add(bSupprimer);
433
 
434
									((TabItem) hmIdentite.get("tiIdentite")).add(hfTelephone);
435
 
436
									layout();
437
								}
438
 
439
							}
440
 
441
 
442
						}
443
					}
444
			);
286 gduche 445
 
293 gduche 446
			fsContactTel.add(bAjouter);
286 gduche 447
 
293 gduche 448
			//Contact - autres
286 gduche 449
			FieldSet fsContact = new FieldSet();
293 gduche 450
			fsContact.setHeading("Contact - Autres");
319 gduche 451
			fsContact.setId("fsContact");
286 gduche 452
 
453
			formLayout = new FormLayout();
454
			formLayout.setLabelAlign(LabelAlign.LEFT);
455
			fsContact.setLayout(formLayout);
456
 
457
			right.add(fsContact);
458
 
459
			// Courriels
460
			TextArea taCourriel = new TextArea();
461
			taCourriel.setFieldLabel("Courriels");
462
			taCourriel.setEmptyText("Saisissez les adresses courriels séparées par un saut de ligne");
463
 
319 gduche 464
			fsContact.add(taCourriel, fd100);
465
 
286 gduche 466
			hmIdentite.put("taCourriel", taCourriel);
467
 
468
			// URLS
469
			TextArea taUrl = new TextArea();
470
			taUrl.setFieldLabel("Sites");
319 gduche 471
			taUrl.setWidth("100%");
286 gduche 472
			taUrl.setEmptyText("Saisissez les adresses des sites séparées par un saut de ligne");
319 gduche 473
			fsContact.add(taUrl, fd100);
286 gduche 474
 
475
			hmIdentite.put("taUrl", taUrl);
476
 
477
 
293 gduche 478
			// Autres informations
479
			FieldSet fsAutresInfos = new FieldSet();
480
			fsAutresInfos.setHeading("Autres informations");
481
 
482
			formLayout = new FormLayout();
483
			formLayout.setLabelAlign(LabelAlign.LEFT);
484
			fsAutresInfos.setLayout(formLayout);
485
 
486
			right.add(fsAutresInfos);
487
 
488
			//Civilité
489
 
490
			ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
491
			ListStore<Valeur> storeSexe = new ListStore<Valeur>();
492
			cbSexe.setStore(storeSexe);
493
			cbSexe.setFieldLabel("Sexe");
494
			cbSexe.setDisplayField("nom");
495
			cbSexe.setEmptyText("Choisissez le sexe:");
496
 
319 gduche 497
			fsAutresInfos.add(cbSexe, fd100);
293 gduche 498
 
499
			hmIdentite.put("cbSexe", cbSexe);
500
 
501
			mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
502
 
503
			//Description
504
			TextArea taDescription = new TextArea();
505
			taDescription.setEmptyText("Saisissez une description");
506
			taDescription.setFieldLabel("Description");
319 gduche 507
			taDescription.setWidth("100%");
508
			fsAutresInfos.add(taDescription, fd100);
293 gduche 509
 
510
			hmIdentite.put("taDescription", taDescription);
511
 
512
			// Logo
513
			TextArea taLogo = new TextArea();
514
			taLogo.setFieldLabel("Logos");
319 gduche 515
			taLogo.setWidth("100%");
293 gduche 516
			taLogo.setEmptyText("Saisissez les adresses des logos séparées par un saut de ligne");
319 gduche 517
			fsAutresInfos.add(taLogo, fd100);
293 gduche 518
 
519
			hmIdentite.put("taLogo", taLogo);
520
 
521
 
522
 
276 gduche 523
			// Ajout des évènements saisi
524
			KeyListener klNoms = new KeyListener()	{
525
				public void componentKeyUp(ComponentEvent ev)	{
283 gduche 526
					rafraichir(null);
280 gduche 527
				}
276 gduche 528
			};
529
 
283 gduche 530
			SelectionChangedListener<InterneValeur> selectionChange = new SelectionChangedListener<InterneValeur>() {
531
				public void selectionChanged(SelectionChangedEvent se) {
532
						rafraichir(null);
533
					}
534
			};
535
 
319 gduche 536
			cbPrefixe.addSelectionChangedListener(selectionChange);
537
			cbPrefixe.addKeyListener(klNoms);
276 gduche 538
			tfPrenom.addKeyListener(klNoms);
539
			tfNom.addKeyListener(klNoms);
283 gduche 540
			cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 541
 
542
	}
543
 
293 gduche 544
	public void creerComposantsAdresse()	{
545
 
546
		// Gauche
547
		LayoutContainer left = new LayoutContainer();
548
		left.setLayout(new FormLayout());
549
 
550
		// Droite
551
		LayoutContainer right = new LayoutContainer();
552
		right.setLayout(new FormLayout());
553
 
554
		// Principal
555
		LayoutContainer main = new LayoutContainer();
556
		main.setLayout(new ColumnLayout());
557
 
558
		// Ajout au principal
559
		main.add(left, new ColumnData(.49));
560
		main.add(right, new ColumnData(.49));
561
 
562
		TextField<String> tfAdresse1 = new TextField();
563
		tfAdresse1.setFieldLabel("Adresse");
319 gduche 564
		left.add(tfAdresse1, fd100);
293 gduche 565
		hmAdresse.put("tfAdresse1", tfAdresse1);
566
 
567
		TextField<String> tfAdresse2 = new TextField();
568
		tfAdresse2.setFieldLabel("Complément d'adresse");
319 gduche 569
		left.add(tfAdresse2, fd100);
293 gduche 570
		hmAdresse.put("tfAdresse2", tfAdresse2);
571
 
572
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
573
		cbPays.setFieldLabel("Pays");
574
		cbPays.setDisplayField("nom");
575
		cbPays.setEmptyText("Sélectionnez le pays:");
576
 
577
		ListStore<Valeur> storePays = new ListStore<Valeur>();
578
		cbPays.setStore(storePays);
579
 
319 gduche 580
		right.add(cbPays, fd100);
293 gduche 581
		hmAdresse.put("cbPays", cbPays);
582
 
583
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
584
			public void selectionChanged(SelectionChangedEvent se) {
585
					// Rafraichir avec le pays sélectionné
586
					obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
587
 
588
				}
589
		};
590
 
591
		cbPays.addSelectionChangedListener(selectionChange);
592
 
593
 
594
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
595
		cbRegion.setFieldLabel("Region");
596
		cbRegion.setDisplayField("nom");
597
		cbRegion.setEmptyText("Sélectionnez la région:");
598
		cbRegion.setVisible(false);
599
 
600
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
601
		cbRegion.setStore(storeRegion);
602
 
319 gduche 603
		right.add(cbRegion, fd100);
293 gduche 604
		hmAdresse.put("cbRegion", cbRegion);
605
 
606
		TextField<String> tfBoitePostale = new TextField<String>();
607
		tfBoitePostale.setFieldLabel("Boite postale");
319 gduche 608
		left.add(tfBoitePostale, fd100);
293 gduche 609
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
610
 
611
		TextField<Integer> tfCodePostal = new TextField<Integer>();
612
		tfCodePostal.setFieldLabel("Code postal");
319 gduche 613
		right.add(tfCodePostal, fd100);
293 gduche 614
		hmAdresse.put("tfCodePostal", tfCodePostal);
615
 
616
		TextField tfVille = new TextField();
617
		tfVille.setFieldLabel("Ville");
618
 
319 gduche 619
		right.add(tfVille, fd100);
293 gduche 620
		hmAdresse.put("tfVille", tfVille);
621
 
622
		// MAJ ComboBox
623
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
624
 
304 gduche 625
		FieldSet fsAdresse = new FieldSet();
626
		fsAdresse.setHeading("Adresse personnelle");
627
		fsAdresse.add(main);
293 gduche 628
 
304 gduche 629
		tiAdresses.add(fsAdresse);
630
 
293 gduche 631
	}
632
 
276 gduche 633
	/**
634
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
635
	 *
636
	 * @param barreOutils la barre d'outils à modifier
637
	 * */
638
	public static void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
639
 
640
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
641
		TextToolItem reinitialiser = new TextToolItem("Réinitialiser");
642
		reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
643
		reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
644
			public void componentSelected(ComponentEvent ce) {
645
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
646
			}
647
		});
648
		barreOutils.add(reinitialiser);
649
	}
650
 
651
	/**
652
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
653
	 *
654
	 * @param barreOutils la barre d'outils à modifier
655
	 * */
656
	public static void ajouterBoutonEnregistrer(ToolBar barreOutils)	{
657
 
658
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
286 gduche 659
		TextToolItem enregistrer = new TextToolItem("Enregistrer");
660
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
661
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
276 gduche 662
			public void componentSelected(ComponentEvent ce) {
663
				// TODO : Enregistrer le formulaire
664
			}
665
		});
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
	 * */
674
	public static void ajouterBoutonAnnuler(ToolBar barreOutils)	{
675
 
676
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
677
		TextToolItem annuler = new TextToolItem("Annuler");
678
		annuler.addSelectionListener(new SelectionListener<ComponentEvent>() {
679
			public void componentSelected(ComponentEvent ce) {
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
 
691
 
293 gduche 692
 
276 gduche 693
	/*---------------------------------------------------------------------------------------
694
	 * 		RAFRAICHISSEMENT DU PANNEAU
695
	 * --------------------------------------------------------------------------------------
696
	 */
283 gduche 697
	public void rafraichir(Object nouvellesDonnees) {
698
		if (nouvellesDonnees instanceof ValeurListe){
699
 
700
 
701
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
702
 
703
			// Créer une liste de valeurs
704
			List<Valeur> liste = new ArrayList<Valeur>();
705
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
706
				liste.add(listeValeurs.get(it.next()));
707
			}
708
 
709
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
710
 
319 gduche 711
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 712
 
713
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
714
 
715
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
716
 
717
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
718
 
719
				remplirCombobox("cbSexe", liste, "hmIdentite");
283 gduche 720
 
293 gduche 721
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
722
 
723
				remplirCombobox("cbTelephone", liste, "hmIdentite");
319 gduche 724
 
725
				//Préselection du tél
726
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
727
				cbTelephone.setValue(liste.get(1));
293 gduche 728
 
729
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
283 gduche 730
 
293 gduche 731
				remplirCombobox("cbPays", liste, "hmAdresse");
283 gduche 732
 
293 gduche 733
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
283 gduche 734
 
293 gduche 735
				remplirCombobox("cbRegion", liste, "hmAdresse");
283 gduche 736
 
293 gduche 737
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 738
			}
293 gduche 739
 
740
 
286 gduche 741
		} else if (nouvellesDonnees instanceof Personne)	{
293 gduche 742
 
286 gduche 743
 
744
 
745
			//Mise à jour de la personne
746
			Personne personne = (Personne) nouvellesDonnees;
747
			personneSelectionnee = personne;
748
 
749
 
319 gduche 750
			//Prefix
751
			String prefixe = (String) personne.get("ce_truk_prefix");
752
			ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
753
			cbPrefixe.setRawValue(prefixe);
754
 
286 gduche 755
			((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
756
			((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
757
			((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
758
			((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
759
			((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
760
 
293 gduche 761
			//FIXME : DATES
286 gduche 762
			//((DateField) hmIdentite.get("dfDateNaissance")).setValue(new Date((String) personne.get("naissance_date")));
763
			((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
764
			//((DateField) hmIdentite.get("dfDateDeces")).setValue(new Date((String) personne.get("deces_date")));
765
			((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
766
 
293 gduche 767
		}
283 gduche 768
 
769
		if (nouvellesDonnees == null)
770
		{
319 gduche 771
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 772
 
773
			//Met à jour le nom Complet du formulaire
283 gduche 774
			String valeurRetour = "";
775
 
776
			// Prefixe
777
			String prefixe = "";
319 gduche 778
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 779
 
780
			if (valPrefixe != null)	{
781
				prefixe = valPrefixe.getNom();
293 gduche 782
			} else 	{
319 gduche 783
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 784
			}
283 gduche 785
 
293 gduche 786
 
283 gduche 787
			// Prénom
788
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
789
 
790
			// Nom
791
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
792
 
793
			// Suffixe
794
			String suffixe = "";
795
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
796
 
797
			if (valSuffixe != null)	{
798
				suffixe = valSuffixe.getNom();
293 gduche 799
			} else 	{
800
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 801
			}
802
 
803
			// Mettre à jour la valeur
804
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
805
			valeurRetour = valeurRetour.replaceAll("null", "");
806
 
807
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
808
 
809
			if (!valeurRetour.trim().equals(""))	{
810
				((LabelField) hmIdentite.get("nomComplet")).show();
811
			} else {
812
				((LabelField) hmIdentite.get("nomComplet")).hide();
813
			}
814
		}
127 gduche 815
	}
816
 
293 gduche 817
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
818
 
819
		HashMap hm = null;
820
		if (hashMapId.equals("hmIdentite"))	{
821
			hm = hmIdentite;
822
		} else if (hashMapId.equals("hmAdresse")){
823
			hm = hmAdresse;
824
		} else {
825
			hm = hmInfosNat;
826
		}
827
 
828
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
829
		store.removeAll();
830
		store.add(liste);
831
		((ComboBox) hm.get(idComboBox)).setStore(store);
832
	}
130 gduche 833
 
834
 
835
 
127 gduche 836
}