Subversion Repositories eFlore/Applications.coel

Rev

Rev 1086 | Rev 1186 | 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:");
1101 gduche 467
		cbSexe.setTypeAhead(true);
468
		cbSexe.setTriggerAction(TriggerAction.ALL);
973 gduche 469
 
470
		FormData fd = new FormData();
471
		fd.setWidth(100);
472
		lcAutreInformations1.add(cbSexe, fd);
676 gduche 473
		hmIdentite.put("cbSexe", cbSexe);
386 gduche 474
 
676 gduche 475
		mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
476
 
477
		//Description
478
		TextArea taDescription = new TextArea();
479
		taDescription.setEmptyText("Saisissez une description");
480
		taDescription.setFieldLabel("Description");
481
		taDescription.setWidth("100%");
482
		taDescription.setName("description");
483
 
1086 jpm 484
		lcAutreInformations1.add(taDescription, new FormData(500, 200));
676 gduche 485
		hmIdentite.put("taDescription", taDescription);
486
 
487
		fsAutresInfos.add(lcAutreInformations1);
488
 
489
		// Logo
689 gduche 490
		LayoutContainer lcLogoUrl = new LayoutContainer();
491
		hmIdentite.put("lcLogoUrl", lcLogoUrl);
676 gduche 492
 
875 jpm 493
		ChampMultiValeursImage logo = new ChampMultiValeursImage(i18nC.personneLogos());
701 gduche 494
		logo.setImageHeight("150px");
495
		logo.setValeurParDefaut("http://");
729 jp_milcent 496
		logo.setValidation(Pattern.url, "http://www.monsite.com/mon_image.jpg");
701 gduche 497
		logo.setValeurBoutonSupprimer("Supprimer");
498
		hmIdentite.put("logos", logo);
676 gduche 499
 
701 gduche 500
		lcLogoUrl.add(logo);
676 gduche 501
 
701 gduche 502
		fsAutresInfos.add(logo);
689 gduche 503
 
504
		LayoutContainer lcAutreInformations2 = new LayoutContainer(new ColumnLayout());
505
		hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
676 gduche 506
		fsAutresInfos.add(lcAutreInformations2);
386 gduche 507
 
676 gduche 508
		right.add(fsAutresInfos);
1086 jpm 509
 
510
		//+------------------------------------------------------------------------------------------------------------+
676 gduche 511
		// Ajout des évènements saisi
512
		KeyListener klNoms = new KeyListener()	{
513
			public void componentKeyUp(ComponentEvent ev)	{
514
				rafraichir(null);
515
			}
516
		};
517
 
518
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
519
			public void selectionChanged(SelectionChangedEvent se) {
730 jp_milcent 520
				rafraichir(null);
521
			}
676 gduche 522
		};
283 gduche 523
 
676 gduche 524
		cbPrefixe.addSelectionChangedListener(selectionChange);
525
		cbPrefixe.addKeyListener(klNoms);
526
		tfPrenom.addKeyListener(klNoms);
527
		tfNom.addKeyListener(klNoms);
528
		cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 529
 
530
	}
531
 
293 gduche 532
	public void creerComposantsAdresse()	{
533
		// Gauche
534
		LayoutContainer left = new LayoutContainer();
535
		left.setLayout(new FormLayout());
821 gduche 536
		left.setStyleAttribute("padding", "15px");
293 gduche 537
		// Droite
538
		LayoutContainer right = new LayoutContainer();
539
		right.setLayout(new FormLayout());
540
 
541
		// Principal
542
		LayoutContainer main = new LayoutContainer();
821 gduche 543
		main.setLayout(new TableLayout(2));
293 gduche 544
 
545
		// Ajout au principal
821 gduche 546
		main.add(left);
547
		main.add(right);
293 gduche 548
 
549
		TextField<String> tfAdresse1 = new TextField();
550
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 551
		tfAdresse1.setName("adresse_01");
319 gduche 552
		left.add(tfAdresse1, fd100);
293 gduche 553
		hmAdresse.put("tfAdresse1", tfAdresse1);
554
 
555
		TextField<String> tfAdresse2 = new TextField();
556
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 557
		tfAdresse2.setName("adresse_02");
319 gduche 558
		left.add(tfAdresse2, fd100);
293 gduche 559
		hmAdresse.put("tfAdresse2", tfAdresse2);
560
 
561
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
562
		cbPays.setFieldLabel("Pays");
563
		cbPays.setDisplayField("nom");
564
		cbPays.setEmptyText("Sélectionnez le pays:");
565
 
566
		ListStore<Valeur> storePays = new ListStore<Valeur>();
567
		cbPays.setStore(storePays);
568
 
319 gduche 569
		right.add(cbPays, fd100);
293 gduche 570
		hmAdresse.put("cbPays", cbPays);
571
 
572
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
573
			public void selectionChanged(SelectionChangedEvent se) {
730 jp_milcent 574
				// Rafraichir avec le pays sélectionné
575
				obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
1036 gduche 576
				//mettreAJourRegion();
730 jp_milcent 577
			}
293 gduche 578
		};
