Subversion Repositories eFlore/Applications.coel

Rev

Rev 1101 | Rev 1239 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
935 jpm 1
package org.tela_botanica.client.vues.personne;
127 gduche 2
 
283 gduche 3
import java.util.ArrayList;
352 gduche 4
import java.util.Collection;
376 gduche 5
import java.util.Date;
276 gduche 6
import java.util.HashMap;
283 gduche 7
import java.util.Iterator;
352 gduche 8
import java.util.LinkedList;
283 gduche 9
import java.util.List;
276 gduche 10
 
11
import org.tela_botanica.client.ComposantClass;
12
import org.tela_botanica.client.Mediateur;
13
import org.tela_botanica.client.RegistreId;
692 gduche 14
import org.tela_botanica.client.composants.ChampMultiValeurs;
701 gduche 15
import org.tela_botanica.client.composants.ChampMultiValeursImage;
722 gduche 16
import org.tela_botanica.client.composants.ChampMultiValeursMultiTypes;
973 gduche 17
import org.tela_botanica.client.composants.HashMapComposants;
907 jpm 18
import org.tela_botanica.client.configuration.Configuration;
991 gduche 19
import org.tela_botanica.client.images.Images;
127 gduche 20
import org.tela_botanica.client.interfaces.Rafraichissable;
293 gduche 21
 
352 gduche 22
import org.tela_botanica.client.modeles.Information;
850 gduche 23
import org.tela_botanica.client.modeles.MenuApplicationId;
280 gduche 24
import org.tela_botanica.client.modeles.Valeur;
283 gduche 25
import org.tela_botanica.client.modeles.ValeurListe;
935 jpm 26
import org.tela_botanica.client.modeles.personne.Personne;
27
import org.tela_botanica.client.modeles.personne.PersonneListe;
28
import org.tela_botanica.client.modeles.projet.Projet;
29
import org.tela_botanica.client.modeles.projet.ProjetListe;
991 gduche 30
import org.tela_botanica.client.modeles.publication.Publication;
31
import org.tela_botanica.client.modeles.publication.PublicationAPersonneListe;
32
import org.tela_botanica.client.modeles.publication.PublicationListe;
729 jp_milcent 33
import org.tela_botanica.client.util.Pattern;
622 gduche 34
import org.tela_botanica.client.util.UtilString;
935 jpm 35
import org.tela_botanica.client.vues.Formulaire;
127 gduche 36
 
488 gduche 37
import com.extjs.gxt.ui.client.event.Events;
276 gduche 38
import com.extjs.gxt.ui.client.Registry;
283 gduche 39
import com.extjs.gxt.ui.client.Style.Scroll;
821 gduche 40
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
386 gduche 41
 
1186 gduche 42
import com.extjs.gxt.ui.client.binding.FieldBinding;
376 gduche 43
import com.extjs.gxt.ui.client.binding.FormBinding;
386 gduche 44
 
488 gduche 45
import com.extjs.gxt.ui.client.event.ButtonEvent;
276 gduche 46
import com.extjs.gxt.ui.client.event.ComponentEvent;
47
import com.extjs.gxt.ui.client.event.KeyListener;
446 gduche 48
import com.extjs.gxt.ui.client.event.Listener;
280 gduche 49
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
50
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 51
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 52
import com.extjs.gxt.ui.client.store.ListStore;
127 gduche 53
import com.extjs.gxt.ui.client.widget.LayoutContainer;
319 gduche 54
import com.extjs.gxt.ui.client.widget.MessageBox;
338 gduche 55
 
991 gduche 56
import com.extjs.gxt.ui.client.widget.ContentPanel;
386 gduche 57
import com.extjs.gxt.ui.client.widget.Info;
276 gduche 58
import com.extjs.gxt.ui.client.widget.TabItem;
59
import com.extjs.gxt.ui.client.widget.TabPanel;
973 gduche 60
import com.extjs.gxt.ui.client.widget.Text;
283 gduche 61
 
356 gduche 62
import com.extjs.gxt.ui.client.widget.button.Button;
63
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
280 gduche 64
import com.extjs.gxt.ui.client.widget.form.ComboBox;
65
import com.extjs.gxt.ui.client.widget.form.DateField;
1186 gduche 66
import com.extjs.gxt.ui.client.widget.form.Field;
276 gduche 67
import com.extjs.gxt.ui.client.widget.form.FieldSet;
68
import com.extjs.gxt.ui.client.widget.form.LabelField;
446 gduche 69
import com.extjs.gxt.ui.client.widget.form.Radio;
70
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
286 gduche 71
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 72
import com.extjs.gxt.ui.client.widget.form.TextField;
456 gduche 73
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
850 gduche 74
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
276 gduche 75
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
76
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
991 gduche 77
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
319 gduche 78
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 79
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
356 gduche 80
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
821 gduche 81
import com.extjs.gxt.ui.client.widget.layout.TableData;
82
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
991 gduche 83
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
84
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
386 gduche 85
import com.google.gwt.core.client.GWT;
339 gduche 86
import com.google.gwt.i18n.client.DateTimeFormat;
991 gduche 87
import com.google.gwt.user.client.Window;
276 gduche 88
import com.google.gwt.user.client.ui.Widget;
127 gduche 89
 
850 gduche 90
public class PersonneForm extends Formulaire implements Rafraichissable {
127 gduche 91
 
730 jp_milcent 92
	// VARIABLES
276 gduche 93
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
991 gduche 94
	PersonneFormPublication tiPubli;
283 gduche 95
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
991 gduche 96
	protected Personne personneSelectionnee, personneSauvegarde = null;
276 gduche 97
 
657 gduche 98
	//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite
973 gduche 99
	private HashMapComposants hmIdentite = new HashMapComposants();
976 gduche 100
	private HashMapComposants hmAdresse = new HashMapComposants();
979 gduche 101
	private HashMapComposants hmInfosNat = new HashMapComposants();
730 jp_milcent 102
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
829 gduche 103
	private FormData fd100 = new FormData("95%");
657 gduche 104
 
668 gduche 105
	private Button enregistrer, enregistrerEtRevenir;
106
 
875 jpm 107
	private Personne personne = null;
108
	private String personneId = null;
376 gduche 109
	private FormBinding binding = null;
110
 
991 gduche 111
	//Publi
112
	private ComboBox<Publication> cbPubli;
113
	private ListStore<Publication> storePubli;
114
 
115
	// CONSTRUCTEUR
915 jpm 116
	public PersonneForm(Mediateur mediateurCourrant, String personneId) {
875 jpm 117
		initialiserPersonneForm(mediateurCourrant, personneId);
118
	}
446 gduche 119
 
875 jpm 120
	public PersonneForm(Mediateur mediateurCourrant, String personneId, Rafraichissable vueARafraichirApresValidation) {
121
		vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
1014 gduche 122
		initialiserPersonneForm(mediateurCourrant, personneId);
875 jpm 123
	}
850 gduche 124
 
875 jpm 125
	private void initialiserPersonneForm(Mediateur mediateurCourrant, String personneIdCourrant) {
1014 gduche 126
 
875 jpm 127
		personne = new Personne();
128
		personne.setId(personneIdCourrant);
129
		personneId = personneIdCourrant;
850 gduche 130
 
884 jpm 131
		String modeDeCreation = (UtilString.isEmpty(personneId) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
875 jpm 132
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.PERSONNE);
133
 
386 gduche 134
		initialiserComposants();
875 jpm 135
		genererTitreFormulaire();
850 gduche 136
 
1014 gduche 137
		mediateur.obtenirListeValeurEtRafraichir(this, "relationPersonnePublication");
875 jpm 138
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
139
			mediateur.selectionnerPersonne(this, personne, null);
850 gduche 140
		}
352 gduche 141
	}
142
 
