Subversion Repositories eFlore/Applications.coel

Rev

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