1026 gduche 579
 
293 gduche 580
		cbPays.addSelectionChangedListener(selectionChange);
581
 
582
 
583
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
584
		cbRegion.setFieldLabel("Region");
585
		cbRegion.setDisplayField("nom");
586
		cbRegion.setEmptyText("Sélectionnez la région:");
587
		cbRegion.setVisible(false);
588
 
589
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
590
		cbRegion.setStore(storeRegion);
591
 
352 gduche 592
 
319 gduche 593
		right.add(cbRegion, fd100);
293 gduche 594
		hmAdresse.put("cbRegion", cbRegion);
595
 
596
		TextField<String> tfBoitePostale = new TextField<String>();
597
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 598
		tfBoitePostale.setName("bp");
599
 
319 gduche 600
		left.add(tfBoitePostale, fd100);
293 gduche 601
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
602
 
603
		TextField<Integer> tfCodePostal = new TextField<Integer>();
604
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 605
		tfCodePostal.setName("code_postal");
606
 
319 gduche 607
		right.add(tfCodePostal, fd100);
293 gduche 608
		hmAdresse.put("tfCodePostal", tfCodePostal);
609
 
610
		TextField tfVille = new TextField();
611
		tfVille.setFieldLabel("Ville");
376 gduche 612
		tfVille.setName("ville");
293 gduche 613
 
319 gduche 614
		right.add(tfVille, fd100);
293 gduche 615
		hmAdresse.put("tfVille", tfVille);
616
 
617
		// MAJ ComboBox
618
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
619
 
304 gduche 620
		FieldSet fsAdresse = new FieldSet();
621
		fsAdresse.setHeading("Adresse personnelle");
622
		fsAdresse.add(main);
293 gduche 623
 
304 gduche 624
		tiAdresses.add(fsAdresse);
293 gduche 625
	}
821 gduche 626
 
627
	public void creerComposantsInfosNat()	{
338 gduche 628
 
979 gduche 629
		FormLayout fl = new FormLayout();
630
		fl.setLabelAlign(LabelAlign.TOP);
821 gduche 631
		FieldSet fsInfosNat = new FieldSet();
979 gduche 632
		fsInfosNat.setLayout(fl);
821 gduche 633
		fsInfosNat.setTitle("Informations Naturaliste");
634
 
979 gduche 635
		TextArea taBiographie = new TextArea();
636
		taBiographie.setFieldLabel("Vie et renommée de l'auteur");
637
		taBiographie.setWidth("400");
638
		taBiographie.setName("biographie");
1086 jpm 639
		fsInfosNat.add(taBiographie, new FormData(800, 200));
979 gduche 640
 
875 jpm 641
		ChampMultiValeurs specialite = new ChampMultiValeurs(i18nC.personneSpecialite());
821 gduche 642
		fsInfosNat.add(specialite);
643
		hmInfosNat.put("specialite", specialite);
644
 
976 gduche 645
		ChampMultiValeursMultiTypes recolte = new ChampMultiValeursMultiTypes(i18nC.personneRecolte(), 200, 200);
646
 
857 jpm 647
		recolte.initialiserType("pays");
821 gduche 648
		hmInfosNat.put("recolte", recolte);
649
		fsInfosNat.add(recolte);
650
		tiInfosNat.add(fsInfosNat);
651
	}
652
 