875 jpm 143
	private void genererTitreFormulaire() {
144
		String titre = i18nC.personneModeAjout();
145
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
146
			 titre = i18nC.personneModeModifier()+" - "+i18nC.id()+": "+personneId;
147
		}
148
		panneauFormulaire.setHeading(titre);
149
	}
150
 
386 gduche 151
	public void initialiserComposants()	{
376 gduche 152
		personneSelectionnee = new Personne();
153
		personneSauvegarde = new Personne();
154
 
276 gduche 155
		initialiserOnglets();
156
 
157
		creerComposantsIdentite();
293 gduche 158
		creerComposantsAdresse();
821 gduche 159
		creerComposantsInfosNat();
991 gduche 160
		//creerComposantsPubli();
338 gduche 161
 
376 gduche 162
		binderPersonne(personneSelectionnee);
276 gduche 163
	}
164
 
165
	/**
166
	 * Crée les onglets identité, adresse et informations naturaliste
167
	 *
168
	 * */
169
	public void initialiserOnglets()	{
170
		//TabPanel
171
		TabPanel formulaireOnglets = new TabPanel();
172
 
173
		//Tab 1 : identite
991 gduche 174
		tiIdentite = creerOnglet(i18nC.personneIdentite(), "tiIdentite");
175
		tiIdentite.setStyleAttribute("padding", "0");
276 gduche 176
		formulaireOnglets.add(tiIdentite);
177
 
178
		//Tab 2 : Adresse
991 gduche 179
		tiAdresses = creerOnglet(i18nC.adresse(), "tiAdresses");
276 gduche 180
		formulaireOnglets.add(tiAdresses);
181
 
182
		//Tab 3 : Infos Naturalistes
991 gduche 183
		tiInfosNat = creerOnglet(i18nC.personneInfoNat(), "tiInfosNat");
184
		formulaireOnglets.add(tiInfosNat);
446 gduche 185
 
991 gduche 186
		tiPubli = new PersonneFormPublication(this);
187
		formulaireOnglets.add(tiPubli);
188
 
850 gduche 189
		getFormulaire().add(formulaireOnglets);
276 gduche 190
	}
191
 
192
	/**
193
	 * Crée les widgets pour l'onglet identité
194
	 *
195
	 * */
196
 
197
 
