Subversion Repositories eFlore/Applications.coel

Rev

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