991 gduche 653
	public void creerComposantsPubli(){
654
		//Création des composants de l'onglet publication
655
 
656
		ContentPanel cp = new ContentPanel();
657
		cp.setHeading("Publications dont la personne est le sujet");
658
		cp.setIcon(Images.ICONES.table());
659
		cp.setLayout(new FitLayout());
660
		cp.setFrame(true);
661
 
662
		ToolBar toolBar = new ToolBar();
663
 
664
		Button ajouterPubli = new Button("Ajouter");
665
		ajouterPubli.setIcon(Images.ICONES.vcardAjouter());
666
		ajouterPubli.addSelectionListener(new SelectionListener<ButtonEvent>() {
667
			@Override
668
			public void componentSelected(ButtonEvent ce) {
669
				Window.alert("ajout publi");
670
				/*StructureAPersonne membreDuPersonnel = new StructureAPersonne("", StructureAPersonne.ROLE_EQUIPE, StructureAPersonne.ETAT_AJOUTE);
671
				ajouterMembreAGrillePersonnel(membreDuPersonnel);*/
672
			}
673
		});
674
		toolBar.add(ajouterPubli);
675
 
676
		toolBar.add(new SeparatorToolItem());
677
 
678
		Button supprimerPubli = new Button("Supprimer");
679
		supprimerPubli.setIcon(Images.ICONES.vcardSupprimer());
680
		supprimerPubli.addSelectionListener(new SelectionListener<ButtonEvent>() {
681
			@Override
682
			public void componentSelected(ButtonEvent ce) {
683
				/*StructureAPersonne personne = grillePersonnel.getSelectionModel().getSelectedItem();
684
				if (personne != null) {
685
					// Ajout de la personne supprimée à la liste
686
					if (personne.getIdPersonne() != null && !personne.getIdPersonne().equals("")) {
687
						personnelSupprime.put(personne.getId(), personne);
688
					}
689
 
690
					// Suppression de l'enregistrement de la grille
691
					grillePersonnel.getStore().remove(personne);
692
 
693
					// Désactivation du bouton supprimer si la grille contient plus d'élément
694
					if (grillePersonnel.getStore().getCount() == 0) {
695
						//TODO : check : Item -> component
696
						ce.getComponent().disable();
697
					}
698
				}*/
699
				Window.alert("supprimer");
700
			}
701
		});
702
		toolBar.add(supprimerPubli);
703
 
704
		toolBar.add(new SeparatorToolItem());
705
 
706
		Button rafraichirPersonnelBtn = new Button("Rafraichir");
707
		rafraichirPersonnelBtn.setIcon(Images.ICONES.rafraichir());
708
		rafraichirPersonnelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {
709
			@Override
710
			public void componentSelected(ButtonEvent ce) {
711
				//rafraichirPersonnel();
712
				Window.alert("rafraichir");
713
			}
714
		});
715
		toolBar.add(rafraichirPersonnelBtn);
716
 
717
		//Ajout d'une ComboBox
718
		storePubli = new ListStore<Publication>();
719
		storePubli.add(new ArrayList<Publication>());
720
 
721
		cbPubli = new ComboBox<Publication>();
722
		cbPubli.setWidth(200);
723
		cbPubli.setEmptyText("Chercher une publication existante...");
724
		cbPubli.setTriggerAction(TriggerAction.ALL);
725
		cbPubli.setEditable(true);
726
		cbPubli.setDisplayField("fmt_nom_complet");
727
		cbPubli.setStore(storePubli);
728
		cbPubli.addKeyListener(new KeyListener() {
729
 
730
			public void componentKeyUp(ComponentEvent ce) {
731
				if (!ce.isNavKeyPress() && cbPubli.getRawValue() != null && cbPubli.getRawValue().length() > 0) {
732
					rafraichirPublicationsExistante(cbPubli.getRawValue());
733
				}
734
			}
735
 
736
		});
737
 
738
		toolBar.add(cbPubli);
739
		toolBar.add(new SeparatorToolItem());
740
		cp.setTopComponent(toolBar);
741
 
742
 
743
		tiPubli.add(cp);
744
	}
745
 
746
	public void rafraichirPublicationsExistante(String nomPubli)	{
747
		nomPubli +="%";
748
		mediateur.selectionnerPublicationParNomComplet(this, null, nomPubli);
749
	}
750
 
276 gduche 751
	/**
752
	 * Ajouter le bouton annuler à la barre d'outils donnée
753
	 *
754
	 * @param barreOutils la barre d'outils à modifier
755
	 * */
356 gduche 756
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 757
 
758
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 759
		Button annuler = new Button("Revenir à la liste");
488 gduche 760
		annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {
761
			public void componentSelected(ButtonEvent ce) {
276 gduche 762
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
763
			}
764
		});
765
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
766
		barreOutils.add(annuler);
767
	}
768
 
293 gduche 769
	public void obtenirListeRegionParPays(String strPays)	{
770
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
771
	}
276 gduche 772
 
730 jp_milcent 773
	// RAFRAICHISSEMENT DU PANNEAU
774
 
