Subversion Repositories eFlore/Applications.coel

Rev

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