Subversion Repositories eFlore/Applications.coel

Rev

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