198
	public void creerComposantsIdentite()	{
676 gduche 199
		// Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite
200
		LayoutContainer left = new LayoutContainer();
201
		left.setLayout(new FormLayout());
829 gduche 202
		left.setStyleAttribute("padding", "15px");
203
 
676 gduche 204
		LayoutContainer right = new LayoutContainer();
205
		right.setLayout(new FormLayout());
829 gduche 206
		right.setStyleAttribute("padding", "15px");
456 gduche 207
 
676 gduche 208
		LayoutContainer main = new LayoutContainer();
209
 
210
		main.add(left, new ColumnData(.45));
211
		main.add(right, new ColumnData(.45));
212
 
213
		main.setLayout(new ColumnLayout());
214
		main.setHeight("100%");
215
		main.setScrollMode(Scroll.AUTO);
216
 
217
		// Création des champs
218
		FormLayout formLayout = new FormLayout();
219
		formLayout.setLabelAlign(LabelAlign.LEFT);
220
 
1086 jpm 221
		//+------------------------------------------------------------------------------------------------------------+
222
		// Fieldset PROJET
676 gduche 223
		FieldSet fsProjet = new FieldSet();
875 jpm 224
		fsProjet.setHeading(i18nC.menuProjet());
676 gduche 225
		fsProjet.setLayout(new FormLayout());
226
 
227
		ListStore<Projet> storeProjets = new ListStore<Projet>();
228
		ComboBox cbProjets = new ComboBox<Projet>();
875 jpm 229
		cbProjets.setFieldLabel(i18nC.personneProjet()+ " :");
230
		cbProjets.setEmptyText(i18nC.txtListeProjetDefaut());
676 gduche 231
		cbProjets.setLabelSeparator("");
232
		cbProjets.setDisplayField("nom");
233
		cbProjets.setEditable(false);
234
		cbProjets.setTriggerAction(TriggerAction.ALL);
235
		cbProjets.setStore(storeProjets);
236
		cbProjets.setAllowBlank(false);
981 jpm 237
		cbProjets.addStyleName(ComposantClass.OBLIGATOIRE);
238
		cbProjets.addListener(Events.Valid, creerEcouteurChampObligatoire());
1086 jpm 239
		fsProjet.add(cbProjets, new FormData(450, 0));
676 gduche 240
 
241
		hmIdentite.put("cbProjets", cbProjets);
242
 
928 jpm 243
		mediateur.selectionnerProjet(this, null);
456 gduche 244
 
676 gduche 245
		left.add(fsProjet);
1086 jpm 246
 
247
		//+------------------------------------------------------------------------------------------------------------+
248
		// Fieldset NOM
676 gduche 249
		FieldSet fsNoms = new FieldSet();
250
		fsNoms.setHeading("Noms");
251
		fsNoms.setLayout(formLayout);
456 gduche 252
 
676 gduche 253
		// Nom complet : Affiché que si valeurs saisies
254
		LabelField nomComplet = new LabelField();
875 jpm 255
		nomComplet.setFieldLabel(i18nC.personneNomComplet() +" :");
676 gduche 256
		nomComplet.hide();
456 gduche 257
 
676 gduche 258
		fsNoms.add(nomComplet);
259
		hmIdentite.put("nomComplet", nomComplet);
276 gduche 260
 
676 gduche 261
		//Préfixe
262
		ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
263
		ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
264
		cbPrefixe.setStore(storePrefixe);
265
		cbPrefixe.setDisplayField("nom");
266
		cbPrefixe.setEmptyText("Choisissez le préfixe:");
267
		cbPrefixe.setFieldLabel("Prefix");
268
 
269
		fsNoms.add(cbPrefixe);
270
		hmIdentite.put("cbPrefixe", cbPrefixe);
271
 
272
		mediateur.obtenirListeValeurEtRafraichir(this, "prefixe");
273
 
274
		//Prénom
275
		TextField<String> tfPrenom = new TextField<String>();
276
		tfPrenom.setFieldLabel("Prénom");
277
		tfPrenom.setName("prenom");
278
 
1086 jpm 279
		fsNoms.add(tfPrenom, new FormData(300, 0));
676 gduche 280
		hmIdentite.put("tfPrenom", tfPrenom);
281
 
282
		//Nom
283
		TextField<String> tfNom = new TextField<String>();
284
		tfNom.setFieldLabel("Nom");
285
		tfNom.setAllowBlank(false);
286
		tfNom.setName("nom");
981 jpm 287
		tfNom.addStyleName(ComposantClass.OBLIGATOIRE);
288
		tfNom.addListener(Events.Valid, creerEcouteurChampObligatoire());
676 gduche 289
 
1086 jpm 290
		fsNoms.add(tfNom, new FormData(300, 0));
676 gduche 291
		hmIdentite.put("tfNom", tfNom);
292
 
293
		//Suffixe
294
		ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
295
		ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
296
		cbSuffixe.setStore(storeSuffixe);
297
		cbSuffixe.setFieldLabel("Suffixe");
298
		cbSuffixe.setDisplayField("nom");
299
		cbSuffixe.setEmptyText("Choisissez un suffixe:");
300
 
301
		fsNoms.add(cbSuffixe);
302
		hmIdentite.put("cbSuffixe", cbSuffixe);
303
 
304
		mediateur.obtenirListeValeurEtRafraichir(this, "suffixes");
305
 
306
		TextField<String> tfAbreviation = new TextField<String>();
307
		tfAbreviation.setFieldLabel("Abréviation");
308
		tfAbreviation.setName("abreviation");
309
 
310
		fsNoms.add(tfAbreviation);
311
		hmIdentite.put("tfAbreviation", tfAbreviation);
312
 
821 gduche 313
		TableLayout layoutAutreNoms = new TableLayout(2);
314
		layoutAutreNoms.setCellVerticalAlign(VerticalAlignment.TOP);
315
		LayoutContainer autresNoms = new LayoutContainer(layoutAutreNoms);
316
		ChampMultiValeurs nomAutre = new ChampMultiValeurs("Autres noms",150);
317
		hmIdentite.put("nomAutre", nomAutre);
318
		autresNoms.add(nomAutre, new TableData("200px", "15px"));
676 gduche 319
 
821 gduche 320
		ChampMultiValeurs abreviationAutre = new ChampMultiValeurs("Autres abréviation",150);
321
		hmIdentite.put("abreviationAutre", abreviationAutre);
322
		autresNoms.add(abreviationAutre, new TableData("200px", "15px"));
323
		fsNoms.add(autresNoms);
376 gduche 324
 
676 gduche 325
		left.add(fsNoms);
326
 
1086 jpm 327
		//+------------------------------------------------------------------------------------------------------------+
328
		// Fieldset NAISSANCE ET DÉCÈS
973 gduche 329
		FieldSet fsNaissanceEtDeces = new FieldSet();
330
		fsNaissanceEtDeces.setHeading("Naissance et Décès");
331
		fsNaissanceEtDeces.setLayout(new ColumnLayout());
332
 
676 gduche 333
		formLayout = new FormLayout();
973 gduche 334
		formLayout.setLabelAlign(LabelAlign.TOP);
335
		LayoutContainer containerNaissance = new LayoutContainer(formLayout);
336
 
676 gduche 337
		DateField dfDateNaissance = new DateField();
338
		dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
973 gduche 339
		dfDateNaissance.setFieldLabel("Date de naissance");
676 gduche 340
		dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
341
 
973 gduche 342
		containerNaissance.add(dfDateNaissance);
676 gduche 343
		hmIdentite.put("dfDateNaissance", dfDateNaissance);
344
 
345
		// Lieu naissance
730 jp_milcent 346
		TextField<String> tfLieuNaissance = new TextField<String>();
973 gduche 347
		tfLieuNaissance.setFieldLabel("Lieu de naissance");
676 gduche 348
		tfLieuNaissance.setName("naissance_lieu");
349
 
973 gduche 350
		containerNaissance.add(tfLieuNaissance);
676 gduche 351
		hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
352
 
973 gduche 353
		fsNaissanceEtDeces.add(containerNaissance, new ColumnData(.5));
354
		left.add(fsNaissanceEtDeces);
355
 
676 gduche 356
		formLayout = new FormLayout();
973 gduche 357
		formLayout.setLabelAlign(LabelAlign.TOP);
358
		LayoutContainer containerDeces = new LayoutContainer(formLayout);
676 gduche 359
 
360
		Radio rbEstDecedee = new Radio();
973 gduche 361
		rbEstDecedee.setId("ce_deces");
362
 
676 gduche 363
		rbEstDecedee.setBoxLabel("oui");
829 gduche 364
		rbEstDecedee.setValueAttribute("1");
973 gduche 365
		rbEstDecedee.setId("rbEstD");
366
 
676 gduche 367
		rbEstDecedee.addListener(Events.Change, new Listener<ComponentEvent>() {
446 gduche 368
 
676 gduche 369
			public void handleEvent(ComponentEvent be) {
370
				if(((Radio) be.getComponent()).getValue().equals(true))	{
973 gduche 371
					hmIdentite.getDateField("dfDateDeces").setVisible(true);
372
					hmIdentite.getTextField("tfLieuDeces").setVisible(true);
676 gduche 373
				} else	{
973 gduche 374
					DateField dfDateDeces = hmIdentite.getDateField("dfDateDeces");
829 gduche 375
					dfDateDeces.setValue(null);
376
					dfDateDeces.setVisible(false);
377
 
973 gduche 378
					TextField tfLieuDeces = hmIdentite.getTextField("tfLieuDeces");
829 gduche 379
					tfLieuDeces.setValue(null);
380
					tfLieuDeces.setVisible(false);
676 gduche 381
				}
382
			}
383
		});
446 gduche 384
 
676 gduche 385
		DateField dfDateDeces = new DateField();
386
		dfDateDeces.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
387
		dfDateDeces.setFormatValue(true);
388
		dfDateDeces.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
973 gduche 389
		dfDateDeces.setFieldLabel("Date de décès");
676 gduche 390
		dfDateDeces.setVisible(false);
391
 
973 gduche 392
		containerDeces.add(dfDateDeces);
676 gduche 393
		hmIdentite.put("dfDateDeces", dfDateDeces);
394
 
730 jp_milcent 395
		TextField<String> tfLieuDeces = new TextField<String>();
973 gduche 396
		tfLieuDeces.setFieldLabel("Lieu de décès");
676 gduche 397
		tfLieuDeces.setName("deces_lieu");
398
		tfLieuDeces.setVisible(false);
399
 
973 gduche 400
		containerDeces.add(tfLieuDeces);
676 gduche 401
		hmIdentite.put("tfLieuDeces", tfLieuDeces);
973 gduche 402
		hmIdentite.put("rbEstDecedee", rbEstDecedee);
403
 
404
		Radio rbNestPasDecedee = new Radio();
405
		rbNestPasDecedee.setValueAttribute("0");
406
		rbNestPasDecedee.setBoxLabel("non");
407
		rbNestPasDecedee.setValue(true);
276 gduche 408
 
973 gduche 409
		RadioGroup rbgDeces = new RadioGroup();
1186 gduche 410
		rbgDeces.setId("rbgDeces");
411
 
973 gduche 412
		rbgDeces.setFieldLabel("Est décédée");
413
		rbgDeces.add(rbEstDecedee);
414
		rbgDeces.add(rbNestPasDecedee);
1186 gduche 415
		hmIdentite.put("rbgDeces", rbgDeces);
973 gduche 416
 
417
		containerDeces.add(rbgDeces);
418
 
419
		fsNaissanceEtDeces.add(containerDeces, new ColumnData(.5));
676 gduche 420
		tiIdentite.add(main);
1086 jpm 421
 
422
		//+------------------------------------------------------------------------------------------------------------+
423
		// Fieldset CONTACT
973 gduche 424
		FieldSet fsContact = new FieldSet();
425
		fsContact.setHeading("Contact");
426
		fsContact.setLayout(new RowLayout());
676 gduche 427
 
973 gduche 428
		ChampMultiValeursMultiTypes telephones = new ChampMultiValeursMultiTypes("Téléphones", 180, 100);
1086 jpm 429
		telephones.initialiserType("tel");
430
		fsContact.add(telephones, new FormData(450, 0));
722 gduche 431
		hmIdentite.put("telephones", telephones);
676 gduche 432
 
973 gduche 433
		ChampMultiValeurs courriels = new ChampMultiValeurs("Courriels", 280);
434
		courriels.setValidation(Pattern.email, "moi@domaine.fr");
1086 jpm 435
		fsContact.add(courriels, new FormData(450, 0));
692 gduche 436
		hmIdentite.put("courriels", courriels);
676 gduche 437
 
438
		LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout());
439
		fsContact.add(lcCourrielContainer);
440
		hmIdentite.put("lcCourrielContainer", lcCourrielContainer);
441
 
973 gduche 442
		fsContact.add(new Text(""));
443
 
692 gduche 444
		ChampMultiValeurs sites = new ChampMultiValeurs("Sites web");
695 gduche 445
		sites.setValeurParDefaut("http://");
729 jp_milcent 446
		sites.setValidation(Pattern.url, "http://www.monsite.com");
