Subversion Repositories eFlore/Applications.coel

Rev

Rev 472 | Rev 595 | 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());
435 gduche 73
		tabLogos.setLayout(new FlowLayout());
74
 
527 gduche 75
		tabPanel = new TabPanel();
76
		tabPanel.setId(ComposantId.ZONE_DETAIL_CORPS);
77
		tabPanel.setBodyBorder(false);
78
 
79
		tabPanel.add(tabIdentite);
80
		tabPanel.add(tabAdresse);
81
		tabPanel.add(tabInfosNat);
435 gduche 82
		tabPanel.add(tabLogos);
527 gduche 83
 
84
		panneauPrincipal.add(tabPanel);
85
		add(panneauPrincipal);
150 gduche 86
	}
87
 
321 gduche 88
	private HashMap hmLabelFieldRegion = new HashMap();
305 gduche 89
 
150 gduche 90
	public void afficherDetailPersonne(Personne personne) {
91
		if (personne != null) {
198 gduche 92
 
527 gduche 93
			String tplEntete = initialiserTplEntete();
472 gduche 94
 
435 gduche 95
			Params enteteParams = new Params();
96
			enteteParams.set("nom", (String) personne.get("fmt_nom_complet"));
97
			enteteParams.set("mail", (String) personne.get("courriel_princ"));
183 gduche 98
 
435 gduche 99
			LinkedList lstLogos = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_logo");
100
			if (lstLogos!=null && lstLogos.size() > 0)	{
101
 
102
				tabLogos.removeAll();
103
				String urlLogoPrinc = (String) lstLogos.get(0);
104
				if (!urlLogoPrinc.trim().equals(""))	{
527 gduche 105
					//TODO : changer le style et déplacer dans CSS
106
					tplEntete = "<div style='position:absolute; right:0; width:30%; text-align:right'><img src='{image}' alt='logo' height='40px'/></div>" + tplEntete;
435 gduche 107
					enteteParams.set("image", urlLogoPrinc);
253 gduche 108
				}
246 gduche 109
 
435 gduche 110
				Iterator<String> itLogo = lstLogos.iterator();
111
				while (itLogo.hasNext()){
112
					String urlLogoCourant = itLogo.next();
113
					Image imgCourante = new Image(urlLogoCourant);
114
					tabLogos.add(imgCourante);
115
				}
527 gduche 116
				tabLogos.enable();
435 gduche 117
 
118
			} else {
472 gduche 119
				enteteParams.set("image", "");
435 gduche 120
				tabLogos.disable();
472 gduche 121
			}
150 gduche 122
 
527 gduche 123
			entete.el().setInnerHtml(Format.substitute(tplEntete, enteteParams));
183 gduche 124
 
527 gduche 125
			String tplIdentite = initialiserTplIdentite();
472 gduche 126
 
435 gduche 127
			Params tabIdentiteParams = new Params();
128
			tabIdentiteParams.set("nom_complet", personne.getString("fmt_nom_complet"));
129
			tabIdentiteParams.set("abreviation", personne.getString("abreviation"));
130
			tabIdentiteParams.set("naissance_date", personne.getString("naissance_date"));
131
			tabIdentiteParams.set("naissance_lieu", personne.getString("naissance_lieu"));
132
			tabIdentiteParams.set("deces_date", personne.getString("deces_date"));
133
			tabIdentiteParams.set("deces_lieu", personne.getString("deces_lieu"));
134
			tabIdentiteParams.set("description", personne.getString("description"));
135
 
321 gduche 136
			tabInfosNat.removeAll();
197 gduche 137
 
259 gduche 138
			// Nom autre : champ truk; non-typé
139
			LinkedList<String> nomsAutre = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_nom_autre");
435 gduche 140
			String listeNoms = "";
259 gduche 141
			if ((nomsAutre != null)&&(nomsAutre.size() > 0))	{
435 gduche 142
				listeNoms = UtilTruk.traiterTrukListe(nomsAutre, ", ");
259 gduche 143
			}
435 gduche 144
			tabIdentiteParams.set("nom_autre", listeNoms);
197 gduche 145
 
259 gduche 146
			// Abréviations, autre : non-typé
147
			LinkedList<String> abrevAutres = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_abreviation_autre");
435 gduche 148
			String listeAbrev = "";
259 gduche 149
			if ((abrevAutres != null)&&(abrevAutres.size() > 0))	{
435 gduche 150
				listeAbrev = UtilTruk.traiterTrukListe(abrevAutres, ", ");
259 gduche 151
			}
435 gduche 152
			tabIdentiteParams.set("abreviation_autre", listeAbrev);
197 gduche 153
 
253 gduche 154
			HashMap<String, String> mapTelephones = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
155
			if ((mapTelephones != null)&&(mapTelephones.size() > 0))	{
156
 
157
				Collection<String> telephoneKeys = mapTelephones.keySet();
158
				Iterator<String> itTelephones = telephoneKeys.iterator();
159
 
160
				while (itTelephones.hasNext())	{
161
					String key = itTelephones.next();
472 gduche 162
					String label = mapTelephones.get(key);
253 gduche 163
					try {
472 gduche 164
						label = mediateur.i18nC.getString(label);
253 gduche 165
					}
166
					catch (MissingResourceException e)	{
167
						label = key;
168
					}
169
 
527 gduche 170
					tplIdentite += "<b>" + label + ":</b> " + key;
171
					tplIdentite += "<br />";
253 gduche 172
				}
215 aurelien 173
			}
197 gduche 174
 
472 gduche 175
			// Courriel :Champ truk de la forme "Adresse@adr.com;; adr2@adr.fr ..."
253 gduche 176
			LinkedList<String> listeCourriel = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
177
			if ((listeCourriel!=null)&&(listeCourriel.size() > 0))	{
178
				String strLabelCourriel = "Courriel";
179
				if (listeCourriel.size() > 1)	{
180
					strLabelCourriel += "s";
181
				}
182
 
183
				String valeurCourriel = "";
184
				Iterator<String> itCourriel = listeCourriel.iterator();
185
				while (itCourriel.hasNext())	{
186
					String valeurCourante = itCourriel.next();
472 gduche 187
					valeurCourriel += "<br /><a href=\"mailto:" + valeurCourante + "\">" + valeurCourante + "</a>";
253 gduche 188
				}
527 gduche 189
				tplIdentite += valeurCourriel;
253 gduche 190
			}
472 gduche 191
 
260 gduche 192
			// Url Site Webs
193
			LinkedList listeUrl = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_url");
194
			if (listeUrl!=null && listeUrl.size() > 0)	{
472 gduche 195
 
527 gduche 196
				tplIdentite += "<br /><br /><b>Sites web:</b><br /><span style='display:inline-block'>";
260 gduche 197
				String strUrl = "";
198
				Iterator<String> urlIt = listeUrl.iterator();
199
				while (urlIt.hasNext())	{
200
					String urlCourante = urlIt.next();
201
					strUrl += "<a href=\""+urlCourante+"\">" + urlCourante + "</a> <br/>";
202
				}
527 gduche 203
				tplIdentite += strUrl + "</span><br />";
472 gduche 204
			}
260 gduche 205
 
527 gduche 206
			tplIdentite += "</div>";
472 gduche 207
 
527 gduche 208
			afficherOnglet(tplIdentite, tabIdentiteParams, tabIdentite);
260 gduche 209
 
527 gduche 210
			String tabAdresseTpl = 	"<div class='css_corps'>" +
211
									"	<div class='css_fieldset'>" +
212
									"		<h1>Adresse personnelle:</h1>" +
213
									"		{adresse01} <br />" +
214
									"		{adresse02} <br />" +
215
									"		{boitePostale}<br />" +
216
									"		{codePostal} {region}<br />" +
217
									"		<span style='uppercase'>{pays}</span><br />" +
472 gduche 218
									"</div>";
219
			//Adresses :
220
			Params paramAdresseTpl = new Params();
221
			paramAdresseTpl.set("adresse01", (String) personne.obtenirValeurChamp("adresse_01"));
222
			paramAdresseTpl.set("adresse02", (String) personne.obtenirValeurChamp("adresse_02"));
223
			paramAdresseTpl.set("boitePostale", (String) personne.obtenirValeurChamp("bp"));
224
			paramAdresseTpl.set("codePostal", (String) personne.obtenirValeurChamp("code_postal"));
225
			paramAdresseTpl.set("ville", (String) personne.obtenirValeurChamp("ville"));
226
			paramAdresseTpl.set("region", (String) personne.obtenirValeurChamp("region"));
227
			paramAdresseTpl.set("pays",  (String) personne.obtenirValeurChamp("pays"));
197 gduche 228
 
472 gduche 229
			afficherOnglet(tabAdresseTpl, paramAdresseTpl, tabAdresse);
230
			tabAdresse.setStyleAttribute("padding", "15px");
215 aurelien 231
 
472 gduche 232
			// Infos naturalistes :Biographie, Spécialité (typé)
260 gduche 233
 
527 gduche 234
			String tplInfosNat = "<div class='css_corps'>" +
235
								 "	<div class='css_fieldset'>" +
236
								 "		<h1>Spécialités</h1>"+
237
								 "			{specialites}" +
238
								 "		<h1>Récolte</h1>" +
239
								 "  </div>" +
240
								 "</div>";
241
			Params prmInfosNat = new Params();
267 gduche 242
 
527 gduche 243
			String strSpecialites = "";
267 gduche 244
			HashMap hmSpecialite = (HashMap) personne.getChaineDenormaliseAsMapOrList("ce_truk_specialite");
245
			if ((hmSpecialite != null)&&(hmSpecialite.size() > 0))	{
246
 
247
				Collection<String> specialiteKeys = hmSpecialite.keySet();
248
				Iterator<String> itSpec = specialiteKeys.iterator();
249
 
250
				while (itSpec.hasNext())	{
251
					String key = itSpec.next();
252
					LabelField specLabel = new LabelField();
253
					String label = "";
254
					try {
472 gduche 255
						label = mediateur.i18nC.getString(key);
267 gduche 256
					}
257
					catch (MissingResourceException e)	{
258
						label = key;
259
					}
260
 
261
					specLabel.setFieldLabel( label + ":");
262
 
263
					specLabel.setValue(hmSpecialite.get(key));
264
 
527 gduche 265
					strSpecialites += specLabel + "<br />";
267 gduche 266
				}
267
			}
527 gduche 268
			prmInfosNat.set("specialites", strSpecialites);
269 gduche 269
 
527 gduche 270
			String strRecolte  ="";
271
 
272
 
273
			System.out.println(personne.getString("truk_recolte"));
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
}