Subversion Repositories eFlore/Applications.coel

Rev

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