Subversion Repositories eFlore/Applications.coel

Rev

Rev 338 | Rev 352 | 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;
276 gduche 4
import java.util.HashMap;
283 gduche 5
import java.util.Iterator;
6
import java.util.List;
276 gduche 7
 
8
import org.tela_botanica.client.ComposantClass;
9
import org.tela_botanica.client.Mediateur;
10
import org.tela_botanica.client.RegistreId;
127 gduche 11
import org.tela_botanica.client.interfaces.Rafraichissable;
283 gduche 12
import org.tela_botanica.client.modeles.Configuration;
280 gduche 13
import org.tela_botanica.client.modeles.InterneValeur;
293 gduche 14
 
286 gduche 15
import org.tela_botanica.client.modeles.Personne;
280 gduche 16
import org.tela_botanica.client.modeles.Valeur;
283 gduche 17
import org.tela_botanica.client.modeles.ValeurListe;
127 gduche 18
 
276 gduche 19
 
20
import com.extjs.gxt.ui.client.Registry;
21
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
283 gduche 22
import com.extjs.gxt.ui.client.Style.Scroll;
276 gduche 23
import com.extjs.gxt.ui.client.event.ComponentEvent;
24
import com.extjs.gxt.ui.client.event.KeyListener;
280 gduche 25
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
26
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 27
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 28
import com.extjs.gxt.ui.client.store.ListStore;
276 gduche 29
import com.extjs.gxt.ui.client.widget.ContentPanel;
127 gduche 30
import com.extjs.gxt.ui.client.widget.LayoutContainer;
319 gduche 31
import com.extjs.gxt.ui.client.widget.MessageBox;
338 gduche 32
 
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
 
319 gduche 37
import com.extjs.gxt.ui.client.widget.button.IconButton;
280 gduche 38
import com.extjs.gxt.ui.client.widget.form.ComboBox;
39
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 40
import com.extjs.gxt.ui.client.widget.form.FieldSet;
293 gduche 41
import com.extjs.gxt.ui.client.widget.form.HiddenField;
276 gduche 42
import com.extjs.gxt.ui.client.widget.form.LabelField;
286 gduche 43
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 44
import com.extjs.gxt.ui.client.widget.form.TextField;
45
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
46
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
47
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
48
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
319 gduche 49
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 50
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
293 gduche 51
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
276 gduche 52
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
53
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
339 gduche 54
import com.google.gwt.i18n.client.DateTimeFormat;
276 gduche 55
import com.google.gwt.user.client.ui.Widget;
127 gduche 56
 
57
 
276 gduche 58
 
