Subversion Repositories eFlore/Applications.coel

Rev

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