Subversion Repositories eFlore/Applications.coel

Rev

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