59
public class FormPersonneVue extends ContentPanel implements Rafraichissable {
60
 
61
 
62
	/*--------------------------------------------------------------------------------------
63
	 * 		VARIABLES
64
	 * -------------------------------------------------------------------------------------
65
	 */
66
 
67
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
283 gduche 68
	private Mediateur mediateur = Registry.get(RegistreId.MEDIATEUR);
69
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
286 gduche 70
	private Personne personneSelectionnee = null;
276 gduche 71
 
72
	/*--------------------------------------------------------------------------------------
73
	 * 		CONSTRUCTEUR
74
	 * -------------------------------------------------------------------------------------
75
	 */
76
	/**
77
	 * Constructeur du panneau
78
	 *
79
	 * Initialise le panneau et ajoute une barre d'outils à deux boutons (réinitialiser le
80
	 * formulaire et annuler la saisie).
81
	 *
82
	 * */
83
	public FormPersonneVue() {
84
 
283 gduche 85
		initialiserPanneau();
276 gduche 86
 
87
		ToolBar barreOutils = new ToolBar();
88
 
89
		ajouterBoutonEnregistrer(barreOutils);
338 gduche 90
		ajouterBoutonEnregistrerEtRevenir(barreOutils);
276 gduche 91
		ajouterBoutonReinitialiser(barreOutils);
92
		ajouterBoutonAnnuler(barreOutils);
93
 
94
 
338 gduche 95
		setBottomComponent(barreOutils);
96
 
276 gduche 97
		initialiserOnglets();
98
 
99
		creerComposantsIdentite();
293 gduche 100
		creerComposantsAdresse();
280 gduche 101
 
338 gduche 102
 
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();
338 gduche 287
			dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
276 gduche 288
 
286 gduche 289
			dfDateNaissance.setFieldLabel("Date");
290
			fsNaissance.add(dfDateNaissance);
276 gduche 291
 
280 gduche 292
			hmIdentite.put("dfDateNaissance", dfDateNaissance);
276 gduche 293
 
280 gduche 294
			// Lieu naissance
295
			TextField<String> tfLieuNaissance = new TextField();
286 gduche 296
			tfLieuNaissance.setFieldLabel("Lieu");
297
			fsNaissance.add(tfLieuNaissance);
280 gduche 298
 
299
			hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
300
 
286 gduche 301
			left.add(fsNaissance);
302
 
303
			// Deces
304
			FieldSet fsDeces = new FieldSet();
305
			fsDeces.setHeading("Décès");
306
 
307
			formLayout = new FormLayout();
308
			formLayout.setLabelAlign(LabelAlign.LEFT);
309
			fsDeces.setLayout(formLayout);
310
 
280 gduche 311
			// Date décès
312
			DateField dfDateDeces = new DateField();
338 gduche 313
			dfDateDeces.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
314
			dfDateDeces.setFormatValue(true);
315
			dfDateDeces.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
316
 
286 gduche 317
			dfDateDeces.setFieldLabel("Date");
318
			fsDeces.add(dfDateDeces);
280 gduche 319
 
320
			hmIdentite.put("dfDateDeces", dfDateDeces);
321
 
322
			// Lieu décès
323
			TextField<String> tfLieuDeces = new TextField();
286 gduche 324
			tfLieuDeces.setFieldLabel("Lieu");
325
			fsDeces.add(tfLieuDeces);
280 gduche 326
 
327
			hmIdentite.put("tfLieuDeces", tfLieuDeces);
328
 
286 gduche 329
			left.add(fsDeces);
280 gduche 330
 
276 gduche 331
			tiIdentite.add(main);
332
 
293 gduche 333
			// Contact - Téléphone
334
			FieldSet fsContactTel = new FieldSet();
335
			fsContactTel.setHeading("Contact - Téléphones");
336
			fsContactTel.setLayout(new TableLayout(3));
337
			hmIdentite.put("fsContactTel", fsContactTel);
276 gduche 338
 
293 gduche 339
			right.add(fsContactTel);
286 gduche 340
 
293 gduche 341
			//Téléphone
342
			TextField tfTelephone = new TextField();
343
			tfTelephone.setFieldLabel("tel");
344
			fsContactTel.add(tfTelephone);
286 gduche 345
 
293 gduche 346
			hmIdentite.put("tfTelephone", tfTelephone);
286 gduche 347
 
293 gduche 348
			//Type de téléphone
349
			ComboBox<Valeur> cbTelephone = new ComboBox<Valeur>();
286 gduche 350
 
293 gduche 351
			cbTelephone.setDisplayField("nom");
352
			cbTelephone.setEmptyText("Choisissez:");
353
			ListStore<Valeur> storeTel = new ListStore<Valeur>();
354
			cbTelephone.setStore(storeTel);
286 gduche 355
 
293 gduche 356
			fsContactTel.add(cbTelephone);
286 gduche 357
 
293 gduche 358
			hmIdentite.put("cbTelephone", cbTelephone);
286 gduche 359
 
293 gduche 360
			mediateur.obtenirListeValeurEtRafraichir(this, "tel");
286 gduche 361
 
293 gduche 362
			// Bouton ajouter
319 gduche 363
			IconButton bAjouter = new IconButton(ComposantClass.ICONE_AJOUTER);
286 gduche 364
 
293 gduche 365
			// Evenement bouton
366
			bAjouter.addSelectionListener(
367
					new SelectionListener<ComponentEvent>() {
368
 
369
						public void componentSelected(ComponentEvent ce) {
370
 
371
							String strTelephone = ((TextField<String>) hmIdentite.get("tfTelephone")).getValue();
372
							if ((strTelephone==null)||(strTelephone.trim().equals("")))	{
319 gduche 373
								MessageBox.alert("Erreur de saisie", "Vous devez saisir un numéro de téléphone", null);
293 gduche 374
							} else if (hmIdentite.get("tel-" + strTelephone) != null){
319 gduche 375
								MessageBox.alert("Erreur de saisie", "Le numéro saisi est déjà présent dans la liste", null);
293 gduche 376
							} else {
377
 
378
								String strValeurTypeTel = "";
379
								Valeur valeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getValue();
380
 
381
								if (valeurTypeTel != null)	{
382
									strValeurTypeTel = valeurTypeTel.getNom();
383
								}	else {
384
									strValeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getRawValue();
385
								}
386
 
387
 
388
								if (strValeurTypeTel.trim().equals(""))	{
319 gduche 389
									MessageBox.alert("Erreur de saisie", "Vous devez saisir un type de téléphone", null);
293 gduche 390
								}	else {
391
 
392
									//Ajout d'un champ à la liste
393
									HiddenField<String> hfTelephone = new HiddenField<String>();
394
									hfTelephone.setId("hidden-" + strTelephone);
395
									hfTelephone.setFieldLabel(strValeurTypeTel);
396
									hfTelephone.setValue(strTelephone);
397
									hmIdentite.put("hidden-" + strTelephone, hfTelephone);
398
 
399
									FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
400
 
401
									Text tTypeTelephone = new Text();
402
									tTypeTelephone.setText(strValeurTypeTel+":");
403
 
404
									hmIdentite.put("type-" + strTelephone, tTypeTelephone);
405
									fsContactTel.add(tTypeTelephone);
406
 
407
									Text tTelephone = new Text();
408
									tTelephone.setText(strTelephone);
409
									hmIdentite.put("tel-" + strTelephone, tTelephone);
410
									fsContactTel.add(tTelephone);
411
 
319 gduche 412
									IconButton bSupprimer = new IconButton(ComposantClass.ICONE_SUPPRIMER);
293 gduche 413
									bSupprimer.setId(strTelephone);
414
 
415
									bSupprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
416
											public void componentSelected(ComponentEvent ce) {
417
 
418
												String strTelephone = ce.component.getId();
419
												FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
420
 
421
												fsContactTel.remove(hmIdentite.get("type-" + strTelephone));
422
												hmIdentite.remove("type-" + strTelephone);
423
 
424
												fsContactTel.remove(hmIdentite.get("tel-" + strTelephone));
425
												hmIdentite.remove("tel-" + strTelephone);
426
 
427
												((TabItem) hmIdentite.get("tiIdentite")).remove(hmIdentite.get("hidden-" + strTelephone));
428
												hmIdentite.remove("hidden-" + strTelephone);
429
 
430
												fsContactTel.remove(ce.component);
431
 
432
												layout();
319 gduche 433
 
293 gduche 434
											}
435
									});
436
 
437
									fsContactTel.add(bSupprimer);
438
 
439
									((TabItem) hmIdentite.get("tiIdentite")).add(hfTelephone);
440
 
441
									layout();
442
								}
443
 
444
							}
445
 
446
 
447
						}
448
					}
449
			);
