Subversion Repositories eFlore/Applications.coel

Rev

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