692 gduche 447
		fsContact.add(sites);
448
		hmIdentite.put("sites", sites);
1086 jpm 449
 
450
		right.add(fsContact);
451
 
452
		//+------------------------------------------------------------------------------------------------------------+
453
		// Fieldset AUTRES INFOS
676 gduche 454
		FieldSet fsAutresInfos = new FieldSet();
455
		fsAutresInfos.setHeading("Autres informations");
456
 
457
		formLayout = new FormLayout();
458
		formLayout.setLabelAlign(LabelAlign.LEFT);
459
		fsAutresInfos.setLayout(formLayout);
356 gduche 460
 
386 gduche 461
 
676 gduche 462
		formLayout = new FormLayout();
463
		formLayout.setLabelAlign(LabelAlign.TOP);
464
		LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout);
1086 jpm 465
 
676 gduche 466
		ListStore<Valeur> storeSexe = new ListStore<Valeur>();
467
		ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
468
		cbSexe.setStore(storeSexe);
469
		cbSexe.setFieldLabel("Sexe");
470
		cbSexe.setDisplayField("nom");
471
		cbSexe.setEmptyText("Choisissez le sexe:");
1101 gduche 472
		cbSexe.setTypeAhead(true);
473
		cbSexe.setTriggerAction(TriggerAction.ALL);
973 gduche 474
 
475
		FormData fd = new FormData();
476
		fd.setWidth(100);
477
		lcAutreInformations1.add(cbSexe, fd);
676 gduche 478
		hmIdentite.put("cbSexe", cbSexe);
386 gduche 479
 
676 gduche 480
		mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
481
 
482
		//Description
483
		TextArea taDescription = new TextArea();
484
		taDescription.setEmptyText("Saisissez une description");
485
		taDescription.setFieldLabel("Description");
486
		taDescription.setWidth("100%");
487
		taDescription.setName("description");
488
 
1086 jpm 489
		lcAutreInformations1.add(taDescription, new FormData(500, 200));
676 gduche 490
		hmIdentite.put("taDescription", taDescription);
491
 
492
		fsAutresInfos.add(lcAutreInformations1);
493
 
494
		// Logo
689 gduche 495
		LayoutContainer lcLogoUrl = new LayoutContainer();
496
		hmIdentite.put("lcLogoUrl", lcLogoUrl);
676 gduche 497
 
875 jpm 498
		ChampMultiValeursImage logo = new ChampMultiValeursImage(i18nC.personneLogos());
701 gduche 499
		logo.setImageHeight("150px");
500
		logo.setValeurParDefaut("http://");
729 jp_milcent 501
		logo.setValidation(Pattern.url, "http://www.monsite.com/mon_image.jpg");
701 gduche 502
		logo.setValeurBoutonSupprimer("Supprimer");
503
		hmIdentite.put("logos", logo);
676 gduche 504
 
701 gduche 505
		lcLogoUrl.add(logo);
676 gduche 506
 
701 gduche 507
		fsAutresInfos.add(logo);
689 gduche 508
 
509
		LayoutContainer lcAutreInformations2 = new LayoutContainer(new ColumnLayout());
510
		hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
676 gduche 511
		fsAutresInfos.add(lcAutreInformations2);
386 gduche 512
 
676 gduche 513
		right.add(fsAutresInfos);
1086 jpm 514
 
515
		//+------------------------------------------------------------------------------------------------------------+
676 gduche 516
		// Ajout des évènements saisi
517
		KeyListener klNoms = new KeyListener()	{
518
			public void componentKeyUp(ComponentEvent ev)	{
519
				rafraichir(null);
520
			}
521
		};
522
 
523
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
524
			public void selectionChanged(SelectionChangedEvent se) {
730 jp_milcent 525
				rafraichir(null);
526
			}
676 gduche 527
		};
283 gduche 528
 
676 gduche 529
		cbPrefixe.addSelectionChangedListener(selectionChange);
530
		cbPrefixe.addKeyListener(klNoms);
531
		tfPrenom.addKeyListener(klNoms);
532
		tfNom.addKeyListener(klNoms);
533
		cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 534
 
535
	}
536
 
293 gduche 537
	public void creerComposantsAdresse()	{
538
		// Gauche
539
		LayoutContainer left = new LayoutContainer();
540
		left.setLayout(new FormLayout());
821 gduche 541
		left.setStyleAttribute("padding", "15px");
293 gduche 542
		// Droite
543
		LayoutContainer right = new LayoutContainer();
544
		right.setLayout(new FormLayout());
545
 
546
		// Principal
547
		LayoutContainer main = new LayoutContainer();
821 gduche 548
		main.setLayout(new TableLayout(2));
293 gduche 549
 
550
		// Ajout au principal
821 gduche 551
		main.add(left);
552
		main.add(right);
293 gduche 553
 
554
		TextField<String> tfAdresse1 = new TextField();
555
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 556
		tfAdresse1.setName("adresse_01");
319 gduche 557
		left.add(tfAdresse1, fd100);
293 gduche 558
		hmAdresse.put("tfAdresse1", tfAdresse1);
559
 
560
		TextField<String> tfAdresse2 = new TextField();
561
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 562
		tfAdresse2.setName("adresse_02");
319 gduche 563
		left.add(tfAdresse2, fd100);
293 gduche 564
		hmAdresse.put("tfAdresse2", tfAdresse2);
565
 
566
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
567
		cbPays.setFieldLabel("Pays");
568
		cbPays.setDisplayField("nom");
569
		cbPays.setEmptyText("Sélectionnez le pays:");
570
 
571
		ListStore<Valeur> storePays = new ListStore<Valeur>();
572
		cbPays.setStore(storePays);
573
 
319 gduche 574
		right.add(cbPays, fd100);
293 gduche 575
		hmAdresse.put("cbPays", cbPays);
576
 
577
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
578
			public void selectionChanged(SelectionChangedEvent se) {
730 jp_milcent 579
				// Rafraichir avec le pays sélectionné
580
				obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
1036 gduche 581
				//mettreAJourRegion();
730 jp_milcent 582
			}
293 gduche 583
		};
1026 gduche 584
 
293 gduche 585
		cbPays.addSelectionChangedListener(selectionChange);
586
 
587
 
588
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
589
		cbRegion.setFieldLabel("Region");
590
		cbRegion.setDisplayField("nom");
591
		cbRegion.setEmptyText("Sélectionnez la région:");
592
		cbRegion.setVisible(false);
593
 
594
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
595
		cbRegion.setStore(storeRegion);
596
 
352 gduche 597
 
319 gduche 598
		right.add(cbRegion, fd100);
293 gduche 599
		hmAdresse.put("cbRegion", cbRegion);
600
 
601
		TextField<String> tfBoitePostale = new TextField<String>();
602
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 603
		tfBoitePostale.setName("bp");
604
 
319 gduche 605
		left.add(tfBoitePostale, fd100);
293 gduche 606
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
607
 
608
		TextField<Integer> tfCodePostal = new TextField<Integer>();
609
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 610
		tfCodePostal.setName("code_postal");
611
 
319 gduche 612
		right.add(tfCodePostal, fd100);
293 gduche 613
		hmAdresse.put("tfCodePostal", tfCodePostal);
614
 
615
		TextField tfVille = new TextField();
616
		tfVille.setFieldLabel("Ville");
376 gduche 617
		tfVille.setName("ville");
293 gduche 618
 
319 gduche 619
		right.add(tfVille, fd100);
293 gduche 620
		hmAdresse.put("tfVille", tfVille);
621
 
622
		// MAJ ComboBox
623
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
624
 
304 gduche 625
		FieldSet fsAdresse = new FieldSet();
626
		fsAdresse.setHeading("Adresse personnelle");
627
		fsAdresse.add(main);
293 gduche 628
 