286 gduche 450
 
293 gduche 451
			fsContactTel.add(bAjouter);
286 gduche 452
 
293 gduche 453
			//Contact - autres
286 gduche 454
			FieldSet fsContact = new FieldSet();
293 gduche 455
			fsContact.setHeading("Contact - Autres");
319 gduche 456
			fsContact.setId("fsContact");
286 gduche 457
 
458
			formLayout = new FormLayout();
459
			formLayout.setLabelAlign(LabelAlign.LEFT);
460
			fsContact.setLayout(formLayout);
461
 
462
			right.add(fsContact);
463
 
464
			// Courriels
465
			TextArea taCourriel = new TextArea();
466
			taCourriel.setFieldLabel("Courriels");
467
			taCourriel.setEmptyText("Saisissez les adresses courriels séparées par un saut de ligne");
468
 
319 gduche 469
			fsContact.add(taCourriel, fd100);
470
 
286 gduche 471
			hmIdentite.put("taCourriel", taCourriel);
472
 
473
			// URLS
474
			TextArea taUrl = new TextArea();
475
			taUrl.setFieldLabel("Sites");
319 gduche 476
			taUrl.setWidth("100%");
286 gduche 477
			taUrl.setEmptyText("Saisissez les adresses des sites séparées par un saut de ligne");
319 gduche 478
			fsContact.add(taUrl, fd100);
286 gduche 479
 
480
			hmIdentite.put("taUrl", taUrl);
481
 
482
 
293 gduche 483
			// Autres informations
484
			FieldSet fsAutresInfos = new FieldSet();
485
			fsAutresInfos.setHeading("Autres informations");
