Subversion Repositories eFlore/Applications.coel

Rev

Rev 267 | Rev 280 | 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
 
189 gduche 3
 
4
 
253 gduche 5
 
6
 
269 gduche 7
import java.util.ArrayList;
253 gduche 8
import java.util.Collection;
197 gduche 9
import java.util.HashMap;
10
import java.util.Iterator;
253 gduche 11
import java.util.LinkedList;
269 gduche 12
import java.util.List;
253 gduche 13
import java.util.MissingResourceException;
189 gduche 14
 
197 gduche 15
 
150 gduche 16
import org.tela_botanica.client.RegistreId;
253 gduche 17
import org.tela_botanica.client.i18n.Constantes;
150 gduche 18
import org.tela_botanica.client.interfaces.Rafraichissable;
19
import org.tela_botanica.client.modeles.Personne;
267 gduche 20
import org.tela_botanica.client.modeles.PersonneListe;
269 gduche 21
import org.tela_botanica.client.modeles.PersonneRecolte;
259 gduche 22
import org.tela_botanica.client.util.UtilTruk;
150 gduche 23
 
24
import com.extjs.gxt.ui.client.Registry;
259 gduche 25
 
26
 
150 gduche 27
import com.extjs.gxt.ui.client.Style.Scroll;
253 gduche 28
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
259 gduche 29
 
269 gduche 30
import com.extjs.gxt.ui.client.store.ListStore;
215 aurelien 31
import com.extjs.gxt.ui.client.widget.ContentPanel;
269 gduche 32
import com.extjs.gxt.ui.client.widget.LayoutContainer;
189 gduche 33
import com.extjs.gxt.ui.client.widget.TabItem;
34
import com.extjs.gxt.ui.client.widget.TabPanel;
197 gduche 35
import com.extjs.gxt.ui.client.widget.form.FieldSet;
246 gduche 36
import com.extjs.gxt.ui.client.widget.form.LabelField;
269 gduche 37
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
38
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
39
import com.extjs.gxt.ui.client.widget.grid.Grid;
150 gduche 40
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
197 gduche 41
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
42
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
253 gduche 43
import com.extjs.gxt.ui.client.widget.layout.TableData;
197 gduche 44
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
269 gduche 45
import com.extjs.gxt.ui.client.widget.table.Table;
46
import com.extjs.gxt.ui.client.widget.table.TableColumn;
47
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
253 gduche 48
import com.google.gwt.core.client.GWT;
260 gduche 49
import com.google.gwt.user.client.Window;
197 gduche 50
import com.google.gwt.user.client.ui.Image;
150 gduche 51
 