283 gduche 775
	public void rafraichir(Object nouvellesDonnees) {
991 gduche 776
		if (nouvellesDonnees instanceof PublicationAPersonneListe)	{
777
			Information info = new Information();
778
			info.setType("publication_liees");
779
			info.setDonnee(0, (PublicationAPersonneListe) nouvellesDonnees);
780
			tiPubli.rafraichir(info);
781
		} else if (nouvellesDonnees instanceof ValeurListe) {
1014 gduche 782
 
283 gduche 783
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
784
 
785
			// Créer une liste de valeurs
786
			List<Valeur> liste = new ArrayList<Valeur>();
787
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
788
				liste.add(listeValeurs.get(it.next()));
789
			}
1014 gduche 790
			if (listeValeurs.getId().equals(config.getListeId("relationPersonnePublication")))	{
791
				tiPubli.rafraichir(nouvellesDonnees);
792
			} else if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
319 gduche 793
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 794
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
795
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
796
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
1101 gduche 797
 
798
				//Ajout de la valeur "Inconnu"
799
				ComboBox<Valeur> cbSexe = hmAdresse.getComboBoxValeur("cbSexe");
800
				Valeur inconnu = new Valeur();
801
				inconnu.set("nom", "Inconnu");
802
				inconnu.set("id", "0");
803
				liste.add(0, inconnu);
804
 
293 gduche 805
				remplirCombobox("cbSexe", liste, "hmIdentite");
1101 gduche 806
 
807
				/*List<Valeur> selection = new LinkedList<Valeur>();
808
				selection.add(inconnu);
809
				cbSexe.setSelection(s);*/
810
 
811
 
293 gduche 812
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
813
				remplirCombobox("cbTelephone", liste, "hmIdentite");
730 jp_milcent 814
 
319 gduche 815
				//Préselection du tél
973 gduche 816
				ComboBox<Valeur> cbTelephone = hmIdentite.getComboBoxValeur("cbTelephone");
319 gduche 817
				cbTelephone.setValue(liste.get(1));
293 gduche 818
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
819
				remplirCombobox("cbPays", liste, "hmAdresse");
820
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
821
				remplirCombobox("cbRegion", liste, "hmAdresse");
1033 gduche 822
				mettreAJourRegion();
976 gduche 823
				hmAdresse.getComboBox("cbRegion").setVisible(true);
1026 gduche 824
 
283 gduche 825
			}
456 gduche 826
		} else if (nouvellesDonnees instanceof ProjetListe) {
827
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
730 jp_milcent 828
			List<Projet> liste = projets.toList();
456 gduche 829
 
973 gduche 830
			ComboBox cbProjets = hmIdentite.getComboBox("cbProjets");
456 gduche 831
			ListStore<Projet> storeProjets= cbProjets.getStore();
832
			storeProjets.removeAll();
833
			storeProjets.add(liste);
834
			cbProjets.setStore(storeProjets);
991 gduche 835
		} else if (nouvellesDonnees instanceof PublicationListe)	{
836
 
837
			PublicationListe publicationListe = (PublicationListe) nouvellesDonnees;
838
			List<Publication> liste = publicationListe.toList();
839
			storePubli.removeAll();
840
			storePubli.add(liste);
841
			cbPubli.setStore(storePubli);
842
 
352 gduche 843
		} else if (nouvellesDonnees instanceof Information)	{
844
			Information info = (Information) nouvellesDonnees;
386 gduche 845
			if (info.getType().equals("ajout_personne"))	{
884 jpm 846
				if (info.getDonnee(0) != null) {
847
					personneSelectionnee.setId(info.getDonnee(0).toString());
848
					GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
849
					Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
850
					repandreRafraichissement();
851
					if (clicBoutonvalidation)	{
852
						mediateur.clicMenu(menuIdCourant);
853
					}
854
				} else {
855
					Info.display("Enregistrement", info.getMessages().toString());
852 gduche 856
				}
433 gduche 857
			} else if (info.getType().equals("modification_personne"))	{
858
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
884 jpm 859
				repandreRafraichissement();
852 gduche 860
				if (clicBoutonvalidation)	{
861
					mediateur.clicMenu(menuIdCourant);
862
				}
884 jpm 863
			} else if (info.getType().equals("maj_utilisateur"))	{
668 gduche 864
				gererEtatActivationBouton();
386 gduche 865
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
776 gduche 866
 
730 jp_milcent 867
				Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
868
				Iterator itPersonneListe = colPersonneListe.iterator();
869
				Personne personne = (Personne) itPersonneListe.next();
870
 
991 gduche 871
				//TODO : Je vois pas l'intérêt des lignes ci dessous..
730 jp_milcent 872
				personneSauvegarde = new Personne();
873
				personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
874
 
875
				binderPersonne(personne);
876
 
776 gduche 877
				mettreAJourPersonne(personne);
730 jp_milcent 878
 
879
				nouvellesDonnees = null;
880
			} else {
881
				Info.display("messages", info.getMessages().toString());
882
			}
776 gduche 883
		}
283 gduche 884
 