486
 
487
			formLayout = new FormLayout();
488
			formLayout.setLabelAlign(LabelAlign.LEFT);
489
			fsAutresInfos.setLayout(formLayout);
490
 
491
			right.add(fsAutresInfos);
492
 
493
			//Civilité
494
 
495
			ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
496
			ListStore<Valeur> storeSexe = new ListStore<Valeur>();
497
			cbSexe.setStore(storeSexe);
498
			cbSexe.setFieldLabel("Sexe");
499
			cbSexe.setDisplayField("nom");
500
			cbSexe.setEmptyText("Choisissez le sexe:");
501
 
319 gduche 502
			fsAutresInfos.add(cbSexe, fd100);
293 gduche 503
 
504
			hmIdentite.put("cbSexe", cbSexe);
505
 
506
			mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
507
 
508
			//Description
509
			TextArea taDescription = new TextArea();
510
			taDescription.setEmptyText("Saisissez une description");
511
			taDescription.setFieldLabel("Description");
319 gduche 512
			taDescription.setWidth("100%");
513
			fsAutresInfos.add(taDescription, fd100);
293 gduche 514
 
515
			hmIdentite.put("taDescription", taDescription);
516
 
517
			// Logo
518
			TextArea taLogo = new TextArea();
519
			taLogo.setFieldLabel("Logos");
319 gduche 520
			taLogo.setWidth("100%");
293 gduche 521
			taLogo.setEmptyText("Saisissez les adresses des logos séparées par un saut de ligne");
319 gduche 522
			fsAutresInfos.add(taLogo, fd100);
293 gduche 523
 
524
			hmIdentite.put("taLogo", taLogo);
525
 
526
 
527
 
276 gduche 528
			// Ajout des évènements saisi
529
			KeyListener klNoms = new KeyListener()	{
530
				public void componentKeyUp(ComponentEvent ev)	{
283 gduche 531
					rafraichir(null);
280 gduche 532
				}
276 gduche 533
			};
534
 
283 gduche 535
			SelectionChangedListener<InterneValeur> selectionChange = new SelectionChangedListener<InterneValeur>() {
536
				public void selectionChanged(SelectionChangedEvent se) {
537
						rafraichir(null);
538
					}
539
			};
540
 
319 gduche 541
			cbPrefixe.addSelectionChangedListener(selectionChange);
542
			cbPrefixe.addKeyListener(klNoms);
276 gduche 543
			tfPrenom.addKeyListener(klNoms);
544
			tfNom.addKeyListener(klNoms);
283 gduche 545
			cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 546
 
547
	}
548
 
293 gduche 549
	public void creerComposantsAdresse()	{
550
 
551
		// Gauche
552
		LayoutContainer left = new LayoutContainer();
553
		left.setLayout(new FormLayout());
554
 
555
		// Droite
556
		LayoutContainer right = new LayoutContainer();
557
		right.setLayout(new FormLayout());
558
 
559
		// Principal
560
		LayoutContainer main = new LayoutContainer();
561
		main.setLayout(new ColumnLayout());
562
 
563
		// Ajout au principal
564
		main.add(left, new ColumnData(.49));
565
		main.add(right, new ColumnData(.49));
566
 
567
		TextField<String> tfAdresse1 = new TextField();
568
		tfAdresse1.setFieldLabel("Adresse");
319 gduche 569
		left.add(tfAdresse1, fd100);
293 gduche 570
		hmAdresse.put("tfAdresse1", tfAdresse1);
571
 
572
		TextField<String> tfAdresse2 = new TextField();
573
		tfAdresse2.setFieldLabel("Complément d'adresse");
319 gduche 574
		left.add(tfAdresse2, fd100);
293 gduche 575
		hmAdresse.put("tfAdresse2", tfAdresse2);
576
 
577
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
578
		cbPays.setFieldLabel("Pays");
579
		cbPays.setDisplayField("nom");
580
		cbPays.setEmptyText("Sélectionnez le pays:");
581
 
582
		ListStore<Valeur> storePays = new ListStore<Valeur>();
583
		cbPays.setStore(storePays);
584
 
319 gduche 585
		right.add(cbPays, fd100);
293 gduche 586
		hmAdresse.put("cbPays", cbPays);
587
 
588
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
589
			public void selectionChanged(SelectionChangedEvent se) {
590
					// Rafraichir avec le pays sélectionné
591
					obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
592
 
593
				}
594
		};
