Subversion Repositories eFlore/Applications.coel

Rev

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