730 jp_milcent 885
		if (nouvellesDonnees == null) {
973 gduche 886
			ComboBox<Valeur> cb= hmIdentite.getComboBoxValeur("cbPrefixe");
293 gduche 887
 
888
			//Met à jour le nom Complet du formulaire
283 gduche 889
			String valeurRetour = "";
890
 
891
			// Prefixe
892
			String prefixe = "";
973 gduche 893
			Valeur valPrefixe = cb.getValue();
283 gduche 894
 
895
			if (valPrefixe != null)	{
896
				prefixe = valPrefixe.getNom();
293 gduche 897
			} else 	{
973 gduche 898
				prefixe =  (String) cb.getRawValue();
293 gduche 899
			}
283 gduche 900
 
901
			// Prénom
973 gduche 902
			String prenom = (String) hmIdentite.getTextField("tfPrenom").getValue();
283 gduche 903
 
904
			// Nom
973 gduche 905
			String nom = (String) hmIdentite.getTextField("tfNom").getValue();
283 gduche 906
 
907
			// Suffixe
973 gduche 908
			ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe");
909
 
283 gduche 910
			String suffixe = "";
973 gduche 911
			Valeur valSuffixe = cbSuffixe.getValue();
283 gduche 912
 
913
			if (valSuffixe != null)	{
914
				suffixe = valSuffixe.getNom();
293 gduche 915
			} else 	{
973 gduche 916
				suffixe =  (String) cbSuffixe.getRawValue();
283 gduche 917
			}
918
 
919
			// Mettre à jour la valeur
920
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
921
			valeurRetour = valeurRetour.replaceAll("null", "");
922
 
973 gduche 923
			hmIdentite.getLabelField("nomComplet").setValue(valeurRetour);
283 gduche 924
 
925
			if (!valeurRetour.trim().equals(""))	{
973 gduche 926
				hmIdentite.getLabelField("nomComplet").show();
283 gduche 927
			} else {
973 gduche 928
				hmIdentite.getLabelField("nomComplet").hide();
283 gduche 929
			}
930
		}
338 gduche 931
 
932
		mediateur.masquerPopinChargement();
456 gduche 933
 
461 gduche 934
		if (this.mode.equals(MODE_AJOUTER))	{
668 gduche 935
			gererEtatActivationBouton();
456 gduche 936
		}
127 gduche 937
	}
938
 
884 jpm 939
	private void repandreRafraichissement() {
940
		if (vueExterneARafraichirApresValidation != null) {
941
			String type = "personne_modifiee";
942
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
943
				type = "personne_ajoutee";
944
			}
945
			Information info = new Information(type);
946
			info.setDonnee(0, personneSelectionnee);
947
			vueExterneARafraichirApresValidation.rafraichir(info);
948
		}
949
	}
950
 
1026 gduche 951
	private void mettreAJourRegion()	{
1033 gduche 952
		//Met à jour la combo box en sélectionnant la valeur enregistrée pour la personne
1026 gduche 953
		ComboBox<Valeur> cbRegion = hmAdresse.getComboBoxValeur("cbRegion");
1036 gduche 954
		if (personneSelectionnee.get("ce_truk_region").toString().startsWith("AUTRE##")) {
955
			cbRegion.setRawValue(personneSelectionnee.get("ce_truk_region").toString().replaceFirst("^AUTRE##", ""));
956
		} else if (personneSelectionnee.get("ce_truk_region") != null && cbRegion.getStore().getCount() > 0)	{
1026 gduche 957
			Valeur valeurRegion = cbRegion.getStore().findModel("id_valeur", personneSelectionnee.get("ce_truk_region"));
958
			if (valeurRegion!=null)	{
959
				cbRegion.setValue(valeurRegion);
960
			}
961
		}
962
	}
1036 gduche 963
 
776 gduche 964
	private void mettreAJourPersonne(Personne personne)	{
965
		//Mise à jour de la personne
966
		//Personne personne = (Personne) nouvellesDonnees;
973 gduche 967
		ComboBox cbProjets = hmIdentite.getComboBox("cbProjets");
776 gduche 968
		cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
969
 
970
		//Prefixe
971
		String prefixe = personne.get("ce_truk_prefix");
973 gduche 972
		ComboBox<Valeur> cbPrefixe = hmIdentite.getComboBoxValeur("cbPrefixe");
776 gduche 973
 
974
 
975
		String prefixeCourant = personne.get("ce_truk_prefix");
976
		if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
977
			cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
978
		}	else	{
979
			cbPrefixe.setRawValue(prefixeCourant);
980
		}
981
 
973 gduche 982
		hmIdentite.getTextField("tfPrenom").setValue(personne.get("prenom"));
983
		hmIdentite.getTextField("tfNom").setValue(personne.get("nom"));
776 gduche 984
 
985
		//Suffixe
986
		String suffixe = personne.get("ce_truk_suffixe");
973 gduche 987
		ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe");
776 gduche 988
 
989
		String suffixeCourant = personne.get("ce_truk_suffix");
990
		if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
991
			cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
992
		}	else	{
993
			cbSuffixe.setRawValue(suffixeCourant);
994
		}
995
 