269 gduche 52
public class PersonneDetailPanneauVue extends LayoutContainer implements Rafraichissable {
150 gduche 53
 
197 gduche 54
	// Le panneau détail se compose de formulaires tabulés
269 gduche 55
	private TabPanel tabPanel;
189 gduche 56
 
197 gduche 57
	// Onglet 1 : identite & contact
215 aurelien 58
	private TabItem tabIdentite;
59
 
60
	private ContentPanel panneauIdentite;
61
	private ContentPanel panneauImage;
62
 
197 gduche 63
	private FieldSet fsIdentite;
64
	private FieldSet fsContact;
189 gduche 65
 
200 gduche 66
	// Onglet 2 : Adresses
67
	private TabItem tabAdresse;
68
	private FieldSet fsAdressePerso;
198 gduche 69
		// contient : adresse perso / adresse pro
70
 
215 aurelien 71
	// Onglet 3 : Informations naturalistes
72
	private TabItem tabInfosNat;
269 gduche 73
	private FieldSet fsSpec;
198 gduche 74
 
267 gduche 75
 
150 gduche 76
	public PersonneDetailPanneauVue() {
189 gduche 77
 
269 gduche 78
		tabPanel = new TabPanel();
79
		this.add(tabPanel);
80
 
198 gduche 81
		//Constructeur de la classe
150 gduche 82
		Registry.register(RegistreId.PANNEAU_PERSONNE_DETAIL, this);
189 gduche 83
		setLayout(new FitLayout());
150 gduche 84
 
215 aurelien 85
		tabIdentite = new TabItem("Identité");
86
		TableLayout tLayout = new TableLayout(2);
87
		tabIdentite.setLayout(tLayout);
88
		tabIdentite.setScrollMode(Scroll.AUTO);
189 gduche 89
 
215 aurelien 90
		panneauIdentite = new ContentPanel();
91
		panneauIdentite.setWidth("400px");
92
		panneauIdentite.setHeaderVisible(false);
93
		panneauIdentite.setBorders(false);
94
		panneauIdentite.setBodyBorder(false);
95
		panneauImage = new ContentPanel();
253 gduche 96
		panneauImage.setLayout(new FlowLayout());
215 aurelien 97
		panneauImage.setBorders(false);
253 gduche 98
		panneauImage.setWidth(350);
215 aurelien 99
		panneauImage.setBodyBorder(false);
100
		panneauImage.setHeaderVisible(false);
200 gduche 101
 
259 gduche 102
		//Gérer l'alignement vertical en haut
253 gduche 103
		TableData td = new TableData();
259 gduche 104
		td.setVerticalAlign(VerticalAlignment.TOP);
105
 
106
		tabIdentite.add(panneauIdentite, td);
253 gduche 107
		tabIdentite.add(panneauImage, td);
259 gduche 108
 
253 gduche 109
 
197 gduche 110
		fsIdentite = new FieldSet();
111
		fsIdentite.setLayout(new FormLayout());
112
 
113
 
114
		fsContact = new FieldSet();
115
		fsContact.setLayout(new FormLayout());
116
 
269 gduche 117
		tabPanel.add(tabIdentite);
197 gduche 118
 
200 gduche 119
		//Onglet Adresse:
259 gduche 120
		tabAdresse = new TabItem("Adresses");
200 gduche 121
		fsAdressePerso = new FieldSet();
122
		fsAdressePerso.setLayout(new FormLayout());
123
 
269 gduche 124
		tabPanel.add(tabAdresse);
200 gduche 125
 
215 aurelien 126
		//Onglet info naturalistes
127
		tabInfosNat = new TabItem("Informations naturalistes");
269 gduche 128
		fsSpec = new FieldSet();
129
		fsSpec.setLayout(new FormLayout());
200 gduche 130
 
269 gduche 131
		tabPanel.add(tabInfosNat);
198 gduche 132
 
150 gduche 133
	}
134
 
135
	public void afficherDetailPersonne(Personne personne) {
136
		if (personne != null) {
198 gduche 137
 
138
 
139
			//MAJ Identité : Configurer les fieldSet
215 aurelien 140
			panneauIdentite.removeAll();
141
			panneauImage.removeAll();
150 gduche 142
 
197 gduche 143
			fsIdentite.setHeading("Identité");
259 gduche 144
			//fsIdentite.setWidth("350px");
183 gduche 145
 
197 gduche 146
			fsContact.setHeading("Contact");
259 gduche 147
			//fsContact.setWidth("350px");
183 gduche 148
 
215 aurelien 149
			panneauIdentite.add(fsIdentite);
150
 
259 gduche 151
 
253 gduche 152
			//La personne peut avoir un ou plusieurs logo
153
			panneauImage.setHeight("100%");
259 gduche 154
			panneauImage.setPosition(0, 6);
155
			panneauImage.setBorders(false);
198 gduche 156
 
253 gduche 157
			LinkedList<String> listeLogos = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
158
			if ((listeLogos != null)&&(listeLogos.size() > 0))	{
259 gduche 159
				panneauImage.setBorders(true);
253 gduche 160
				for (int i = 0; i < listeLogos.size(); i++)	{
161
					String logoUrl = listeLogos.get(i);
162
					if ((logoUrl!=null)&&(!logoUrl.trim().equals("")))	{
163
						//Si c'est le cas, on l'affiche sur la même ligne que fsIdentité
164
						Image img = new Image();
165
						img.setUrl(logoUrl);
166
 
167
						panneauImage.add(img);
168
						if (panneauImage.getWidth() < (img.getWidth() + 15))	{
169
							panneauImage.setWidth(img.getWidth() + 15);
170
						}
171
 
172
					}
173
				}
246 gduche 174
 
189 gduche 175
			}
150 gduche 176
 
215 aurelien 177
			panneauIdentite.add(fsContact);
183 gduche 178
 
197 gduche 179
			fsIdentite.removeAll();
180
			fsContact.removeAll();
215 aurelien 181
			fsAdressePerso.removeAll();
269 gduche 182
			fsSpec.removeAll();
197 gduche 183
			//Ajout des champs Identité
184
 
185
 
186
 
187
			// TODO: projet
188
 
189
			// nom complet
190
			Object nomComplet = personne.obtenirValeurChamp("fmt_nom_complet");
266 gduche 191
			ajouterLabelField(fsIdentite,"Nom Complet", nomComplet);
197 gduche 192
 
259 gduche 193
			// Nom autre : champ truk; non-typé
194
			LinkedList<String> nomsAutre = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_nom_autre");
195
			if ((nomsAutre != null)&&(nomsAutre.size() > 0))	{
196
 
197
				LabelField noms = new LabelField();
198
				noms.setFieldLabel("Autres noms:");
199
				String listeNoms = UtilTruk.traiterTrukListe(nomsAutre, ", ");
200
				noms.setValue(listeNoms);
201
				fsIdentite.add(noms);
202
			}
197 gduche 203
 
204
			// abreviation
205
			Object abreviation = personne.obtenirValeurChamp("abreviation");
266 gduche 206
			ajouterLabelField(fsIdentite, "Abreviation", abreviation);
197 gduche 207
 
259 gduche 208
			// Abréviations, autre : non-typé
209
			LinkedList<String> abrevAutres = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_abreviation_autre");
210
			if ((abrevAutres != null)&&(abrevAutres.size() > 0))	{
211
 
212
				LabelField abreviations = new LabelField();
213
				abreviations.setFieldLabel("Autres abreviations:");
214
				String listeAbrev = UtilTruk.traiterTrukListe(abrevAutres, ", ");
215
				abreviations.setValue(listeAbrev);
216
				fsIdentite.add(abreviations);
217
			}
218
			fsIdentite.addText("<hr>");
197 gduche 219
 
259 gduche 220
			// date naissance
221
			// TODO : Mettre la date en format FR 10/12/09
222
			Object dateNaissance = personne.obtenirValeurChamp("naissance_date");
266 gduche 223
			ajouterLabelField(fsIdentite, "Né le", dateNaissance);
259 gduche 224
 
197 gduche 225
			// lieu naissance
259 gduche 226
			Object lieuNaissance = personne.obtenirValeurChamp("naissance_lieu");
266 gduche 227
			ajouterLabelField(fsIdentite, "A", lieuNaissance);
197 gduche 228
 
229
			// date deces
259 gduche 230
			Object dateDeces = personne.obtenirValeurChamp("deces_date");
266 gduche 231
			ajouterLabelField(fsIdentite, "Date décès", dateDeces);
197 gduche 232
 
233
			// lieu deces
259 gduche 234
			Object lieuDeces = personne.obtenirValeurChamp("deces_lieu");
266 gduche 235
			ajouterLabelField(fsIdentite, "Lieu de décès", lieuDeces);
197 gduche 236
 
259 gduche 237
			fsIdentite.addText("<hr>");
238
 
200 gduche 239
			//Description
240
			String description = (String) personne.obtenirValeurChamp("description");
241
			if ((description!=null)&&(!description.trim().equals("")))	{
253 gduche 242
				LabelField txtDescription = new LabelField();
243
				txtDescription.setFieldLabel("Description:");
200 gduche 244
				txtDescription.setValue(description);
245
 
253 gduche 246
				//rendreNonEditable(txtDescription);
200 gduche 247
 
248
				fsIdentite.add(txtDescription);
249
			}
197 gduche 250
 
251
 
253 gduche 252
			// CONTACT
253
			// Téléphones
254
			// > Plusieurs téléphones possible, typés
255
			Constantes constantesI18n = (Constantes) GWT.create(Constantes.class);
197 gduche 256
 
253 gduche 257
			HashMap<String, String> mapTelephones = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
258
			if ((mapTelephones != null)&&(mapTelephones.size() > 0))	{
259
 
260
				Collection<String> telephoneKeys = mapTelephones.keySet();
261
				Iterator<String> itTelephones = telephoneKeys.iterator();
262
 
263
				while (itTelephones.hasNext())	{
264
					String key = itTelephones.next();
265
					LabelField telephoneLabel = new LabelField();
266
					String label = "";
267
					try {
268
						label = constantesI18n.getString(key);
269
					}
270
					catch (MissingResourceException e)	{
271
						label = key;
272
					}
273
 
274
					telephoneLabel.setFieldLabel( label + ":");
275
 
276
					telephoneLabel.setValue(mapTelephones.get(key));
277
 
278
					fsContact.add(telephoneLabel);
279
				}
215 aurelien 280
			}
197 gduche 281
 
253 gduche 282
			// Fax
283
			// > Plusieurs fax possible, typés
284
 
285
			HashMap<String, String> mapFax = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_fax");
286
			if ((mapFax != null)&&(mapFax.size() > 0))	{
287
 
288
				Collection<String> faxKeys = mapFax.keySet();
289
				Iterator<String> itFax = faxKeys.iterator();
290
 
291
				while (itFax.hasNext())	{
292
					String key = itFax.next();
293
					LabelField faxLabel = new LabelField();
294
					String label = "";
295
					try {
296
						label = constantesI18n.getString(key);
297
					}
298
					catch (MissingResourceException e)	{
299
						label = key;
300
					}
301
 
302
					faxLabel.setFieldLabel( label + ":");
303
 
304
					faxLabel.setValue(mapTelephones.get(key));
305
 
306
					fsContact.add(faxLabel);
307
				}
308
			}
309
 
310
			// Courriel
311
			// Courriel est un champ truk de la forme "Adresse@adr.com;; adr2@adr.fr ..."
312
 
313
			LinkedList<String> listeCourriel = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
314
			if ((listeCourriel!=null)&&(listeCourriel.size() > 0))	{
315
				String strLabelCourriel = "Courriel";
316
				if (listeCourriel.size() > 1)	{
317
					strLabelCourriel += "s";
318
				}
319
 
320
				LabelField labelCourriel = new LabelField();
321
				labelCourriel.setFieldLabel(strLabelCourriel);
322
 
323
				String valeurCourriel = "";
324
				Iterator<String> itCourriel = listeCourriel.iterator();
325
				while (itCourriel.hasNext())	{
326
					String valeurCourante = itCourriel.next();
327
					valeurCourriel += "<a href=\"mailto:" + valeurCourante + "\">" + valeurCourante + "</a><br />";
328
 
329
				}
330
 
331
				labelCourriel.setValue(valeurCourriel);
332
				fsContact.add(labelCourriel);
333
			}
334
 
335
 
260 gduche 336
			// Url Site Webs
337
			LinkedList listeUrl = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_url");
338
			if (listeUrl!=null && listeUrl.size() > 0)	{
339
				String strUrl = "";
340
				Iterator<String> urlIt = listeUrl.iterator();
341
				while (urlIt.hasNext())	{
342
					String urlCourante = urlIt.next();
343
					strUrl += "<a href=\""+urlCourante+"\">" + urlCourante + "</a> <br/>";
344
 
345
 
346
				}
347
 
348
				LabelField urlLabelField = new LabelField();
349
				urlLabelField.setFieldLabel("Url:");
350
				urlLabelField.setValue(strUrl);
351
				fsContact.add(urlLabelField);
352
			}
353
 
354
 
215 aurelien 355
			panneauIdentite.add(fsContact);
197 gduche 356
 
198 gduche 357
 
215 aurelien 358
			fsAdressePerso.setHeading("Adresse personnelle");
359
 
198 gduche 360
			/*
361
			 * Adresses :
215 aurelien 362
			 * */
197 gduche 363
			String adresse01 = (String) personne.obtenirValeurChamp("adresse_01");
266 gduche 364
			ajouterLabelField(fsAdressePerso, "Adresse", adresse01);
197 gduche 365
 
366
			String adresse02 = (String) personne.obtenirValeurChamp("adresse_02");
266 gduche 367
			ajouterLabelField(fsAdressePerso, "", adresse02);
197 gduche 368
 
369
			String boitePostale = (String) personne.obtenirValeurChamp("bp");
266 gduche 370
			ajouterLabelField(fsAdressePerso, "Boite Postale", boitePostale);
197 gduche 371
 
372
			String codePostal = (String) personne.obtenirValeurChamp("code_postal");
266 gduche 373
			ajouterLabelField(fsAdressePerso, "Code postal", codePostal);
197 gduche 374
 
375
			String ville = (String) personne.obtenirValeurChamp("ville");
266 gduche 376
			ajouterLabelField(fsAdressePerso, "Ville", ville);
197 gduche 377
 
378
			String region = (String) personne.obtenirValeurChamp("region");
266 gduche 379
			ajouterLabelField(fsAdressePerso, "Région", region);
197 gduche 380
 
381
			String pays = (String) personne.obtenirValeurChamp("pays");
266 gduche 382
			ajouterLabelField(fsAdressePerso, "Pays", pays);
197 gduche 383
 
215 aurelien 384
			fsAdressePerso.addText("<br >");
385
			fsAdressePerso.setWidth("350px");
197 gduche 386
 
215 aurelien 387
			tabAdresse.add(fsAdressePerso);
267 gduche 388
			//tabAdresse.setScrollMode(Scroll.AUTO);
246 gduche 389
 
215 aurelien 390
 
260 gduche 391
			/*
392
			 *	Infos naturalistes
393
			 * */
394
 
395
			// Biographie
267 gduche 396
			// Spécialité (typé)
397
 
269 gduche 398
			fsSpec.setHeading("Spécialités");
399
			tabInfosNat.add(fsSpec);
267 gduche 400
 
401
			HashMap hmSpecialite = (HashMap) personne.getChaineDenormaliseAsMapOrList("ce_truk_specialite");
402
			if ((hmSpecialite != null)&&(hmSpecialite.size() > 0))	{
403
 
404
				Collection<String> specialiteKeys = hmSpecialite.keySet();
405
				Iterator<String> itSpec = specialiteKeys.iterator();
406
 
407
				while (itSpec.hasNext())	{
408
					String key = itSpec.next();
409
					LabelField specLabel = new LabelField();
410
					String label = "";
411
					try {
412
						label = constantesI18n.getString(key);
413
					}
414
					catch (MissingResourceException e)	{
415
						label = key;
416
					}
417
 
418
					specLabel.setFieldLabel( label + ":");
419
 
420
					specLabel.setValue(hmSpecialite.get(key));
421
 
269 gduche 422
					fsSpec.add(specLabel);
267 gduche 423
				}
424
			}
269 gduche 425
 
426
			// Récolte
427
 
428
 
429
 
430
			LinkedList<String> lstRecolte = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_recolte");
431
			if ((lstRecolte!=null)&&(lstRecolte.size()>0))	{
432
				FieldSet fsRecolte = new FieldSet();
433
				fsRecolte.setHeading("Récoltes");
434
				fsRecolte.setLayout(new FormLayout());
435
 
436
				Iterator<String> itRecolte = lstRecolte.iterator();
437
				while (itRecolte.hasNext())	{
438
 
439
					String recolteCourante = itRecolte.next();
440
					LabelField lfRecolte = new LabelField();
441
					String[] splitRecolte = recolteCourante.split("\\|");
442
 
443
					String labelRecolte = "";
444
					if (splitRecolte.length > 1)	{
445
 
446
						lfRecolte.setFieldLabel(splitRecolte[1]);
447
					}
448
 
449
					lfRecolte.setValue(splitRecolte[0]);
450
 
451
					// TODO : lier avec BDD ISO-3166-2
452
 
453
					fsRecolte.add(lfRecolte);
454
 
455
				}
456
 
457
				tabInfosNat.add(fsRecolte);
458
			}
260 gduche 459
			// tabInfosNat
150 gduche 460
			layout();
197 gduche 461
		}
462
	}
463
 
266 gduche 464
	private void ajouterLabelField(FieldSet fs, String tfLabel, Object tfValue)	{
197 gduche 465
 
466
		if ((tfValue!=null)&&(!tfValue.toString().trim().equals("")))	{
189 gduche 467
 
246 gduche 468
 
469
			LabelField tf = new LabelField();
197 gduche 470
 
246 gduche 471
			tf.setFieldLabel(tfLabel + ":");
197 gduche 472
			if ((tfLabel==null)||("".equals(tfLabel)))	{
473
				tf.setHideLabel(true);
474
				tf.setStyleAttribute("margin", "0 0 0 105px");
475
			}
476
			tf.setValue(tfValue);
477
 
200 gduche 478
			//Ajout au fieldSet
479
			fs.add(tf);
480
		}
481
	}
482
 
266 gduche 483
 
197 gduche 484
 
485
 
183 gduche 486
	public void rafraichir(Object nouvelleDonnees) {
227 aurelien 487
 
488
		// Si on a reçu une personne on en affiche les détails
183 gduche 489
		if (nouvelleDonnees instanceof Personne) {
490
			afficherDetailPersonne((Personne) nouvelleDonnees);
227 aurelien 491
		}
150 gduche 492
	}
493
 
197 gduche 494
}