304 gduche 629
		tiAdresses.add(fsAdresse);
293 gduche 630
	}
821 gduche 631
 
632
	public void creerComposantsInfosNat()	{
338 gduche 633
 
979 gduche 634
		FormLayout fl = new FormLayout();
635
		fl.setLabelAlign(LabelAlign.TOP);
821 gduche 636
		FieldSet fsInfosNat = new FieldSet();
979 gduche 637
		fsInfosNat.setLayout(fl);
821 gduche 638
		fsInfosNat.setTitle("Informations Naturaliste");
639
 
979 gduche 640
		TextArea taBiographie = new TextArea();
641
		taBiographie.setFieldLabel("Vie et renommée de l'auteur");
642
		taBiographie.setWidth("400");
643
		taBiographie.setName("biographie");
1086 jpm 644
		fsInfosNat.add(taBiographie, new FormData(800, 200));
979 gduche 645
 
875 jpm 646
		ChampMultiValeurs specialite = new ChampMultiValeurs(i18nC.personneSpecialite());
821 gduche 647
		fsInfosNat.add(specialite);
648
		hmInfosNat.put("specialite", specialite);
649
 
976 gduche 650
		ChampMultiValeursMultiTypes recolte = new ChampMultiValeursMultiTypes(i18nC.personneRecolte(), 200, 200);
651
 
857 jpm 652
		recolte.initialiserType("pays");
821 gduche 653
		hmInfosNat.put("recolte", recolte);
654
		fsInfosNat.add(recolte);
655
		tiInfosNat.add(fsInfosNat);
656
	}
657
 
991 gduche 658
	public void creerComposantsPubli(){
659
		//Création des composants de l'onglet publication
660
 
661
		ContentPanel cp = new ContentPanel();
662
		cp.setHeading("Publications dont la personne est le sujet");
663
		cp.setIcon(Images.ICONES.table());
664
		cp.setLayout(new FitLayout());
665
		cp.setFrame(true);
666
 
667
		ToolBar toolBar = new ToolBar();
668
 
669
		Button ajouterPubli = new Button("Ajouter");
670
		ajouterPubli.setIcon(Images.ICONES.vcardAjouter());
671
		ajouterPubli.addSelectionListener(new SelectionListener<ButtonEvent>() {
672
			@Override
673
			public void componentSelected(ButtonEvent ce) {
674
				Window.alert("ajout publi");
675
				/*StructureAPersonne membreDuPersonnel = new StructureAPersonne("", StructureAPersonne.ROLE_EQUIPE, StructureAPersonne.ETAT_AJOUTE);
676
				ajouterMembreAGrillePersonnel(membreDuPersonnel);*/
677
			}
678
		});
679
		toolBar.add(ajouterPubli);
680
 
681
		toolBar.add(new SeparatorToolItem());
682
 
683
		Button supprimerPubli = new Button("Supprimer");
684
		supprimerPubli.setIcon(Images.ICONES.vcardSupprimer());
685
		supprimerPubli.addSelectionListener(new SelectionListener<ButtonEvent>() {
686
			@Override
687
			public void componentSelected(ButtonEvent ce) {
688
				/*StructureAPersonne personne = grillePersonnel.getSelectionModel().getSelectedItem();
689
				if (personne != null) {
690
					// Ajout de la personne supprimée à la liste
691
					if (personne.getIdPersonne() != null && !personne.getIdPersonne().equals("")) {
692
						personnelSupprime.put(personne.getId(), personne);
693
					}
694
 
695
					// Suppression de l'enregistrement de la grille
696
					grillePersonnel.getStore().remove(personne);
697
 
698
					// Désactivation du bouton supprimer si la grille contient plus d'élément
699
					if (grillePersonnel.getStore().getCount() == 0) {
700
						//TODO : check : Item -> component
701
						ce.getComponent().disable();
702
					}
703
				}*/
704
				Window.alert("supprimer");
705
			}
706
		});
707
		toolBar.add(supprimerPubli);
708
 
709
		toolBar.add(new SeparatorToolItem());
710
 
711
		Button rafraichirPersonnelBtn = new Button("Rafraichir");
712
		rafraichirPersonnelBtn.setIcon(Images.ICONES.rafraichir());
713
		rafraichirPersonnelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {
714
			@Override
715
			public void componentSelected(ButtonEvent ce) {
716
				//rafraichirPersonnel();
717
				Window.alert("rafraichir");
718
			}
719
		});
720
		toolBar.add(rafraichirPersonnelBtn);
721
 
722
		//Ajout d'une ComboBox
723
		storePubli = new ListStore<Publication>();
724
		storePubli.add(new ArrayList<Publication>());
725
 
726
		cbPubli = new ComboBox<Publication>();
727
		cbPubli.setWidth(200);
728
		cbPubli.setEmptyText("Chercher une publication existante...");
729
		cbPubli.setTriggerAction(TriggerAction.ALL);
730
		cbPubli.setEditable(true);
731
		cbPubli.setDisplayField("fmt_nom_complet");
732
		cbPubli.setStore(storePubli);
733
		cbPubli.addKeyListener(new KeyListener() {
734
 
735
			public void componentKeyUp(ComponentEvent ce) {
736
				if (!ce.isNavKeyPress() && cbPubli.getRawValue() != null && cbPubli.getRawValue().length() > 0) {
737
					rafraichirPublicationsExistante(cbPubli.getRawValue());
738
				}
739
			}
740
 
741
		});
742
 
743
		toolBar.add(cbPubli);
744
		toolBar.add(new SeparatorToolItem());
745
		cp.setTopComponent(toolBar);
746
 
747
 
748
		tiPubli.add(cp);
749
	}
750
 
751
	public void rafraichirPublicationsExistante(String nomPubli)	{
752
		nomPubli +="%";
753
		mediateur.selectionnerPublicationParNomComplet(this, null, nomPubli);
754
	}
755
 
276 gduche 756
	/**
757
	 * Ajouter le bouton annuler à la barre d'outils donnée
758
	 *
759
	 * @param barreOutils la barre d'outils à modifier
760
	 * */
356 gduche 761
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 762
 
763
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 764
		Button annuler = new Button("Revenir à la liste");
488 gduche 765
		annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {
766
			public void componentSelected(ButtonEvent ce) {
276 gduche 767
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
768
			}
769
		});
770
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
771
		barreOutils.add(annuler);
772
	}
773
 
293 gduche 774
	public void obtenirListeRegionParPays(String strPays)	{
775
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
776
	}
276 gduche 777
 
730 jp_milcent 778
	// RAFRAICHISSEMENT DU PANNEAU
779
 
283 gduche 780
	public void rafraichir(Object nouvellesDonnees) {
991 gduche 781
		if (nouvellesDonnees instanceof PublicationAPersonneListe)	{
782
			Information info = new Information();
783
			info.setType("publication_liees");
784
			info.setDonnee(0, (PublicationAPersonneListe) nouvellesDonnees);
785
			tiPubli.rafraichir(info);
786
		} else if (nouvellesDonnees instanceof ValeurListe) {
1014 gduche 787
 
283 gduche 788
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
789
 
790
			// Créer une liste de valeurs
791
			List<Valeur> liste = new ArrayList<Valeur>();
792
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
793
				liste.add(listeValeurs.get(it.next()));
794
			}
1014 gduche 795
			if (listeValeurs.getId().equals(config.getListeId("relationPersonnePublication")))	{
796
				tiPubli.rafraichir(nouvellesDonnees);
797
			} else if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
319 gduche 798
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 799
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
800
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
801
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
1101 gduche 802
 
803
				//Ajout de la valeur "Inconnu"
804
				ComboBox<Valeur> cbSexe = hmAdresse.getComboBoxValeur("cbSexe");
805
				Valeur inconnu = new Valeur();
806
				inconnu.set("nom", "Inconnu");
807
				inconnu.set("id", "0");
808
				liste.add(0, inconnu);
809
 
293 gduche 810
				remplirCombobox("cbSexe", liste, "hmIdentite");
1101 gduche 811
 
812
				/*List<Valeur> selection = new LinkedList<Valeur>();
813
				selection.add(inconnu);
814
				cbSexe.setSelection(s);*/
815
 
816
 
293 gduche 817
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
818
				remplirCombobox("cbTelephone", liste, "hmIdentite");
730 jp_milcent 819
 
319 gduche 820
				//Préselection du tél
973 gduche 821
				ComboBox<Valeur> cbTelephone = hmIdentite.getComboBoxValeur("cbTelephone");
319 gduche 822
				cbTelephone.setValue(liste.get(1));
293 gduche 823
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
824
				remplirCombobox("cbPays", liste, "hmAdresse");
825
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
826
				remplirCombobox("cbRegion", liste, "hmAdresse");
1033 gduche 827
				mettreAJourRegion();
976 gduche 828
				hmAdresse.getComboBox("cbRegion").setVisible(true);
1026 gduche 829
 
283 gduche 830
			}