973 gduche 996
		hmIdentite.getChampMultiValeurs("nomAutre").peupler(personne.getString("truk_nom_autre"));
997
		hmIdentite.getTextField("tfAbreviation").setValue(personne.get("abreviation"));
998
		hmIdentite.getChampMultiValeurs("abreviationAutre").peupler(personne.getString("truk_abreviation_autre"));
776 gduche 999
 
973 gduche 1000
		hmIdentite.getDateField("dfDateNaissance").setValue(personne.getDate("naissance_date"));
1001
		hmIdentite.getTextField("tfLieuNaissance").setValue(personne.get("naissance_lieu"));
776 gduche 1002
 
829 gduche 1003
		if (personne.estDecedee())	{
973 gduche 1004
			hmIdentite.getDateField("dfDateDeces").setValue(personne.getDate("deces_date"));
1005
			hmIdentite.getTextField("tfLieuDeces").setValue(personne.get("deces_lieu"));
1006
			Radio rbEstDecede = hmIdentite.getRadio("rbEstDecedee");
829 gduche 1007
			rbEstDecede.setValue(true);
1008
		}
776 gduche 1009
 
973 gduche 1010
		hmIdentite.getChampMultiValeurs("telephones").peupler(personne.getString("truk_telephone"));
776 gduche 1011
 
1012
		//Courriel
973 gduche 1013
		hmIdentite.getChampMultiValeurs("courriels").peupler(personne.getCourriel());
776 gduche 1014
 
1015
		//Sites web
973 gduche 1016
		hmIdentite.getChampMultiValeurs("sites").peupler(personne.getString("truk_url"));
776 gduche 1017
 
1018
		// Sexe
1019
		String strSexe = personne.get("ce_sexe");
973 gduche 1020
		ComboBox<Valeur> cbSexe = hmIdentite.getComboBoxValeur("cbSexe");
776 gduche 1021
 
1022
		if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)	{
1023
			cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
1024
		}
1025
 
973 gduche 1026
		hmIdentite.getTextArea("taDescription").setRawValue((String) personne.get("description"));
776 gduche 1027
 
1028
		//Logo
973 gduche 1029
		hmIdentite.getChampMultiValeurs("logos").peupler(personne.getString("truk_logo"));
776 gduche 1030
 
1031
		/*--------------------------------------------------
1032
		                      Adresse
1033
		 ---------------------------------------------------*/
1034
 
1035
		// Adresse
976 gduche 1036
		hmAdresse.getTextField("tfAdresse1").setValue((String) personne.get("adresse_01"));
776 gduche 1037
 
1038
		// Complément
976 gduche 1039
		hmAdresse.getTextField("tfAdresse2").setValue((String) personne.get("adresse_02"));
776 gduche 1040
 
1041
		//Boite postale
976 gduche 1042
		hmAdresse.getTextField("tfBoitePostale").setValue((String) personne.get("bp"));
776 gduche 1043
 
1044
		//Pays
1026 gduche 1045
		String strPays = personne.get("ce_truk_pays");
976 gduche 1046
		ComboBox<Valeur> cbPays = hmAdresse.getComboBoxValeur("cbPays");
1026 gduche 1047
		if (cbPays.getStore().findModel("id_valeur", strPays) != null)	{
1048
			cbPays.setValue(cbPays.getStore().findModel("id_valeur", strPays));
1049
			cbPays.fireEvent(Events.OnChange);
776 gduche 1050
		}	else	{
1051
			cbPays.setRawValue(strPays);
1052
		}
1053
 
1026 gduche 1054
		//Région : doit être chargé après chargement de la liste des régions...
1055
		String strRegion = personne.get("ce_truk_region");
1056
 
776 gduche 1057
		if ((strRegion!=null)&&(!strRegion.equals("")))	{
976 gduche 1058
			ComboBox<Valeur> cbRegion = hmAdresse.getComboBoxValeur("cbRegion");
1026 gduche 1059
			System.out.println(cbRegion.getStore().getCount());
776 gduche 1060
			cbRegion.setVisible(true);
1061
 
1026 gduche 1062
			if (cbRegion.getStore().findModel("id_valeur", strRegion) != null)	{
1063
				cbRegion.setValue(cbRegion.getStore().findModel("id_valeur", strRegion));
776 gduche 1064
			}	else	{
1065
				cbRegion.setRawValue(strRegion);
1066
			}
1067
		}
1068
 
1069
		//Cp
976 gduche 1070
		hmAdresse.getTextField("tfCodePostal").setValue(personne.get("code_postal"));
776 gduche 1071
 
1072
		//Ville
976 gduche 1073
		hmAdresse.getTextField("tfVille").setValue(personne.get("ville"));
776 gduche 1074
 
