Subversion Repositories eFlore/Applications.coel

Rev

Rev 595 | Rev 777 | 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
 
435 gduche 9
import org.tela_botanica.client.ComposantId;
305 gduche 10
import org.tela_botanica.client.Mediateur;
150 gduche 11
import org.tela_botanica.client.RegistreId;
12
import org.tela_botanica.client.interfaces.Rafraichissable;
305 gduche 13
import org.tela_botanica.client.modeles.Configuration;
150 gduche 14
import org.tela_botanica.client.modeles.Personne;
305 gduche 15
import org.tela_botanica.client.modeles.Valeur;
16
import org.tela_botanica.client.modeles.ValeurListe;
259 gduche 17
import org.tela_botanica.client.util.UtilTruk;
527 gduche 18
 
150 gduche 19
import com.extjs.gxt.ui.client.Registry;
20
import com.extjs.gxt.ui.client.Style.Scroll;
435 gduche 21
import com.extjs.gxt.ui.client.util.Format;
22
import com.extjs.gxt.ui.client.util.Params;
215 aurelien 23
import com.extjs.gxt.ui.client.widget.ContentPanel;
527 gduche 24
import com.extjs.gxt.ui.client.widget.Html;
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;
527 gduche 29
import com.extjs.gxt.ui.client.widget.layout.AnchorLayout;
150 gduche 30
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
197 gduche 31
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
32
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
435 gduche 33
import com.extjs.gxt.ui.client.widget.layout.RowData;
197 gduche 34
import com.google.gwt.user.client.ui.Image;
150 gduche 35
 
