Subversion Repositories eFlore/Applications.coel

Rev

Rev 780 | Rev 820 | 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
 
797 gduche 209
			String tabAdresseTpl = 	"<div class='{css_corps}'>" +
210
									"	<div class='{css_fieldset}'>" +
211
									"		<h2>Adresse personnelle:</h2>" +
527 gduche 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é)
797 gduche 232
			String tplInfosNat = "<div class='{css_corps}'>" +
233
								 "	<div class='{css_fieldset}'>" +
234
								 "		<h2>" + mediateur.i18nC.personneSpecialite() + "</h1>"+
527 gduche 235
								 "			{specialites}" +
797 gduche 236
								 "		<h2>" + mediateur.i18nC.personneRecolte() + "</h2>" +
237
								 "		{recoltes}" +
527 gduche 238
								 "  </div>" +
239
								 "</div>";
240
			Params prmInfosNat = new Params();
267 gduche 241
 
797 gduche 242
			//TODO : replace id region par valeur
269 gduche 243
 
797 gduche 244
			String specialite = construireTxtTruck(personne.getSpecialite());
245
			prmInfosNat.set("specialites", specialite);
527 gduche 246
 
797 gduche 247
			String recolte = construireTxtTruck(personne.getString("truk_recolte"));
248
			prmInfosNat.set("recoltes", recolte);
305 gduche 249
 
797 gduche 250
			afficherOnglet(tplInfosNat, prmInfosNat, tabInfosNat);
251
			tabAdresse.setStyleAttribute("padding", "15px");
252
 
253
 
305 gduche 254
			changerLabelRegions();
150 gduche 255
			layout();
197 gduche 256
		}
257
	}
305 gduche 258
 
527 gduche 259
	public String initialiserTplEntete()	{
472 gduche 260
 
527 gduche 261
		return "<div id='{css_id}'>"+
262
			   "<h1>{nom}</h1>"+
263
			   "<h2><a href='{mail}'>{mail}</a></h2>" +
264
			   "</div>";
472 gduche 265
	}
305 gduche 266
 
472 gduche 267
 
527 gduche 268
	public String initialiserTplIdentite() {
269
 
270
		return "<div class='{css_corps}'>" +
271
			   "	<div class='{css_fieldset}'>" +
272
				"	 <h2>Noms:</h2>" +
273
				"	 <span><b>" + mediateur.i18nC.personneNomComplet() + ":</b></span> {nom_complet}<br />" +
274
				"	 <span><b>" + mediateur.i18nC.personneNomAutre() + ":</b></span> {nom_autre}<br />" +
275
				"	 <span><b>" + mediateur.i18nC.personneAbreviation() + ":</b></span> {abreviation}<br />" +
276
				" 	 <span><b>" + mediateur.i18nC.personneAbreviationAutre() + ":</b></b></span> {abreviation_autre}<br /><br />" +
277
				"	 <h2>Naissance:</h2>" +
278
				" 	 <span><b>" + mediateur.i18nC.personneDateNaissance() + "</b></span> {naissance_date}<br />" +
279
				" 	 <span><b>" + mediateur.i18nC.personneLieuNaissance() + ":</b></span> {naissance_lieu}<br /><br />" +
280
				"	<h2>Décès:</h2>" +
281
				" 	 <span><b>" + mediateur.i18nC.personneDateDeces() + ":</b></span> {deces_date}<br />" +
282
				" 	 <span><b>" + mediateur.i18nC.personneLieuDeces() + ":</b></span> {deces_lieu}<br /><br />" +
283
				" 	</div>" +
284
				"</div>" +
285
				"<div class='{css_corps}'>" +
286
				"	<div class='css_fieldset'> " +
287
				"	<h2>Description:</h2>" +
288
				" 		{description}<br />" +
289
				"	</div>" +
290
				"<br />";
291
	}
292
 
305 gduche 293
	private void changerLabelRegions()	{
294
 
321 gduche 295
		Collection<String> colClesComposants = hmLabelFieldRegion.keySet();
305 gduche 296
		Iterator<String> itComposants = colClesComposants.iterator();
297
 
298
		while (itComposants.hasNext())	{
299
			String region = itComposants.next();
300
			mediateur.obtenirValeurEtRafraichir(this, "region", region);
301
		}
302
	}
197 gduche 303
 
266 gduche 304
	private void ajouterLabelField(FieldSet fs, String tfLabel, Object tfValue)	{
197 gduche 305
 
306
		if ((tfValue!=null)&&(!tfValue.toString().trim().equals("")))	{
189 gduche 307
 
246 gduche 308
 
309
			LabelField tf = new LabelField();
197 gduche 310
 
246 gduche 311
			tf.setFieldLabel(tfLabel + ":");
197 gduche 312
			if ((tfLabel==null)||("".equals(tfLabel)))	{
313
				tf.setHideLabel(true);
314
				tf.setStyleAttribute("margin", "0 0 0 105px");
315
			}
316
			tf.setValue(tfValue);
317
 
200 gduche 318
			//Ajout au fieldSet
319
			fs.add(tf);
320
		}
321
	}
322
 
266 gduche 323
 
197 gduche 324
 
305 gduche 325
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
197 gduche 326
 
305 gduche 327
	public void rafraichir(Object nouvellesDonnees) {
227 aurelien 328
 
329
		// Si on a reçu une personne on en affiche les détails
305 gduche 330
		if (nouvellesDonnees instanceof Personne) {
331
			afficherDetailPersonne((Personne) nouvellesDonnees);
332
		} else if (nouvellesDonnees instanceof ValeurListe)	{
333
 
334
			ValeurListe listeValeur = (ValeurListe) nouvellesDonnees;
335
			if (listeValeur.getId().equals(config.getListeId("region")))	{
336
 
337
				Collection colCleListeValeur = listeValeur.keySet();
338
 
339
				Iterator<String> itLv = colCleListeValeur.iterator();
340
 
341
				while (itLv.hasNext())	{
342
					String idRegion = itLv.next();
343
					Valeur region = listeValeur.get(idRegion);
344
 
345
 
346
 
347
					if (region != null)	{
348
 
349
						String strRegionId = region.getAbreviation();
350
 
321 gduche 351
						LinkedList<LabelField> listComposantsRegion = (LinkedList) hmLabelFieldRegion.get(strRegionId);
305 gduche 352
						for (int i=0; i < listComposantsRegion.size(); i++)	{
353
							LabelField lfRegion = listComposantsRegion.get(i);
354
							lfRegion.setFieldLabel(region.getNom());
355
						}
356
 
357
					}
358
				}
359
			}
360
		}
150 gduche 361
	}
362
 
197 gduche 363
}