Subversion Repositories eFlore/Applications.coel

Rev

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