595
 
596
		cbPays.addSelectionChangedListener(selectionChange);
597
 
598
 
599
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
600
		cbRegion.setFieldLabel("Region");
601
		cbRegion.setDisplayField("nom");
602
		cbRegion.setEmptyText("Sélectionnez la région:");
603
		cbRegion.setVisible(false);
604
 
605
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
606
		cbRegion.setStore(storeRegion);
607
 
319 gduche 608
		right.add(cbRegion, fd100);
293 gduche 609
		hmAdresse.put("cbRegion", cbRegion);
610
 
611
		TextField<String> tfBoitePostale = new TextField<String>();
612
		tfBoitePostale.setFieldLabel("Boite postale");
319 gduche 613
		left.add(tfBoitePostale, fd100);
293 gduche 614
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
615
 
616
		TextField<Integer> tfCodePostal = new TextField<Integer>();
617
		tfCodePostal.setFieldLabel("Code postal");
319 gduche 618
		right.add(tfCodePostal, fd100);
293 gduche 619
		hmAdresse.put("tfCodePostal", tfCodePostal);
620
 
621
		TextField tfVille = new TextField();
622
		tfVille.setFieldLabel("Ville");
623
 
319 gduche 624
		right.add(tfVille, fd100);
293 gduche 625
		hmAdresse.put("tfVille", tfVille);
626
 
627
		// MAJ ComboBox
628
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
629
 
304 gduche 630
		FieldSet fsAdresse = new FieldSet();
631
		fsAdresse.setHeading("Adresse personnelle");
632
		fsAdresse.add(main);
293 gduche 633
 
304 gduche 634
		tiAdresses.add(fsAdresse);
635
 
293 gduche 636
	}
338 gduche 637
 
276 gduche 638
	/**
639
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
640
	 *
641
	 * @param barreOutils la barre d'outils à modifier
642
	 * */
643
	public static void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
644
 
645
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
646
		TextToolItem reinitialiser = new TextToolItem("Réinitialiser");
647
		reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
648
		reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
649
			public void componentSelected(ComponentEvent ce) {
650
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
651
			}
652
		});
653
		barreOutils.add(reinitialiser);
654
	}
655
 
656
	/**
338 gduche 657
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
658
	 *
659
	 * @param barreOutils la barre d'outils à modifier
660
	 * */
661
	public static void ajouterBoutonEnregistrerEtRevenir(ToolBar barreOutils)	{
662
 
663
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
664
		TextToolItem enregistrer = new TextToolItem("Enregistrer et revenir à la liste");
665
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
666
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
667
			public void componentSelected(ComponentEvent ce) {
668
				// TODO : Enregistrer le formulaire
669
			}
670
		});
671
		barreOutils.add(enregistrer);
672
	}
673
 
674
	/**
276 gduche 675
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
676
	 *
677
	 * @param barreOutils la barre d'outils à modifier
678
	 * */
679
	public static void ajouterBoutonEnregistrer(ToolBar barreOutils)	{
680
 
681
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
286 gduche 682
		TextToolItem enregistrer = new TextToolItem("Enregistrer");
683
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
684
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
276 gduche 685
			public void componentSelected(ComponentEvent ce) {
686
				// TODO : Enregistrer le formulaire
687
			}
688
		});
286 gduche 689
		barreOutils.add(enregistrer);
276 gduche 690
	}
691
 
692
	/**
693
	 * Ajouter le bouton annuler à la barre d'outils donnée
694
	 *
695
	 * @param barreOutils la barre d'outils à modifier
696
	 * */
697
	public static void ajouterBoutonAnnuler(ToolBar barreOutils)	{
698
 
699
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
338 gduche 700
		TextToolItem annuler = new TextToolItem("Revenir à la liste");
276 gduche 701
		annuler.addSelectionListener(new SelectionListener<ComponentEvent>() {
702
			public void componentSelected(ComponentEvent ce) {
703
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
704
			}
705
		});
706
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
707
		barreOutils.add(annuler);
708
	}
709
 
293 gduche 710
	public void obtenirListeRegionParPays(String strPays)	{
711
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
712
	}
276 gduche 713
 
714
 
293 gduche 715
 
276 gduche 716
	/*---------------------------------------------------------------------------------------
717
	 * 		RAFRAICHISSEMENT DU PANNEAU
718
	 * --------------------------------------------------------------------------------------
719
	 */