527 gduche 36
public class PersonneDetailVue extends DetailVue implements Rafraichissable {
150 gduche 37
 
435 gduche 38
 
269 gduche 39
	private TabPanel tabPanel;
527 gduche 40
	private Html entete;
189 gduche 41
 
215 aurelien 42
	private TabItem tabIdentite;
200 gduche 43
	private TabItem tabAdresse;
215 aurelien 44
	private TabItem tabInfosNat;
435 gduche 45
	private TabItem tabLogos;
46
 
527 gduche 47
	public PersonneDetailVue(Mediateur mediateur) {
189 gduche 48
 
527 gduche 49
		super(mediateur);
50
		setLayout(new FitLayout());
435 gduche 51
 
527 gduche 52
		entete = new Html();
53
		entete.setId(ComposantId.ZONE_DETAIL_ENTETE);
435 gduche 54
 
527 gduche 55
		ContentPanel panneauPrincipal = new ContentPanel();
56
		panneauPrincipal.setLayout(new FitLayout());
57
		panneauPrincipal.setHeaderVisible(false);
58
		panneauPrincipal.setBodyBorder(true);
59
		panneauPrincipal.setTopComponent(entete);
435 gduche 60
 
472 gduche 61
		tabIdentite = new TabItem(mediateur.i18nC.personneIdentite());
527 gduche 62
		tabIdentite.setLayout(new AnchorLayout());
63
		tabIdentite.setScrollMode(Scroll.AUTO);
197 gduche 64
 
472 gduche 65
		tabAdresse = new TabItem(mediateur.i18nC.personneAdresses());
66
		tabAdresse.setLayout(new FitLayout());
67
		tabAdresse.setScrollMode(Scroll.AUTO);
200 gduche 68
 
472 gduche 69
		tabInfosNat = new TabItem(mediateur.i18nC.personneInfoNat());
321 gduche 70
		tabInfosNat.setScrollMode(Scroll.AUTO);
200 gduche 71
 
472 gduche 72
		tabLogos = new TabItem(mediateur.i18nC.personneLogos());
680 gduche 73
		tabLogos.setScrollMode(Scroll.AUTO);
435 gduche 74
		tabLogos.setLayout(new FlowLayout());
75
 
527 gduche 76
		tabPanel = new TabPanel();
77
		tabPanel.setId(ComposantId.ZONE_DETAIL_CORPS);
78
		tabPanel.setBodyBorder(false);
79
 
80
		tabPanel.add(tabIdentite);
81
		tabPanel.add(tabAdresse);
82
		tabPanel.add(tabInfosNat);
435 gduche 83
		tabPanel.add(tabLogos);
527 gduche 84
 
85
		panneauPrincipal.add(tabPanel);
86
		add(panneauPrincipal);
150 gduche 87
	}
88
 
321 gduche 89
	private HashMap hmLabelFieldRegion = new HashMap();
305 gduche 90
 
150 gduche 91
	public void afficherDetailPersonne(Personne personne) {
92
		if (personne != null) {
198 gduche 93
 
527 gduche 94
			String tplEntete = initialiserTplEntete();
472 gduche 95
 
435 gduche 96
			Params enteteParams = new Params();
97
			enteteParams.set("nom", (String) personne.get("fmt_nom_complet"));
98
			enteteParams.set("mail", (String) personne.get("courriel_princ"));
183 gduche 99
 
435 gduche 100
			LinkedList lstLogos = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_logo");
101
			if (lstLogos!=null && lstLogos.size() > 0)	{
102
 
103
				tabLogos.removeAll();
104
				String urlLogoPrinc = (String) lstLogos.get(0);
105
				if (!urlLogoPrinc.trim().equals(""))	{
527 gduche 106
					//TODO : changer le style et déplacer dans CSS
107
					tplEntete = "<div style='position:absolute; right:0; width:30%; text-align:right'><img src='{image}' alt='logo' height='40px'/></div>" + tplEntete;
435 gduche 108
					enteteParams.set("image", urlLogoPrinc);
253 gduche 109
				}
246 gduche 110
 
435 gduche 111
				Iterator<String> itLogo = lstLogos.iterator();
112
				while (itLogo.hasNext()){
113
					String urlLogoCourant = itLogo.next();
114
					Image imgCourante = new Image(urlLogoCourant);
115
					tabLogos.add(imgCourante);
116
				}
527 gduche 117
				tabLogos.enable();
435 gduche 118
 
119
			} else {
472 gduche 120
				enteteParams.set("image", "");
435 gduche 121
				tabLogos.disable();
472 gduche 122
			}
150 gduche 123
 
527 gduche 124
			entete.el().setInnerHtml(Format.substitute(tplEntete, enteteParams));
183 gduche 125
 
527 gduche 126
			String tplIdentite = initialiserTplIdentite();
472 gduche 127
 
435 gduche 128
			Params tabIdentiteParams = new Params();
129
			tabIdentiteParams.set("nom_complet", personne.getString("fmt_nom_complet"));
130
			tabIdentiteParams.set("abreviation", personne.getString("abreviation"));
131
			tabIdentiteParams.set("naissance_date", personne.getString("naissance_date"));
132
			tabIdentiteParams.set("naissance_lieu", personne.getString("naissance_lieu"));
133
			tabIdentiteParams.set("deces_date", personne.getString("deces_date"));
134
			tabIdentiteParams.set("deces_lieu", personne.getString("deces_lieu"));
135
			tabIdentiteParams.set("description", personne.getString("description"));
136
 
321 gduche 137
			tabInfosNat.removeAll();
197 gduche 138
 
259 gduche 139
			// Nom autre : champ truk; non-typé
140
			LinkedList<String> nomsAutre = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_nom_autre");
435 gduche 141
			String listeNoms = "";
259 gduche 142
			if ((nomsAutre != null)&&(nomsAutre.size() > 0))	{
435 gduche 143
				listeNoms = UtilTruk.traiterTrukListe(nomsAutre, ", ");
259 gduche 144
			}
435 gduche 145
			tabIdentiteParams.set("nom_autre", listeNoms);
197 gduche 146
 
259 gduche 147
			// Abréviations, autre : non-typé
148
			LinkedList<String> abrevAutres = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_abreviation_autre");
435 gduche 149
			String listeAbrev = "";
259 gduche 150
			if ((abrevAutres != null)&&(abrevAutres.size() > 0))	{
435 gduche 151
				listeAbrev = UtilTruk.traiterTrukListe(abrevAutres, ", ");
259 gduche 152
			}
435 gduche 153
			tabIdentiteParams.set("abreviation_autre", listeAbrev);
197 gduche 154
 
253 gduche 155
			HashMap<String, String> mapTelephones = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
156
			if ((mapTelephones != null)&&(mapTelephones.size() > 0))	{
157
 
158
				Collection<String> telephoneKeys = mapTelephones.keySet();
159
				Iterator<String> itTelephones = telephoneKeys.iterator();
160
 
161
				while (itTelephones.hasNext())	{
162
					String key = itTelephones.next();
472 gduche 163
					String label = mapTelephones.get(key);
680 gduche 164
 
253 gduche 165
					try {
472 gduche 166
						label = mediateur.i18nC.getString(label);
253 gduche 167
					}
168
					catch (MissingResourceException e)	{
169
					}
170
 
527 gduche 171
					tplIdentite += "<b>" + label + ":</b> " + key;
172
					tplIdentite += "<br />";
253 gduche 173
				}
215 aurelien 174
			}
197 gduche 175
 
472 gduche 176
			// Courriel :Champ truk de la forme "Adresse@adr.com;; adr2@adr.fr ..."
253 gduche 177
			LinkedList<String> listeCourriel = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
178
			if ((listeCourriel!=null)&&(listeCourriel.size() > 0))	{
179
				String strLabelCourriel = "Courriel";
180
				if (listeCourriel.size() > 1)	{
181
					strLabelCourriel += "s";
182
				}
183
 
184
				String valeurCourriel = "";
185
				Iterator<String> itCourriel = listeCourriel.iterator();
186
				while (itCourriel.hasNext())	{
187
					String valeurCourante = itCourriel.next();
472 gduche 188
					valeurCourriel += "<br /><a href=\"mailto:" + valeurCourante + "\">" + valeurCourante + "</a>";
253 gduche 189
				}
527 gduche 190
				tplIdentite += valeurCourriel;
253 gduche 191
			}
472 gduche 192
 
260 gduche 193
			// Url Site Webs
194
			LinkedList listeUrl = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_url");
195
			if (listeUrl!=null && listeUrl.size() > 0)	{
472 gduche 196
 
527 gduche 197
				tplIdentite += "<br /><br /><b>Sites web:</b><br /><span style='display:inline-block'>";
260 gduche 198
				String strUrl = "";
199
				Iterator<String> urlIt = listeUrl.iterator();
200
				while (urlIt.hasNext())	{
201
					String urlCourante = urlIt.next();
202
					strUrl += "<a href=\""+urlCourante+"\">" + urlCourante + "</a> <br/>";
203
				}
527 gduche 204
				tplIdentite += strUrl + "</span><br />";
472 gduche 205
			}
260 gduche 206
 
527 gduche 207
			tplIdentite += "</div>";
472 gduche 208
 
527 gduche 209
			afficherOnglet(tplIdentite, tabIdentiteParams, tabIdentite);
260 gduche 210
 
527 gduche 211
			String tabAdresseTpl = 	"<div class='css_corps'>" +
212
									"	<div class='css_fieldset'>" +
213
									"		<h1>Adresse personnelle:</h1>" +
214
									"		{adresse01} <br />" +
215
									"		{adresse02} <br />" +
216
									"		{boitePostale}<br />" +
217
									"		{codePostal} {region}<br />" +
218
									"		<span style='uppercase'>{pays}</span><br />" +
472 gduche 219
									"</div>";
220
			//Adresses :
221
			Params paramAdresseTpl = new Params();
222
			paramAdresseTpl.set("adresse01", (String) personne.obtenirValeurChamp("adresse_01"));
223
			paramAdresseTpl.set("adresse02", (String) personne.obtenirValeurChamp("adresse_02"));
224
			paramAdresseTpl.set("boitePostale", (String) personne.obtenirValeurChamp("bp"));
225
			paramAdresseTpl.set("codePostal", (String) personne.obtenirValeurChamp("code_postal"));
226
			paramAdresseTpl.set("ville", (String) personne.obtenirValeurChamp("ville"));
227
			paramAdresseTpl.set("region", (String) personne.obtenirValeurChamp("region"));
228
			paramAdresseTpl.set("pays",  (String) personne.obtenirValeurChamp("pays"));
197 gduche 229
 
472 gduche 230
			afficherOnglet(tabAdresseTpl, paramAdresseTpl, tabAdresse);
231
			tabAdresse.setStyleAttribute("padding", "15px");
215 aurelien 232
 
472 gduche 233
			// Infos naturalistes :Biographie, Spécialité (typé)
260 gduche 234
 
527 gduche 235
			String tplInfosNat = "<div class='css_corps'>" +
236
								 "	<div class='css_fieldset'>" +
237
								 "		<h1>Spécialités</h1>"+
238
								 "			{specialites}" +
239
								 "		<h1>Récolte</h1>" +
240
								 "  </div>" +
241
								 "</div>";
242
			Params prmInfosNat = new Params();
267 gduche 243
 
527 gduche 244
			String strSpecialites = "";
267 gduche 245
			HashMap hmSpecialite = (HashMap) personne.getChaineDenormaliseAsMapOrList("ce_truk_specialite");
246
			if ((hmSpecialite != null)&&(hmSpecialite.size() > 0))	{
247
 
248
				Collection<String> specialiteKeys = hmSpecialite.keySet();
249
				Iterator<String> itSpec = specialiteKeys.iterator();
250
 
251
				while (itSpec.hasNext())	{
252
					String key = itSpec.next();
253
					LabelField specLabel = new LabelField();
254
					String label = "";
255
					try {
472 gduche 256
						label = mediateur.i18nC.getString(key);
267 gduche 257
					}
258
					catch (MissingResourceException e)	{
259
						label = key;
260
					}
261
 
262
					specLabel.setFieldLabel( label + ":");
263
 
264
					specLabel.setValue(hmSpecialite.get(key));
265
 
527 gduche 266
					strSpecialites += specLabel + "<br />";
267 gduche 267
				}
268
			}
527 gduche 269
			prmInfosNat.set("specialites", strSpecialites);
269 gduche 270
 
527 gduche 271
			String strRecolte  ="";
272
 
273
 
269 gduche 274
			LinkedList<String> lstRecolte = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_recolte");
275
			if ((lstRecolte!=null)&&(lstRecolte.size()>0))	{
276
				FieldSet fsRecolte = new FieldSet();
277
				fsRecolte.setHeading("Récoltes");
278
				fsRecolte.setLayout(new FormLayout());
279
 
280
				Iterator<String> itRecolte = lstRecolte.iterator();
281
				while (itRecolte.hasNext())	{
282
 
283
					String recolteCourante = itRecolte.next();
284
					LabelField lfRecolte = new LabelField();
285
					String[] splitRecolte = recolteCourante.split("\\|");
286
 
287
					String labelRecolte = "";
288
					if (splitRecolte.length > 1)	{
280 gduche 289
						lfRecolte.setValue(splitRecolte[1]);
269 gduche 290
					}
291
 
280 gduche 292
					lfRecolte.setFieldLabel(splitRecolte[0]);
305 gduche 293
					fsRecolte.add(lfRecolte);
269 gduche 294
 
321 gduche 295
					LinkedList<LabelField> lstComposantsRegion = (LinkedList<LabelField>) hmLabelFieldRegion.get(splitRecolte[0]);
269 gduche 296
 
305 gduche 297
					if (lstComposantsRegion == null)	{
298
						lstComposantsRegion = new LinkedList<LabelField>();
299
					}
269 gduche 300
 
305 gduche 301
					lstComposantsRegion.add(lfRecolte);
321 gduche 302
					hmLabelFieldRegion.remove(splitRecolte[0]);
303
					hmLabelFieldRegion.put(splitRecolte[0], lstComposantsRegion);
305 gduche 304
 
269 gduche 305
				}
306
 
307
				tabInfosNat.add(fsRecolte);
308
			}
305 gduche 309
 
310
			changerLabelRegions();
150 gduche 311
			layout();
197 gduche 312
		}
313
	}
305 gduche 314
 
527 gduche 315
	public String initialiserTplEntete()	{
472 gduche 316
 
527 gduche 317
		return "<div id='{css_id}'>"+
318
			   "<h1>{nom}</h1>"+
319
			   "<h2><a href='{mail}'>{mail}</a></h2>" +
320
			   "</div>";
472 gduche 321
	}
305 gduche 322
 
472 gduche 323
 
527 gduche 324
	public String initialiserTplIdentite() {
325
 
326
		return "<div class='{css_corps}'>" +
327
			   "	<div class='{css_fieldset}'>" +
328
				"	 <h2>Noms:</h2>" +
329
				"	 <span><b>" + mediateur.i18nC.personneNomComplet() + ":</b></span> {nom_complet}<br />" +
330
				"	 <span><b>" + mediateur.i18nC.personneNomAutre() + ":</b></span> {nom_autre}<br />" +
331
				"	 <span><b>" + mediateur.i18nC.personneAbreviation() + ":</b></span> {abreviation}<br />" +
332
				" 	 <span><b>" + mediateur.i18nC.personneAbreviationAutre() + ":</b></b></span> {abreviation_autre}<br /><br />" +
333
				"	 <h2>Naissance:</h2>" +
334
				" 	 <span><b>" + mediateur.i18nC.personneDateNaissance() + "</b></span> {naissance_date}<br />" +
335
				" 	 <span><b>" + mediateur.i18nC.personneLieuNaissance() + ":</b></span> {naissance_lieu}<br /><br />" +
336
				"	<h2>Décès:</h2>" +
337
				" 	 <span><b>" + mediateur.i18nC.personneDateDeces() + ":</b></span> {deces_date}<br />" +
338
				" 	 <span><b>" + mediateur.i18nC.personneLieuDeces() + ":</b></span> {deces_lieu}<br /><br />" +
339
				" 	</div>" +
340
				"</div>" +
341
				"<div class='{css_corps}'>" +
342
				"	<div class='css_fieldset'> " +
343
				"	<h2>Description:</h2>" +
344
				" 		{description}<br />" +
345
				"	</div>" +
346
				"<br />";
347
	}
348
 
305 gduche 349
	private void changerLabelRegions()	{
350
 
321 gduche 351
		Collection<String> colClesComposants = hmLabelFieldRegion.keySet();
305 gduche 352
		Iterator<String> itComposants = colClesComposants.iterator();
353
 
354
		while (itComposants.hasNext())	{
355
			String region = itComposants.next();
356
			mediateur.obtenirValeurEtRafraichir(this, "region", region);
357
		}
358
	}
197 gduche 359
 
266 gduche 360
	private void ajouterLabelField(FieldSet fs, String tfLabel, Object tfValue)	{
197 gduche 361
 
362
		if ((tfValue!=null)&&(!tfValue.toString().trim().equals("")))	{
189 gduche 363
 
246 gduche 364
 
365
			LabelField tf = new LabelField();
197 gduche 366
 
246 gduche 367
			tf.setFieldLabel(tfLabel + ":");
197 gduche 368
			if ((tfLabel==null)||("".equals(tfLabel)))	{
369
				tf.setHideLabel(true);
370
				tf.setStyleAttribute("margin", "0 0 0 105px");
371
			}
372
			tf.setValue(tfValue);
373
 
200 gduche 374
			//Ajout au fieldSet
375
			fs.add(tf);
376
		}
377
	}
378
 
266 gduche 379
 
197 gduche 380
 
305 gduche 381
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
197 gduche 382
 
305 gduche 383
	public void rafraichir(Object nouvellesDonnees) {
227 aurelien 384
 
385
		// Si on a reçu une personne on en affiche les détails
305 gduche 386
		if (nouvellesDonnees instanceof Personne) {
387
			afficherDetailPersonne((Personne) nouvellesDonnees);
388
		} else if (nouvellesDonnees instanceof ValeurListe)	{
389
 
390
			ValeurListe listeValeur = (ValeurListe) nouvellesDonnees;
391
			if (listeValeur.getId().equals(config.getListeId("region")))	{
392
 
393
				Collection colCleListeValeur = listeValeur.keySet();
394
 
395
				Iterator<String> itLv = colCleListeValeur.iterator();
396
 
397
				while (itLv.hasNext())	{
398
					String idRegion = itLv.next();
399
					Valeur region = listeValeur.get(idRegion);
400
 
401
 
402
 
403
					if (region != null)	{
404
 
405
						String strRegionId = region.getAbreviation();
406
 
321 gduche 407
						LinkedList<LabelField> listComposantsRegion = (LinkedList) hmLabelFieldRegion.get(strRegionId);
305 gduche 408
						for (int i=0; i < listComposantsRegion.size(); i++)	{
409
							LabelField lfRegion = listComposantsRegion.get(i);
410
							lfRegion.setFieldLabel(region.getNom());
411
						}
412
 
413
					}
414
				}
415
			}
416
		}
150 gduche 417
	}
418
 
197 gduche 419
}