456 gduche 831
		} else if (nouvellesDonnees instanceof ProjetListe) {
832
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
730 jp_milcent 833
			List<Projet> liste = projets.toList();
456 gduche 834
 
973 gduche 835
			ComboBox cbProjets = hmIdentite.getComboBox("cbProjets");
456 gduche 836
			ListStore<Projet> storeProjets= cbProjets.getStore();
837
			storeProjets.removeAll();
838
			storeProjets.add(liste);
839
			cbProjets.setStore(storeProjets);
991 gduche 840
		} else if (nouvellesDonnees instanceof PublicationListe)	{
841
 
842
			PublicationListe publicationListe = (PublicationListe) nouvellesDonnees;
843
			List<Publication> liste = publicationListe.toList();
844
			storePubli.removeAll();
845
			storePubli.add(liste);
846
			cbPubli.setStore(storePubli);
847
 
352 gduche 848
		} else if (nouvellesDonnees instanceof Information)	{
849
			Information info = (Information) nouvellesDonnees;
386 gduche 850
			if (info.getType().equals("ajout_personne"))	{
884 jpm 851
				if (info.getDonnee(0) != null) {
852
					personneSelectionnee.setId(info.getDonnee(0).toString());
853
					GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
854
					Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
855
					repandreRafraichissement();
856
					if (clicBoutonvalidation)	{
857
						mediateur.clicMenu(menuIdCourant);
858
					}
859
				} else {
860
					Info.display("Enregistrement", info.getMessages().toString());
852 gduche 861
				}
433 gduche 862
			} else if (info.getType().equals("modification_personne"))	{
863
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
884 jpm 864
				repandreRafraichissement();
852 gduche 865
				if (clicBoutonvalidation)	{
866
					mediateur.clicMenu(menuIdCourant);
867
				}
884 jpm 868
			} else if (info.getType().equals("maj_utilisateur"))	{
668 gduche 869
				gererEtatActivationBouton();
386 gduche 870
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
776 gduche 871
 
730 jp_milcent 872
				Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
873
				Iterator itPersonneListe = colPersonneListe.iterator();
874
				Personne personne = (Personne) itPersonneListe.next();
875
 
991 gduche 876
				//TODO : Je vois pas l'intérêt des lignes ci dessous..
730 jp_milcent 877
				personneSauvegarde = new Personne();
878
				personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
879
 
880
				binderPersonne(personne);
881
 
776 gduche 882
				mettreAJourPersonne(personne);
730 jp_milcent 883
 
884
				nouvellesDonnees = null;
885
			} else {
886
				Info.display("messages", info.getMessages().toString());
887
			}
776 gduche 888
		}
283 gduche 889
 
730 jp_milcent 890
		if (nouvellesDonnees == null) {
973 gduche 891
			ComboBox<Valeur> cb= hmIdentite.getComboBoxValeur("cbPrefixe");
293 gduche 892
 
893
			//Met à jour le nom Complet du formulaire
283 gduche 894
			String valeurRetour = "";
895
 
896
			// Prefixe
897
			String prefixe = "";
973 gduche 898
			Valeur valPrefixe = cb.getValue();
283 gduche 899
 
900
			if (valPrefixe != null)	{
901
				prefixe = valPrefixe.getNom();
293 gduche 902
			} else 	{
973 gduche 903
				prefixe =  (String) cb.getRawValue();
293 gduche 904
			}
283 gduche 905
 
906
			// Prénom
973 gduche 907
			String prenom = (String) hmIdentite.getTextField("tfPrenom").getValue();
283 gduche 908
 
909
			// Nom
973 gduche 910
			String nom = (String) hmIdentite.getTextField("tfNom").getValue();
283 gduche 911
 
912
			// Suffixe
973 gduche 913
			ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe");
914
 
283 gduche 915
			String suffixe = "";
973 gduche 916
			Valeur valSuffixe = cbSuffixe.getValue();
283 gduche 917
 
918
			if (valSuffixe != null)	{
919
				suffixe = valSuffixe.getNom();
293 gduche 920
			} else 	{
973 gduche 921
				suffixe =  (String) cbSuffixe.getRawValue();
283 gduche 922
			}
923
 
924
			// Mettre à jour la valeur
925
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
926
			valeurRetour = valeurRetour.replaceAll("null", "");
927
 
973 gduche 928
			hmIdentite.getLabelField("nomComplet").setValue(valeurRetour);
283 gduche 929
 
930
			if (!valeurRetour.trim().equals(""))	{
973 gduche 931
				hmIdentite.getLabelField("nomComplet").show();
283 gduche 932
			} else {
973 gduche 933
				hmIdentite.getLabelField("nomComplet").hide();
283 gduche 934
			}
935
		}
338 gduche 936
 
937
		mediateur.masquerPopinChargement();
456 gduche 938
 
461 gduche 939
		if (this.mode.equals(MODE_AJOUTER))	{
668 gduche 940
			gererEtatActivationBouton();
456 gduche 941
		}
127 gduche 942
	}
943
 
884 jpm 944
	private void repandreRafraichissement() {
945
		if (vueExterneARafraichirApresValidation != null) {
946
			String type = "personne_modifiee";
947
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
948
				type = "personne_ajoutee";
949
			}
950
			Information info = new Information(type);
951
			info.setDonnee(0, personneSelectionnee);
952
			vueExterneARafraichirApresValidation.rafraichir(info);
953
		}
954
	}
955
 
1026 gduche 956
	private void mettreAJourRegion()	{
1033 gduche 957
		//Met à jour la combo box en sélectionnant la valeur enregistrée pour la personne
1026 gduche 958
		ComboBox<Valeur> cbRegion = hmAdresse.getComboBoxValeur("cbRegion");
1036 gduche 959
		if (personneSelectionnee.get("ce_truk_region").toString().startsWith("AUTRE##")) {
960
			cbRegion.setRawValue(personneSelectionnee.get("ce_truk_region").toString().replaceFirst("^AUTRE##", ""));
961
		} else if (personneSelectionnee.get("ce_truk_region") != null && cbRegion.getStore().getCount() > 0)	{
1026 gduche 962
			Valeur valeurRegion = cbRegion.getStore().findModel("id_valeur", personneSelectionnee.get("ce_truk_region"));
963
			if (valeurRegion!=null)	{
964
				cbRegion.setValue(valeurRegion);
965
			}
966
		}
967
	}
1036 gduche 968
 
