Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
150 gduche 1
package org.tela_botanica.client.vues;
2
 
253 gduche 3
import java.util.Collection;
197 gduche 4
import java.util.HashMap;
5
import java.util.Iterator;
253 gduche 6
import java.util.LinkedList;
7
import java.util.MissingResourceException;
189 gduche 8
 
197 gduche 9
 
305 gduche 10
import org.tela_botanica.client.Mediateur;
150 gduche 11
import org.tela_botanica.client.RegistreId;
253 gduche 12
import org.tela_botanica.client.i18n.Constantes;
150 gduche 13
import org.tela_botanica.client.interfaces.Rafraichissable;
305 gduche 14
import org.tela_botanica.client.modeles.Configuration;
150 gduche 15
import org.tela_botanica.client.modeles.Personne;
305 gduche 16
import org.tela_botanica.client.modeles.Valeur;
17
import org.tela_botanica.client.modeles.ValeurListe;
259 gduche 18
import org.tela_botanica.client.util.UtilTruk;
150 gduche 19
 
20
import com.extjs.gxt.ui.client.Registry;
21
import com.extjs.gxt.ui.client.Style.Scroll;
253 gduche 22
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
215 aurelien 23
import com.extjs.gxt.ui.client.widget.ContentPanel;
269 gduche 24
import com.extjs.gxt.ui.client.widget.LayoutContainer;
189 gduche 25
import com.extjs.gxt.ui.client.widget.TabItem;
26
import com.extjs.gxt.ui.client.widget.TabPanel;
197 gduche 27
import com.extjs.gxt.ui.client.widget.form.FieldSet;
246 gduche 28
import com.extjs.gxt.ui.client.widget.form.LabelField;
150 gduche 29
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
197 gduche 30
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
31
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
253 gduche 32
import com.extjs.gxt.ui.client.widget.layout.TableData;
197 gduche 33
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
280 gduche 34
 
253 gduche 35
import com.google.gwt.core.client.GWT;
197 gduche 36
import com.google.gwt.user.client.ui.Image;
150 gduche 37
 
