Subversion Repositories eFlore/Applications.coel

Rev

Rev 286 | Rev 304 | 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");
140
		tiAdresses.setLayout(new FlowLayout());
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
 
614
		tiAdresses.add(main);
615
 
616
	}
617
 
276 gduche 618
	/**
619
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
620
	 *
621
	 * @param barreOutils la barre d'outils à modifier
622
	 * */
623
	public static void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
624
 
625
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
626
		TextToolItem reinitialiser = new TextToolItem("Réinitialiser");
627
		reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
628
		reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
629
			public void componentSelected(ComponentEvent ce) {
630
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
631
			}
632
		});
633
		barreOutils.add(reinitialiser);
634
	}
635
 
636
	/**
637
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
638
	 *
639
	 * @param barreOutils la barre d'outils à modifier
640
	 * */
641
	public static void ajouterBoutonEnregistrer(ToolBar barreOutils)	{
642
 
643
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
286 gduche 644
		TextToolItem enregistrer = new TextToolItem("Enregistrer");
645
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
646
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
276 gduche 647
			public void componentSelected(ComponentEvent ce) {
648
				// TODO : Enregistrer le formulaire
649
			}
650
		});
286 gduche 651
		barreOutils.add(enregistrer);
276 gduche 652
	}
653
 
654
	/**
655
	 * Ajouter le bouton annuler à la barre d'outils donnée
656
	 *
657
	 * @param barreOutils la barre d'outils à modifier
658
	 * */
659
	public static void ajouterBoutonAnnuler(ToolBar barreOutils)	{
660
 
661
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
662
		TextToolItem annuler = new TextToolItem("Annuler");
663
		annuler.addSelectionListener(new SelectionListener<ComponentEvent>() {
664
			public void componentSelected(ComponentEvent ce) {
665
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
666
			}
667
		});
668
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
669
		barreOutils.add(annuler);
670
	}
671
 
293 gduche 672
	public void obtenirListeRegionParPays(String strPays)	{
673
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
674
	}
276 gduche 675
 
676
 
293 gduche 677
 
276 gduche 678
	/*---------------------------------------------------------------------------------------
679
	 * 		RAFRAICHISSEMENT DU PANNEAU
680
	 * --------------------------------------------------------------------------------------
681
	 */
283 gduche 682
	public void rafraichir(Object nouvellesDonnees) {
683
		if (nouvellesDonnees instanceof ValeurListe){
684
 
685
 
686
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
687
 
688
			// Créer une liste de valeurs
689
			List<Valeur> liste = new ArrayList<Valeur>();
690
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
691
				liste.add(listeValeurs.get(it.next()));
692
			}
693
 
694
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
695
 
293 gduche 696
				remplirCombobox("cbPrefix", liste, "hmIdentite");
697
 
698
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
699
 
700
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
701
 
702
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
703
 
704
				remplirCombobox("cbSexe", liste, "hmIdentite");
283 gduche 705
 
293 gduche 706
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
707
 
708
				remplirCombobox("cbTelephone", liste, "hmIdentite");
709
 
710
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
283 gduche 711
 
293 gduche 712
				remplirCombobox("cbPays", liste, "hmAdresse");
283 gduche 713
 
293 gduche 714
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
283 gduche 715
 
293 gduche 716
				remplirCombobox("cbRegion", liste, "hmAdresse");
283 gduche 717
 
293 gduche 718
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 719
			}
293 gduche 720
 
721
 
286 gduche 722
		} else if (nouvellesDonnees instanceof Personne)	{
293 gduche 723
 
286 gduche 724
 
725
 
726
			//Mise à jour de la personne
727
			Personne personne = (Personne) nouvellesDonnees;
728
			personneSelectionnee = personne;
729
 
730
 
731
			((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
732
			((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
733
			((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
734
			((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
735
			((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
736
 
293 gduche 737
			//FIXME : DATES
286 gduche 738
			//((DateField) hmIdentite.get("dfDateNaissance")).setValue(new Date((String) personne.get("naissance_date")));
739
			((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
740
			//((DateField) hmIdentite.get("dfDateDeces")).setValue(new Date((String) personne.get("deces_date")));
741
			((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
742
 
293 gduche 743
		}
283 gduche 744
 
745
		if (nouvellesDonnees == null)
746
		{
747
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefix");
293 gduche 748
 
749
			//Met à jour le nom Complet du formulaire
283 gduche 750
			String valeurRetour = "";
751
 
752
			// Prefixe
753
			String prefixe = "";
754
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefix")).getValue();
755
 
756
			if (valPrefixe != null)	{
757
				prefixe = valPrefixe.getNom();
293 gduche 758
			} else 	{
759
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefix")).getRawValue();
760
			}
283 gduche 761
 
293 gduche 762
 
283 gduche 763
			// Prénom
764
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
765
 
766
			// Nom
767
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
768
 
769
			// Suffixe
770
			String suffixe = "";
771
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
772
 
773
			if (valSuffixe != null)	{
774
				suffixe = valSuffixe.getNom();
293 gduche 775
			} else 	{
776
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 777
			}
778
 
779
			// Mettre à jour la valeur
780
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
781
			valeurRetour = valeurRetour.replaceAll("null", "");
782
 
783
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
784
 
785
			if (!valeurRetour.trim().equals(""))	{
786
				((LabelField) hmIdentite.get("nomComplet")).show();
787
			} else {
788
				((LabelField) hmIdentite.get("nomComplet")).hide();
789
			}
790
		}
127 gduche 791
	}
792
 
293 gduche 793
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
794
 
795
		HashMap hm = null;
796
		if (hashMapId.equals("hmIdentite"))	{
797
			hm = hmIdentite;
798
		} else if (hashMapId.equals("hmAdresse")){
799
			hm = hmAdresse;
800
		} else {
801
			hm = hmInfosNat;
802
		}
803
 
804
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
805
		store.removeAll();
806
		store.add(liste);
807
		((ComboBox) hm.get(idComboBox)).setStore(store);
808
	}
130 gduche 809
 
810
 
811
 
127 gduche 812
}