776 gduche 969
	private void mettreAJourPersonne(Personne personne)	{
970
		//Mise à jour de la personne
971
		//Personne personne = (Personne) nouvellesDonnees;
973 gduche 972
		ComboBox cbProjets = hmIdentite.getComboBox("cbProjets");
776 gduche 973
		cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
974
 
975
		//Prefixe
976
		String prefixe = personne.get("ce_truk_prefix");
973 gduche 977
		ComboBox<Valeur> cbPrefixe = hmIdentite.getComboBoxValeur("cbPrefixe");
776 gduche 978
 
979
 
980
		String prefixeCourant = personne.get("ce_truk_prefix");
981
		if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
982
			cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
983
		}	else	{
984
			cbPrefixe.setRawValue(prefixeCourant);
985
		}
986
 
973 gduche 987
		hmIdentite.getTextField("tfPrenom").setValue(personne.get("prenom"));
988
		hmIdentite.getTextField("tfNom").setValue(personne.get("nom"));
776 gduche 989
 
990
		//Suffixe
991
		String suffixe = personne.get("ce_truk_suffixe");
973 gduche 992
		ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe");
776 gduche 993
 
994
		String suffixeCourant = personne.get("ce_truk_suffix");
995
		if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
996
			cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
997
		}	else	{
998
			cbSuffixe.setRawValue(suffixeCourant);
999
		}
1000
 
973 gduche 1001
		hmIdentite.getChampMultiValeurs("nomAutre").peupler(personne.getString("truk_nom_autre"));
1002
		hmIdentite.getTextField("tfAbreviation").setValue(personne.get("abreviation"));
1003
		hmIdentite.getChampMultiValeurs("abreviationAutre").peupler(personne.getString("truk_abreviation_autre"));
776 gduche 1004
 
973 gduche 1005
		hmIdentite.getDateField("dfDateNaissance").setValue(personne.getDate("naissance_date"));
1006
		hmIdentite.getTextField("tfLieuNaissance").setValue(personne.get("naissance_lieu"));
776 gduche 1007
 
1186 gduche 1008
 
829 gduche 1009
		if (personne.estDecedee())	{
973 gduche 1010
			hmIdentite.getDateField("dfDateDeces").setValue(personne.getDate("deces_date"));
1011
			hmIdentite.getTextField("tfLieuDeces").setValue(personne.get("deces_lieu"));
1012
			Radio rbEstDecede = hmIdentite.getRadio("rbEstDecedee");
829 gduche 1013
			rbEstDecede.setValue(true);
1014
		}
776 gduche 1015
 
973 gduche 1016
		hmIdentite.getChampMultiValeurs("telephones").peupler(personne.getString("truk_telephone"));
776 gduche 1017
 
1018
		//Courriel
973 gduche 1019
		hmIdentite.getChampMultiValeurs("courriels").peupler(personne.getCourriel());
776 gduche 1020
 
1021
		//Sites web
973 gduche 1022
		hmIdentite.getChampMultiValeurs("sites").peupler(personne.getString("truk_url"));
776 gduche 1023
 
1024
		// Sexe
1025
		String strSexe = personne.get("ce_sexe");
973 gduche 1026
		ComboBox<Valeur> cbSexe = hmIdentite.getComboBoxValeur("cbSexe");
776 gduche 1027
 
1028
		if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)	{
1029
			cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
1030
		}
1031
 
973 gduche 1032
		hmIdentite.getTextArea("taDescription").setRawValue((String) personne.get("description"));
776 gduche 1033
 
1034
		//Logo
973 gduche 1035
		hmIdentite.getChampMultiValeurs("logos").peupler(personne.getString("truk_logo"));
776 gduche 1036
 
1037
		/*--------------------------------------------------
1038
		                      Adresse
1039
		 ---------------------------------------------------*/
1040
 
1041
		// Adresse
976 gduche 1042
		hmAdresse.getTextField("tfAdresse1").setValue((String) personne.get("adresse_01"));
776 gduche 1043
 
1044
		// Complément
976 gduche 1045
		hmAdresse.getTextField("tfAdresse2").setValue((String) personne.get("adresse_02"));
776 gduche 1046
 
1047
		//Boite postale
976 gduche 1048
		hmAdresse.getTextField("tfBoitePostale").setValue((String) personne.get("bp"));
776 gduche 1049
 
1050
		//Pays
1026 gduche 1051
		String strPays = personne.get("ce_truk_pays");
976 gduche 1052
		ComboBox<Valeur> cbPays = hmAdresse.getComboBoxValeur("cbPays");
1026 gduche 1053
		if (cbPays.getStore().findModel("id_valeur", strPays) != null)	{
1054
			cbPays.setValue(cbPays.getStore().findModel("id_valeur", strPays));
1055
			cbPays.fireEvent(Events.OnChange);
776 gduche 1056
		}	else	{
1057
			cbPays.setRawValue(strPays);
1058
		}
1059
 
1026 gduche 1060
		//Région : doit être chargé après chargement de la liste des régions...
1061
		String strRegion = personne.get("ce_truk_region");
1062
 
776 gduche 1063
		if ((strRegion!=null)&&(!strRegion.equals("")))	{
976 gduche 1064
			ComboBox<Valeur> cbRegion = hmAdresse.getComboBoxValeur("cbRegion");
1026 gduche 1065
			System.out.println(cbRegion.getStore().getCount());
776 gduche 1066
			cbRegion.setVisible(true);
1067
 
1026 gduche 1068
			if (cbRegion.getStore().findModel("id_valeur", strRegion) != null)	{
1069
				cbRegion.setValue(cbRegion.getStore().findModel("id_valeur", strRegion));
776 gduche 1070
			}	else	{
1071
				cbRegion.setRawValue(strRegion);
1072
			}
1073
		}
1074
 
1075
		//Cp
976 gduche 1076
		hmAdresse.getTextField("tfCodePostal").setValue(personne.get("code_postal"));
776 gduche 1077
 
1078
		//Ville
976 gduche 1079
		hmAdresse.getTextField("tfVille").setValue(personne.get("ville"));
776 gduche 1080
 
821 gduche 1081
		/*--------------------------------------------------------
1082
		 * 					Infos naturalistes
1083
		 * -----------------------------------------------------*/
1084
 
979 gduche 1085
		hmInfosNat.getChampMultiValeurs("specialite").peupler(personne.getString("ce_truk_specialite"));
976 gduche 1086
		String tr = personne.getString("truk_recolte");
979 gduche 1087
		hmInfosNat.getChampMultiValeursMultiTypes("recolte").peupler(tr);
991 gduche 1088
 
1089
		//Onglet publi
1090
		tiPubli.mettreAJourPersonne();
776 gduche 1091
		gererEtatActivationBouton();
1092
	}
730 jp_milcent 1093
 
293 gduche 1094
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
1095
		HashMap hm = null;
1096
		if (hashMapId.equals("hmIdentite"))	{
1097
			hm = hmIdentite;
1098
		} else if (hashMapId.equals("hmAdresse")){
1099
			hm = hmAdresse;
1100
		} else {
1101
			hm = hmInfosNat;
1102
		}
1103
 
1104
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1105
 
293 gduche 1106
		store.removeAll();
1107
		store.add(liste);
1108
		((ComboBox) hm.get(idComboBox)).setStore(store);
1109
	}
130 gduche 1110
 
668 gduche 1111
	private void gererEtatActivationBouton()	{
850 gduche 1112
	/*	if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
668 gduche 1113
			enregistrer.setEnabled(false);
1114
			enregistrerEtRevenir.setEnabled(false);
1115
		} else	{
1116
			enregistrer.setEnabled(true);
1117
			enregistrerEtRevenir.setEnabled(true);
850 gduche 1118
		}*/
668 gduche 1119
	}
1120
 
850 gduche 1121
	public void reinitialiserFormulaire()	{
461 gduche 1122
		mediateur.afficherPopinChargement();
776 gduche 1123
		mettreAJourPersonne(personneSauvegarde);
376 gduche 1124
		mediateur.masquerPopinChargement();
1125
	}