269 gduche 38
public class PersonneDetailPanneauVue extends LayoutContainer implements Rafraichissable {
150 gduche 39
 
197 gduche 40
	// Le panneau détail se compose de formulaires tabulés
269 gduche 41
	private TabPanel tabPanel;
189 gduche 42
 
197 gduche 43
	// Onglet 1 : identite & contact
215 aurelien 44
	private TabItem tabIdentite;
45
 
46
	private ContentPanel panneauIdentite;
47
	private ContentPanel panneauImage;
48
 
197 gduche 49
	private FieldSet fsIdentite;
50
	private FieldSet fsContact;
189 gduche 51
 
200 gduche 52
	// Onglet 2 : Adresses
53
	private TabItem tabAdresse;
54
	private FieldSet fsAdressePerso;
198 gduche 55
		// contient : adresse perso / adresse pro
56
 
215 aurelien 57
	// Onglet 3 : Informations naturalistes
58
	private TabItem tabInfosNat;
269 gduche 59
	private FieldSet fsSpec;
198 gduche 60
 
305 gduche 61
	private Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
267 gduche 62
 
150 gduche 63
	public PersonneDetailPanneauVue() {
189 gduche 64
 
269 gduche 65
		tabPanel = new TabPanel();
66
		this.add(tabPanel);
67
 
198 gduche 68
		//Constructeur de la classe
150 gduche 69
		Registry.register(RegistreId.PANNEAU_PERSONNE_DETAIL, this);
189 gduche 70
		setLayout(new FitLayout());
150 gduche 71
 
215 aurelien 72
		tabIdentite = new TabItem("Identité");
73
		TableLayout tLayout = new TableLayout(2);
74
		tabIdentite.setLayout(tLayout);
75
		tabIdentite.setScrollMode(Scroll.AUTO);
189 gduche 76
 
215 aurelien 77
		panneauIdentite = new ContentPanel();
78
		panneauIdentite.setWidth("400px");
79
		panneauIdentite.setHeaderVisible(false);
80
		panneauIdentite.setBorders(false);
81
		panneauIdentite.setBodyBorder(false);
82
		panneauImage = new ContentPanel();
253 gduche 83
		panneauImage.setLayout(new FlowLayout());
215 aurelien 84
		panneauImage.setBorders(false);
253 gduche 85
		panneauImage.setWidth(350);
215 aurelien 86
		panneauImage.setBodyBorder(false);
87
		panneauImage.setHeaderVisible(false);
200 gduche 88
 
259 gduche 89
		//Gérer l'alignement vertical en haut
253 gduche 90
		TableData td = new TableData();
259 gduche 91
		td.setVerticalAlign(VerticalAlignment.TOP);
92
 
93
		tabIdentite.add(panneauIdentite, td);
253 gduche 94
		tabIdentite.add(panneauImage, td);
259 gduche 95
 
253 gduche 96
 
197 gduche 97
		fsIdentite = new FieldSet();
98
		fsIdentite.setLayout(new FormLayout());
99
 
100
 
101
		fsContact = new FieldSet();
102
		fsContact.setLayout(new FormLayout());
103
 
269 gduche 104
		tabPanel.add(tabIdentite);
197 gduche 105
 
200 gduche 106
		//Onglet Adresse:
259 gduche 107
		tabAdresse = new TabItem("Adresses");
200 gduche 108
		fsAdressePerso = new FieldSet();
109
		fsAdressePerso.setLayout(new FormLayout());
110
 
269 gduche 111
		tabPanel.add(tabAdresse);
200 gduche 112
 
215 aurelien 113
		//Onglet info naturalistes
114
		tabInfosNat = new TabItem("Informations naturalistes");
269 gduche 115
		fsSpec = new FieldSet();
116
		fsSpec.setLayout(new FormLayout());
321 gduche 117
		tabInfosNat.setScrollMode(Scroll.AUTO);
200 gduche 118
 
269 gduche 119
		tabPanel.add(tabInfosNat);
198 gduche 120
 
150 gduche 121
	}
122
 
305 gduche 123
 
321 gduche 124
	private HashMap hmLabelFieldRegion = new HashMap();
305 gduche 125
 
150 gduche 126
	public void afficherDetailPersonne(Personne personne) {
127
		if (personne != null) {
198 gduche 128
 
129
 
130
			//MAJ Identité : Configurer les fieldSet
215 aurelien 131
			panneauIdentite.removeAll();
132
			panneauImage.removeAll();
150 gduche 133
 
197 gduche 134
			fsIdentite.setHeading("Identité");
259 gduche 135
			//fsIdentite.setWidth("350px");
183 gduche 136
 
197 gduche 137
			fsContact.setHeading("Contact");
259 gduche 138
			//fsContact.setWidth("350px");
183 gduche 139
 
215 aurelien 140
			panneauIdentite.add(fsIdentite);
141
 
259 gduche 142
 
253 gduche 143
			//La personne peut avoir un ou plusieurs logo
144
			panneauImage.setHeight("100%");
259 gduche 145
			panneauImage.setPosition(0, 6);
146
			panneauImage.setBorders(false);
198 gduche 147
 
253 gduche 148
			LinkedList<String> listeLogos = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
149
			if ((listeLogos != null)&&(listeLogos.size() > 0))	{
259 gduche 150
				panneauImage.setBorders(true);
253 gduche 151
				for (int i = 0; i < listeLogos.size(); i++)	{
152
					String logoUrl = listeLogos.get(i);
153
					if ((logoUrl!=null)&&(!logoUrl.trim().equals("")))	{
154
						//Si c'est le cas, on l'affiche sur la même ligne que fsIdentité
155
						Image img = new Image();
156
						img.setUrl(logoUrl);
157
 
158
						panneauImage.add(img);
159
						if (panneauImage.getWidth() < (img.getWidth() + 15))	{
160
							panneauImage.setWidth(img.getWidth() + 15);
161
						}
162
 
163
					}
164
				}
246 gduche 165
 
189 gduche 166
			}
150 gduche 167
 
215 aurelien 168
			panneauIdentite.add(fsContact);
183 gduche 169
 
197 gduche 170
			fsIdentite.removeAll();
171
			fsContact.removeAll();
215 aurelien 172
			fsAdressePerso.removeAll();
269 gduche 173
			fsSpec.removeAll();
321 gduche 174
			tabInfosNat.removeAll();
197 gduche 175
			//Ajout des champs Identité
176
 
177
 
178
 
179
			// TODO: projet
180
 
181
			// nom complet
182
			Object nomComplet = personne.obtenirValeurChamp("fmt_nom_complet");
266 gduche 183
			ajouterLabelField(fsIdentite,"Nom Complet", nomComplet);
197 gduche 184
 
259 gduche 185
			// Nom autre : champ truk; non-typé
186
			LinkedList<String> nomsAutre = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_nom_autre");
187
			if ((nomsAutre != null)&&(nomsAutre.size() > 0))	{
188
 
189
				LabelField noms = new LabelField();
190
				noms.setFieldLabel("Autres noms:");
191
				String listeNoms = UtilTruk.traiterTrukListe(nomsAutre, ", ");
192
				noms.setValue(listeNoms);
193
				fsIdentite.add(noms);
194
			}
197 gduche 195
 
196
			// abreviation
197
			Object abreviation = personne.obtenirValeurChamp("abreviation");
266 gduche 198
			ajouterLabelField(fsIdentite, "Abreviation", abreviation);
197 gduche 199
 
259 gduche 200
			// Abréviations, autre : non-typé
201
			LinkedList<String> abrevAutres = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_abreviation_autre");
202
			if ((abrevAutres != null)&&(abrevAutres.size() > 0))	{
203
 
204
				LabelField abreviations = new LabelField();
205
				abreviations.setFieldLabel("Autres abreviations:");
206
				String listeAbrev = UtilTruk.traiterTrukListe(abrevAutres, ", ");
207
				abreviations.setValue(listeAbrev);
208
				fsIdentite.add(abreviations);
209
			}
210
			fsIdentite.addText("<hr>");
197 gduche 211
 
259 gduche 212
			// date naissance
213
			// TODO : Mettre la date en format FR 10/12/09
214
			Object dateNaissance = personne.obtenirValeurChamp("naissance_date");
266 gduche 215
			ajouterLabelField(fsIdentite, "Né le", dateNaissance);
259 gduche 216
 
197 gduche 217
			// lieu naissance
259 gduche 218
			Object lieuNaissance = personne.obtenirValeurChamp("naissance_lieu");
266 gduche 219
			ajouterLabelField(fsIdentite, "A", lieuNaissance);
197 gduche 220
 
221
			// date deces
259 gduche 222
			Object dateDeces = personne.obtenirValeurChamp("deces_date");
266 gduche 223
			ajouterLabelField(fsIdentite, "Date décès", dateDeces);
197 gduche 224
 
225
			// lieu deces
259 gduche 226
			Object lieuDeces = personne.obtenirValeurChamp("deces_lieu");
266 gduche 227
			ajouterLabelField(fsIdentite, "Lieu de décès", lieuDeces);
197 gduche 228
 
259 gduche 229
			fsIdentite.addText("<hr>");
230
 
200 gduche 231
			//Description
232
			String description = (String) personne.obtenirValeurChamp("description");
233
			if ((description!=null)&&(!description.trim().equals("")))	{
253 gduche 234
				LabelField txtDescription = new LabelField();
235
				txtDescription.setFieldLabel("Description:");
200 gduche 236
				txtDescription.setValue(description);
237
 
253 gduche 238
				//rendreNonEditable(txtDescription);
200 gduche 239
 
240
				fsIdentite.add(txtDescription);
241
			}
197 gduche 242
 
243
 
253 gduche 244
			// CONTACT
245
			// Téléphones
246
			// > Plusieurs téléphones possible, typés
247
			Constantes constantesI18n = (Constantes) GWT.create(Constantes.class);
197 gduche 248
 
253 gduche 249
			HashMap<String, String> mapTelephones = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
250
			if ((mapTelephones != null)&&(mapTelephones.size() > 0))	{
251
 
252
				Collection<String> telephoneKeys = mapTelephones.keySet();
253
				Iterator<String> itTelephones = telephoneKeys.iterator();
254
 
255
				while (itTelephones.hasNext())	{
256
					String key = itTelephones.next();
257
					LabelField telephoneLabel = new LabelField();
258
					String label = "";
259
					try {
260
						label = constantesI18n.getString(key);
261
					}
262
					catch (MissingResourceException e)	{
263
						label = key;
264
					}
265
 
266
					telephoneLabel.setFieldLabel( label + ":");
267
 
268
					telephoneLabel.setValue(mapTelephones.get(key));
269
 
270
					fsContact.add(telephoneLabel);
271
				}
215 aurelien 272
			}
197 gduche 273
 
253 gduche 274
			// Fax
275
			// > Plusieurs fax possible, typés
276
 
277
			HashMap<String, String> mapFax = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_fax");
278
			if ((mapFax != null)&&(mapFax.size() > 0))	{
279
 
280
				Collection<String> faxKeys = mapFax.keySet();
281
				Iterator<String> itFax = faxKeys.iterator();
282
 
283
				while (itFax.hasNext())	{
284
					String key = itFax.next();
285
					LabelField faxLabel = new LabelField();
286
					String label = "";
287
					try {
288
						label = constantesI18n.getString(key);
289
					}
290
					catch (MissingResourceException e)	{
291
						label = key;
292
					}
293
 
294
					faxLabel.setFieldLabel( label + ":");
295
 
296
					faxLabel.setValue(mapTelephones.get(key));
297
 
298
					fsContact.add(faxLabel);
299
				}
300
			}
301
 
302
			// Courriel
303
			// Courriel est un champ truk de la forme "Adresse@adr.com;; adr2@adr.fr ..."
304
 
305
			LinkedList<String> listeCourriel = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
306
			if ((listeCourriel!=null)&&(listeCourriel.size() > 0))	{
307
				String strLabelCourriel = "Courriel";
308
				if (listeCourriel.size() > 1)	{
309
					strLabelCourriel += "s";
310
				}
311
 
312
				LabelField labelCourriel = new LabelField();
313
				labelCourriel.setFieldLabel(strLabelCourriel);
314
 
315
				String valeurCourriel = "";
316
				Iterator<String> itCourriel = listeCourriel.iterator();
317
				while (itCourriel.hasNext())	{
318
					String valeurCourante = itCourriel.next();
319
					valeurCourriel += "<a href=\"mailto:" + valeurCourante + "\">" + valeurCourante + "</a><br />";
320
 
321
				}
322
 
323
				labelCourriel.setValue(valeurCourriel);
324
				fsContact.add(labelCourriel);
325
			}
326
 
327
 
260 gduche 328
			// Url Site Webs
329
			LinkedList listeUrl = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_url");
330
			if (listeUrl!=null && listeUrl.size() > 0)	{
331
				String strUrl = "";
332
				Iterator<String> urlIt = listeUrl.iterator();
333
				while (urlIt.hasNext())	{
334
					String urlCourante = urlIt.next();
335
					strUrl += "<a href=\""+urlCourante+"\">" + urlCourante + "</a> <br/>";
336
 
337
 
338
				}
339
 
340
				LabelField urlLabelField = new LabelField();
341
				urlLabelField.setFieldLabel("Url:");
342
				urlLabelField.setValue(strUrl);
343
				fsContact.add(urlLabelField);
344
			}
345
 
346
 
215 aurelien 347
			panneauIdentite.add(fsContact);
197 gduche 348
 
198 gduche 349
 
215 aurelien 350
			fsAdressePerso.setHeading("Adresse personnelle");
351
 
198 gduche 352
			/*
353
			 * Adresses :
215 aurelien 354
			 * */
197 gduche 355
			String adresse01 = (String) personne.obtenirValeurChamp("adresse_01");
266 gduche 356
			ajouterLabelField(fsAdressePerso, "Adresse", adresse01);
197 gduche 357
 
358
			String adresse02 = (String) personne.obtenirValeurChamp("adresse_02");
266 gduche 359
			ajouterLabelField(fsAdressePerso, "", adresse02);
197 gduche 360
 
361
			String boitePostale = (String) personne.obtenirValeurChamp("bp");
266 gduche 362
			ajouterLabelField(fsAdressePerso, "Boite Postale", boitePostale);
197 gduche 363
 
364
			String codePostal = (String) personne.obtenirValeurChamp("code_postal");
266 gduche 365
			ajouterLabelField(fsAdressePerso, "Code postal", codePostal);
197 gduche 366
 
367
			String ville = (String) personne.obtenirValeurChamp("ville");
266 gduche 368
			ajouterLabelField(fsAdressePerso, "Ville", ville);
197 gduche 369
 
370
			String region = (String) personne.obtenirValeurChamp("region");
266 gduche 371
			ajouterLabelField(fsAdressePerso, "Région", region);
197 gduche 372
 
373
			String pays = (String) personne.obtenirValeurChamp("pays");
266 gduche 374
			ajouterLabelField(fsAdressePerso, "Pays", pays);
197 gduche 375
 
215 aurelien 376
			fsAdressePerso.addText("<br >");
377
			fsAdressePerso.setWidth("350px");
197 gduche 378
 
215 aurelien 379
			tabAdresse.add(fsAdressePerso);
246 gduche 380
 
215 aurelien 381
 
305 gduche 382
			// Infos naturalistes
260 gduche 383
 
384
			// Biographie
267 gduche 385
			// Spécialité (typé)
386
 
269 gduche 387
			fsSpec.setHeading("Spécialités");
388
			tabInfosNat.add(fsSpec);
267 gduche 389
 
390
			HashMap hmSpecialite = (HashMap) personne.getChaineDenormaliseAsMapOrList("ce_truk_specialite");
391
			if ((hmSpecialite != null)&&(hmSpecialite.size() > 0))	{
392
 
393
				Collection<String> specialiteKeys = hmSpecialite.keySet();
394
				Iterator<String> itSpec = specialiteKeys.iterator();
395
 
396
				while (itSpec.hasNext())	{
397
					String key = itSpec.next();
398
					LabelField specLabel = new LabelField();
399
					String label = "";
400
					try {
401
						label = constantesI18n.getString(key);
402
					}
403
					catch (MissingResourceException e)	{
404
						label = key;
405
					}
406
 
407
					specLabel.setFieldLabel( label + ":");
408
 
409
					specLabel.setValue(hmSpecialite.get(key));
410
 
269 gduche 411
					fsSpec.add(specLabel);
267 gduche 412
				}
413
			}
269 gduche 414
 
415
			// Récolte
416
			LinkedList<String> lstRecolte = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_recolte");
417
			if ((lstRecolte!=null)&&(lstRecolte.size()>0))	{
418
				FieldSet fsRecolte = new FieldSet();
419
				fsRecolte.setHeading("Récoltes");
420
				fsRecolte.setLayout(new FormLayout());
421
 
422
				Iterator<String> itRecolte = lstRecolte.iterator();
423
				while (itRecolte.hasNext())	{
424
 
425
					String recolteCourante = itRecolte.next();
426
					LabelField lfRecolte = new LabelField();
427
					String[] splitRecolte = recolteCourante.split("\\|");
428
 
429
					String labelRecolte = "";
430
					if (splitRecolte.length > 1)	{
280 gduche 431
						lfRecolte.setValue(splitRecolte[1]);
269 gduche 432
					}
433
 
280 gduche 434
					lfRecolte.setFieldLabel(splitRecolte[0]);
305 gduche 435
					fsRecolte.add(lfRecolte);
269 gduche 436
 
321 gduche 437
					LinkedList<LabelField> lstComposantsRegion = (LinkedList<LabelField>) hmLabelFieldRegion.get(splitRecolte[0]);
269 gduche 438
 
305 gduche 439
					if (lstComposantsRegion == null)	{
440
						lstComposantsRegion = new LinkedList<LabelField>();
441
					}
269 gduche 442
 
305 gduche 443
					lstComposantsRegion.add(lfRecolte);
321 gduche 444
					hmLabelFieldRegion.remove(splitRecolte[0]);
445
					hmLabelFieldRegion.put(splitRecolte[0], lstComposantsRegion);
305 gduche 446
 
269 gduche 447
				}
448
 
449
				tabInfosNat.add(fsRecolte);
450
			}
305 gduche 451
 
452
			changerLabelRegions();
260 gduche 453
			// tabInfosNat
150 gduche 454
			layout();
197 gduche 455
		}
456
	}
305 gduche 457
 
458
 
459
	private void changerLabelRegions()	{
460
 
321 gduche 461
		Collection<String> colClesComposants = hmLabelFieldRegion.keySet();
305 gduche 462
		Iterator<String> itComposants = colClesComposants.iterator();
463
 
464
		while (itComposants.hasNext())	{
465
			String region = itComposants.next();
466
			mediateur.obtenirValeurEtRafraichir(this, "region", region);
467
		}
468
	}
197 gduche 469
 
266 gduche 470
	private void ajouterLabelField(FieldSet fs, String tfLabel, Object tfValue)	{
197 gduche 471
 
472
		if ((tfValue!=null)&&(!tfValue.toString().trim().equals("")))	{
189 gduche 473
 
246 gduche 474
 
475
			LabelField tf = new LabelField();
197 gduche 476
 
246 gduche 477
			tf.setFieldLabel(tfLabel + ":");
197 gduche 478
			if ((tfLabel==null)||("".equals(tfLabel)))	{
479
				tf.setHideLabel(true);
480
				tf.setStyleAttribute("margin", "0 0 0 105px");
481
			}
482
			tf.setValue(tfValue);
483
 
200 gduche 484
			//Ajout au fieldSet
485
			fs.add(tf);
486
		}
487
	}
488
 
266 gduche 489
 
197 gduche 490
 
305 gduche 491
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
197 gduche 492
 
305 gduche 493
	public void rafraichir(Object nouvellesDonnees) {
227 aurelien 494
 
495
		// Si on a reçu une personne on en affiche les détails
305 gduche 496
		if (nouvellesDonnees instanceof Personne) {
497
			afficherDetailPersonne((Personne) nouvellesDonnees);
498
		} else if (nouvellesDonnees instanceof ValeurListe)	{
499
 
500
			ValeurListe listeValeur = (ValeurListe) nouvellesDonnees;
501
			if (listeValeur.getId().equals(config.getListeId("region")))	{
502
 
503
				Collection colCleListeValeur = listeValeur.keySet();
504
 
505
				Iterator<String> itLv = colCleListeValeur.iterator();
506
 
507
				while (itLv.hasNext())	{
508
					String idRegion = itLv.next();
509
					Valeur region = listeValeur.get(idRegion);
510
 
511
 
512
 
513
					if (region != null)	{
514
 
515
						String strRegionId = region.getAbreviation();
516
 
321 gduche 517
						LinkedList<LabelField> listComposantsRegion = (LinkedList) hmLabelFieldRegion.get(strRegionId);
305 gduche 518
						for (int i=0; i < listComposantsRegion.size(); i++)	{
519
							LabelField lfRegion = listComposantsRegion.get(i);
520
							lfRegion.setFieldLabel(region.getNom());
521
						}
522
 
523
					}
524
				}
525
			}
526
		}
150 gduche 527
	}
528
 
197 gduche 529
}