821 gduche 1075
		/*--------------------------------------------------------
1076
		 * 					Infos naturalistes
1077
		 * -----------------------------------------------------*/
1078
 
979 gduche 1079
		hmInfosNat.getChampMultiValeurs("specialite").peupler(personne.getString("ce_truk_specialite"));
976 gduche 1080
		String tr = personne.getString("truk_recolte");
979 gduche 1081
		hmInfosNat.getChampMultiValeursMultiTypes("recolte").peupler(tr);
991 gduche 1082
 
1083
		//Onglet publi
1084
		tiPubli.mettreAJourPersonne();
776 gduche 1085
		gererEtatActivationBouton();
1086
	}
730 jp_milcent 1087
 
293 gduche 1088
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
1089
		HashMap hm = null;
1090
		if (hashMapId.equals("hmIdentite"))	{
1091
			hm = hmIdentite;
1092
		} else if (hashMapId.equals("hmAdresse")){
1093
			hm = hmAdresse;
1094
		} else {
1095
			hm = hmInfosNat;
1096
		}
1097
 
1098
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1099
 
293 gduche 1100
		store.removeAll();
1101
		store.add(liste);
1102
		((ComboBox) hm.get(idComboBox)).setStore(store);
1103
	}
130 gduche 1104
 
668 gduche 1105
	private void gererEtatActivationBouton()	{
850 gduche 1106
	/*	if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
668 gduche 1107
			enregistrer.setEnabled(false);
1108
			enregistrerEtRevenir.setEnabled(false);
1109
		} else	{
1110
			enregistrer.setEnabled(true);
1111
			enregistrerEtRevenir.setEnabled(true);
850 gduche 1112
		}*/
668 gduche 1113
	}
1114
 
850 gduche 1115
	public void reinitialiserFormulaire()	{
461 gduche 1116
		mediateur.afficherPopinChargement();
776 gduche 1117
		mettreAJourPersonne(personneSauvegarde);
376 gduche 1118
		mediateur.masquerPopinChargement();
1119
	}
1120
 
1121
	public void binderPersonne(Personne personne)	{
850 gduche 1122
		binding = new FormBinding(getFormulaire());
731 jp_milcent 1123
 
376 gduche 1124
		personneSelectionnee = personne;
1125
		binding.autoBind();
1126
		binding.bind(personneSelectionnee);
1127
		layout();
1128
	}
973 gduche 1129
 
376 gduche 1130
	private String obtenirValeurCombo(String strComboName)	{
1131
		String strValeur = "";
1132
		Valeur valeur;
1133
 
973 gduche 1134
		ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur(strComboName);
376 gduche 1135
		if (combo == null)	{
976 gduche 1136
			combo = hmAdresse.getComboBoxValeur(strComboName);
376 gduche 1137
		}
829 gduche 1138
		strValeur = combo.getRawValue();
1026 gduche 1139
		valeur = combo.getValue();
829 gduche 1140
		if (valeur != null)	{
1141
			strValeur = valeur.getId();
1142
		}
1143
 
376 gduche 1144
		return strValeur;
1145
	}
850 gduche 1146
 
934 jpm 1147
	public boolean soumettreFormulaire() {
1014 gduche 1148
		tiPubli.collecter();
850 gduche 1149
		if (verifierFormulaire())	{
991 gduche 1150
			tiPubli.soumettre();
850 gduche 1151
			mediateur.enregistrerPersonne(this, personneSelectionnee);
1152
		}
1153
		return true;
1154
	}
1155
 
934 jpm 1156
	public boolean verifierFormulaire() {
884 jpm 1157
		boolean success = true;
1158
		LinkedList<String> lstMessageErreur = new LinkedList<String>();
850 gduche 1159
 
973 gduche 1160
		ComboBox<Projet> cbProjets = hmIdentite.getComboBox("cbProjets");
850 gduche 1161
		Projet projet = cbProjets.getValue();
1162
		if (projet == null)	{
1163
			lstMessageErreur.add("Le projet n'a pas été renseigné");
1164
		} else {
1165
			personneSelectionnee.set("ce_projet", projet.getId());
1166
		}
1167
 
973 gduche 1168
		String strTfNom = (String) hmIdentite.getTextField("tfNom").getValue();
850 gduche 1169
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1170
			lstMessageErreur.add("Le nom n'a pas été saisi");
1171
		} else {
1172
			strTfNom = UtilString.ucFirst(strTfNom);
1173
			personneSelectionnee.set("nom", strTfNom);
1174
		}
1175
 
973 gduche 1176
		String strTfPrenom = (String) hmIdentite.getTextField("tfPrenom").getValue();
850 gduche 1177
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1178
 
1179
		//Préparer les données
973 gduche 1180
		ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur("cbSexe");
850 gduche 1181
		Valeur valeur;