283 gduche 720
	public void rafraichir(Object nouvellesDonnees) {
721
		if (nouvellesDonnees instanceof ValeurListe){
722
 
723
 
724
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
725
 
726
			// Créer une liste de valeurs
727
			List<Valeur> liste = new ArrayList<Valeur>();
728
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
729
				liste.add(listeValeurs.get(it.next()));
730
			}
731
 
732
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
733
 
319 gduche 734
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 735
 
736
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
737
 
738
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
739
 
740
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
741
 
742
				remplirCombobox("cbSexe", liste, "hmIdentite");
283 gduche 743
 
293 gduche 744
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
745
 
746
				remplirCombobox("cbTelephone", liste, "hmIdentite");
319 gduche 747
 
748
				//Préselection du tél
749
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
750
				cbTelephone.setValue(liste.get(1));
293 gduche 751
 
752
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
283 gduche 753
 
293 gduche 754
				remplirCombobox("cbPays", liste, "hmAdresse");
283 gduche 755
 
293 gduche 756
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
283 gduche 757
 
293 gduche 758
				remplirCombobox("cbRegion", liste, "hmAdresse");
283 gduche 759
 
293 gduche 760
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 761
			}
293 gduche 762
 
763
 
286 gduche 764
		} else if (nouvellesDonnees instanceof Personne)	{
293 gduche 765
 
286 gduche 766
 
767
 
768
			//Mise à jour de la personne
769
			Personne personne = (Personne) nouvellesDonnees;
770
			personneSelectionnee = personne;
771
 
772
 
338 gduche 773
			//Prefixe
319 gduche 774
			String prefixe = (String) personne.get("ce_truk_prefix");
775
			ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
776
			cbPrefixe.setRawValue(prefixe);
777
 
286 gduche 778
			((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
779
			((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
780
			((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
781
			((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
782
			((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
783
 
293 gduche 784
			//FIXME : DATES
338 gduche 785
			DateField dfDateNaissance = ((DateField) hmIdentite.get("dfDateNaissance"));
786
			String strDateNaissance = (String) personne.get("naissance_date");
787
 
788
 
286 gduche 789
			((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
790
			//((DateField) hmIdentite.get("dfDateDeces")).setValue(new Date((String) personne.get("deces_date")));
791
			((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
792
 
293 gduche 793
		}
283 gduche 794
 
795
		if (nouvellesDonnees == null)
796
		{
319 gduche 797
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 798
 
799
			//Met à jour le nom Complet du formulaire
283 gduche 800
			String valeurRetour = "";
801
 
802
			// Prefixe
803
			String prefixe = "";
319 gduche 804
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 805
 
806
			if (valPrefixe != null)	{
807
				prefixe = valPrefixe.getNom();
293 gduche 808
			} else 	{
319 gduche 809
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 810
			}
283 gduche 811
 
293 gduche 812
 
283 gduche 813
			// Prénom
814
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
815
 
816
			// Nom
817
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
818
 
819
			// Suffixe
820
			String suffixe = "";
821
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
822
 
823
			if (valSuffixe != null)	{
824
				suffixe = valSuffixe.getNom();
293 gduche 825
			} else 	{
826
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 827
			}
828
 
829
			// Mettre à jour la valeur
830
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
831
			valeurRetour = valeurRetour.replaceAll("null", "");
832
 
833
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
834
 
835
			if (!valeurRetour.trim().equals(""))	{
836
				((LabelField) hmIdentite.get("nomComplet")).show();
837
			} else {
838
				((LabelField) hmIdentite.get("nomComplet")).hide();
839
			}
840
		}
338 gduche 841
 
842
		mediateur.masquerPopinChargement();
127 gduche 843
	}
844
 
293 gduche 845
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
846
 
847
		HashMap hm = null;
848
		if (hashMapId.equals("hmIdentite"))	{
849
			hm = hmIdentite;
850
		} else if (hashMapId.equals("hmAdresse")){
851
			hm = hmAdresse;
852
		} else {
853
			hm = hmInfosNat;
854
		}
855
 
856
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
857
		store.removeAll();
858
		store.add(liste);
859
		((ComboBox) hm.get(idComboBox)).setStore(store);
860
	}
130 gduche 861
 
862
 
863
 
127 gduche 864
}