Subversion Repositories eFlore/Applications.coel

Rev

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