1182
		String strValeur = "";
1183
 
973 gduche 1184
		valeur = combo.getValue();
850 gduche 1185
		if (valeur!=null)	{
1186
			personneSelectionnee.set("ce_sexe", valeur.getId());
1187
		}
1188
 
1189
		strValeur = obtenirValeurCombo("cbPrefixe");
1190
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1191
 
1192
		strValeur = obtenirValeurCombo("cbSuffixe");
1193
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1194
 
973 gduche 1195
		String nomAutre = hmIdentite.getChampMultiValeurs("nomAutre").getValeurs();
850 gduche 1196
		personneSelectionnee.set("truk_nom_autre", nomAutre);
1197
 
973 gduche 1198
		String abreviationAutre = hmIdentite.getChampMultiValeurs("abreviationAutre").getValeurs();
850 gduche 1199
		personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);
1200
 
973 gduche 1201
		personneSelectionnee.set("truk_courriel", hmIdentite.getChampMultiValeurs("courriels").getValeurs());
850 gduche 1202
 
1203
 
1204
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1205
		String strPrefixe = "";
973 gduche 1206
		combo = hmIdentite.getComboBoxValeur("cbPrefixe");
1207
		valeur = combo.getValue();
850 gduche 1208
		if (valeur != null)	{
1209
			strPrefixe = valeur.getNom();
1210
		} else {
1211
			strPrefixe = combo.getRawValue();
1212
		}
1213
 
1214
		String strSuffixe = "";
973 gduche 1215
		combo = hmIdentite.getComboBox("cbSuffixe");
1216
		valeur = combo.getValue();
850 gduche 1217
		if (valeur != null)	{
1218
			strSuffixe = valeur.getNom() + " ";
1219
		} else {
1220
			strSuffixe = combo.getRawValue() +" ";
1221
		}
1222
 
1223
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
1224
 
973 gduche 1225
		DateField dfDateNaissance = hmIdentite.getDateField("dfDateNaissance");
850 gduche 1226
		Date naissanceDate = dfDateNaissance.getValue();
1227
		personneSelectionnee.setNaissanceDate(naissanceDate);
1228
 
973 gduche 1229
		Radio rbEstDecedee = hmIdentite.getRadio("rbEstDecedee");
850 gduche 1230
		if (rbEstDecedee.getValue() == true)	{
973 gduche 1231
			DateField dfDecesDate = hmIdentite.getDateField("dfDateDeces");
1232
			String decesLieu = (String) hmIdentite.getTextField("tfLieuDeces").getValue();
850 gduche 1233
			personneSelectionnee.setDeces(dfDecesDate.getValue(), decesLieu);
1234
		}	else	{
1235
			personneSelectionnee.setNonDecedee();
1236
		}
1237
 
1238
		strValeur = obtenirValeurCombo("cbPays");
1239
		personneSelectionnee.set("ce_truk_pays", strValeur);
1240
 
1026 gduche 1241
		strValeur = obtenirValeurCombo("cbRegion");
1036 gduche 1242
		ComboBox<Valeur> cbRegions = hmAdresse.getComboBoxValeur("cbRegion");
1243
		if (cbRegions.getStore().findModel("id", strValeur) == null)	{
1244
			strValeur = "AUTRE##" + strValeur;
1245
		}
850 gduche 1246
		personneSelectionnee.set("ce_truk_region", strValeur);
1247
 
973 gduche 1248
		personneSelectionnee.set("truk_telephone", hmIdentite.getChampMultiValeursMultiTypes("telephones").getValeurs());
850 gduche 1249
 
973 gduche 1250
		String logoUrls = hmIdentite.getChampMultiValeursImage("logos").getValeurs();
850 gduche 1251
		personneSelectionnee.set("truk_logo", logoUrls);
1252
 
973 gduche 1253
		personneSelectionnee.set("truk_url", hmIdentite.getChampMultiValeurs("sites").getValeurs());
850 gduche 1254
 
1255
		//Infos Naturalistes
1256
		String recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs();
1257
		personneSelectionnee.set("truk_recolte", recolte);
1258
 
1259
		String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();
1260
		personneSelectionnee.set("ce_truk_specialite", specialite);
1261
 
1014 gduche 1262
		lstMessageErreur.addAll(tiPubli.verifier());
850 gduche 1263
 
884 jpm 1264
		if (lstMessageErreur.size() != 0)	{
850 gduche 1265
			String strMessagesErreur = "<span><br />";
1266
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1267
			while (itMessagesErreur.hasNext())	{
1268
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
1269
			}
1270
			strMessagesErreur += "</span>";
1271
 
1272
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
1273
 			success = false;
1274
		}
1275
 
1276
		return success;
1277
	}
127 gduche 1278
}