1126
 
1127
	public void binderPersonne(Personne personne)	{
850 gduche 1128
		binding = new FormBinding(getFormulaire());
731 jp_milcent 1129
 
376 gduche 1130
		personneSelectionnee = personne;
1186 gduche 1131
 
1132
		FieldBinding f = new FieldBinding((RadioGroup) hmIdentite.get("rbgDeces"), null);
376 gduche 1133
		binding.autoBind();
1186 gduche 1134
		binding.removeFieldBinding(f);
1135
 
376 gduche 1136
		binding.bind(personneSelectionnee);
1137
		layout();
1138
	}
973 gduche 1139
 
376 gduche 1140
	private String obtenirValeurCombo(String strComboName)	{
1141
		String strValeur = "";
1142
		Valeur valeur;
1143
 
973 gduche 1144
		ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur(strComboName);
376 gduche 1145
		if (combo == null)	{
976 gduche 1146
			combo = hmAdresse.getComboBoxValeur(strComboName);
376 gduche 1147
		}
829 gduche 1148
		strValeur = combo.getRawValue();
1026 gduche 1149
		valeur = combo.getValue();
829 gduche 1150
		if (valeur != null)	{
1151
			strValeur = valeur.getId();
1152
		}
1153
 
376 gduche 1154
		return strValeur;
1155
	}
850 gduche 1156
 
934 jpm 1157
	public boolean soumettreFormulaire() {
1014 gduche 1158
		tiPubli.collecter();
850 gduche 1159
		if (verifierFormulaire())	{
991 gduche 1160
			tiPubli.soumettre();
850 gduche 1161
			mediateur.enregistrerPersonne(this, personneSelectionnee);
1162
		}
1163
		return true;
1164
	}
1165
 
934 jpm 1166
	public boolean verifierFormulaire() {
884 jpm 1167
		boolean success = true;
1168
		LinkedList<String> lstMessageErreur = new LinkedList<String>();
850 gduche 1169
 
973 gduche 1170
		ComboBox<Projet> cbProjets = hmIdentite.getComboBox("cbProjets");
850 gduche 1171
		Projet projet = cbProjets.getValue();
1172
		if (projet == null)	{
1173
			lstMessageErreur.add("Le projet n'a pas été renseigné");
1174
		} else {
1175
			personneSelectionnee.set("ce_projet", projet.getId());
1176
		}
1177
 
973 gduche 1178
		String strTfNom = (String) hmIdentite.getTextField("tfNom").getValue();
850 gduche 1179
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1180
			lstMessageErreur.add("Le nom n'a pas été saisi");
1181
		} else {
1182
			strTfNom = UtilString.ucFirst(strTfNom);
1183
			personneSelectionnee.set("nom", strTfNom);
1184
		}
1185
 
973 gduche 1186
		String strTfPrenom = (String) hmIdentite.getTextField("tfPrenom").getValue();
850 gduche 1187
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1188
 
1189
		//Préparer les données
973 gduche 1190
		ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur("cbSexe");
850 gduche 1191
		Valeur valeur;
1192
		String strValeur = "";
1193
 
973 gduche 1194
		valeur = combo.getValue();
850 gduche 1195
		if (valeur!=null)	{
1196
			personneSelectionnee.set("ce_sexe", valeur.getId());
1197
		}
1198
 
1199
		strValeur = obtenirValeurCombo("cbPrefixe");
1200
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1201
 
1202
		strValeur = obtenirValeurCombo("cbSuffixe");
1203
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1204
 
973 gduche 1205
		String nomAutre = hmIdentite.getChampMultiValeurs("nomAutre").getValeurs();
850 gduche 1206
		personneSelectionnee.set("truk_nom_autre", nomAutre);
1207
 
973 gduche 1208
		String abreviationAutre = hmIdentite.getChampMultiValeurs("abreviationAutre").getValeurs();
850 gduche 1209
		personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);
1210
 
973 gduche 1211
		personneSelectionnee.set("truk_courriel", hmIdentite.getChampMultiValeurs("courriels").getValeurs());
850 gduche 1212
 
1213
 
1214
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1215
		String strPrefixe = "";
973 gduche 1216
		combo = hmIdentite.getComboBoxValeur("cbPrefixe");
1217
		valeur = combo.getValue();
850 gduche 1218
		if (valeur != null)	{
1219
			strPrefixe = valeur.getNom();
1220
		} else {
1221
			strPrefixe = combo.getRawValue();
1222
		}
1223
 
1224
		String strSuffixe = "";
973 gduche 1225
		combo = hmIdentite.getComboBox("cbSuffixe");
1226
		valeur = combo.getValue();
850 gduche 1227
		if (valeur != null)	{
1228
			strSuffixe = valeur.getNom() + " ";
1229
		} else {
1230
			strSuffixe = combo.getRawValue() +" ";
1231
		}
1232
 
1233
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
1234
 
973 gduche 1235
		DateField dfDateNaissance = hmIdentite.getDateField("dfDateNaissance");
850 gduche 1236
		Date naissanceDate = dfDateNaissance.getValue();
1237
		personneSelectionnee.setNaissanceDate(naissanceDate);
1238
 
973 gduche 1239
		Radio rbEstDecedee = hmIdentite.getRadio("rbEstDecedee");
850 gduche 1240
		if (rbEstDecedee.getValue() == true)	{
973 gduche 1241
			DateField dfDecesDate = hmIdentite.getDateField("dfDateDeces");
1242
			String decesLieu = (String) hmIdentite.getTextField("tfLieuDeces").getValue();
850 gduche 1243
			personneSelectionnee.setDeces(dfDecesDate.getValue(), decesLieu);
1244
		}	else	{
1245
			personneSelectionnee.setNonDecedee();
1246
		}
1247
 
1248
		strValeur = obtenirValeurCombo("cbPays");
1249
		personneSelectionnee.set("ce_truk_pays", strValeur);
1250
 
1026 gduche 1251
		strValeur = obtenirValeurCombo("cbRegion");
1036 gduche 1252
		ComboBox<Valeur> cbRegions = hmAdresse.getComboBoxValeur("cbRegion");
1253
		if (cbRegions.getStore().findModel("id", strValeur) == null)	{
1254
			strValeur = "AUTRE##" + strValeur;
1255
		}
850 gduche 1256
		personneSelectionnee.set("ce_truk_region", strValeur);
1257
 
973 gduche 1258
		personneSelectionnee.set("truk_telephone", hmIdentite.getChampMultiValeursMultiTypes("telephones").getValeurs());
850 gduche 1259
 
973 gduche 1260
		String logoUrls = hmIdentite.getChampMultiValeursImage("logos").getValeurs();
850 gduche 1261
		personneSelectionnee.set("truk_logo", logoUrls);
1262
 
973 gduche 1263
		personneSelectionnee.set("truk_url", hmIdentite.getChampMultiValeurs("sites").getValeurs());
850 gduche 1264
 
1265
		//Infos Naturalistes
1266
		String recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs();
1267
		personneSelectionnee.set("truk_recolte", recolte);
1268
 
1269
		String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();
1270
		personneSelectionnee.set("ce_truk_specialite", specialite);
1271
 
1014 gduche 1272
		lstMessageErreur.addAll(tiPubli.verifier());
850 gduche 1273
 
884 jpm 1274
		if (lstMessageErreur.size() != 0)	{
850 gduche 1275
			String strMessagesErreur = "<span><br />";
1276
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1277
			while (itMessagesErreur.hasNext())	{
1278
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
1279
			}
1280
			strMessagesErreur += "</span>";
1281
 
1282
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
1283
 			success = false;
1284
		}
1285
 
1286
		return success;
1287
	}
127 gduche 1288
}