Subversion Repositories eFlore/Applications.coel

Rev

Rev 964 | Rev 1018 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
934 jpm 1
package org.tela_botanica.client.vues.collection;
858 jpm 2
 
954 jpm 3
import java.util.HashMap;
4
import java.util.Iterator;
5
 
858 jpm 6
import org.tela_botanica.client.Mediateur;
7
import org.tela_botanica.client.composants.ChampCaseACocher;
8
import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;
9
import org.tela_botanica.client.composants.ChampSliderPourcentage;
859 jpm 10
import org.tela_botanica.client.composants.ConteneurMultiChamps;
858 jpm 11
import org.tela_botanica.client.interfaces.Rafraichissable;
954 jpm 12
import org.tela_botanica.client.modeles.aDonnee;
13
import org.tela_botanica.client.modeles.collection.Collection;
14
import org.tela_botanica.client.modeles.collection.CollectionBotanique;
15
import org.tela_botanica.client.util.Debug;
16
import org.tela_botanica.client.util.Pattern;
17
import org.tela_botanica.client.util.UtilDate;
18
import org.tela_botanica.client.util.UtilString;
934 jpm 19
import org.tela_botanica.client.vues.Formulaire;
20
import org.tela_botanica.client.vues.FormulaireOnglet;
858 jpm 21
 
859 jpm 22
import com.extjs.gxt.ui.client.util.Margins;
858 jpm 23
import com.extjs.gxt.ui.client.widget.Text;
24
import com.extjs.gxt.ui.client.widget.form.DateField;
25
import com.extjs.gxt.ui.client.widget.form.FieldSet;
26
import com.extjs.gxt.ui.client.widget.form.TextArea;
27
import com.extjs.gxt.ui.client.widget.layout.FormData;
859 jpm 28
import com.extjs.gxt.ui.client.widget.layout.HBoxLayoutData;
858 jpm 29
 
30
public class CollectionFormContenu extends FormulaireOnglet implements Rafraichissable {
31
 
954 jpm 32
	private Collection collection = null;
33
	private CollectionBotanique collectionBotanique = null;
34
	private Collection collectionCollectee = null;
35
	private CollectionBotanique collectionBotaniqueCollectee = null;
36
 
858 jpm 37
	private ChampCaseACocher natureChp = null;
38
	private TextArea specialiteChp = null;
39
	private ChampCaseACocher periodeConstitutionChp = null;
40
	private ChampComboBoxListeValeurs dateDebutCombo = null;
41
	private ChampComboBoxListeValeurs dateFinCombo = null;
42
	private DateField dateDebutChp = null;
43
	private DateField dateFinChp = null;
44
	private TextArea annotationClassementChp = null;
45
	private ChampComboBoxListeValeurs etatClassementCombo = null;
46
	private ChampComboBoxListeValeurs precisionDateCombo = null;
47
	private ChampComboBoxListeValeurs precisionLocaliteCombo = null;
48
	private TextArea etiquetteAnnotationChp = null;
49
	private ChampComboBoxListeValeurs integreCollectionCombo = null;
50
	private ChampComboBoxListeValeurs infoIntegreCollectionCombo = null;
51
	private ChampSliderPourcentage auteurTitrePourcentChp;
52
	private ChampSliderPourcentage famillePourcentChp;
53
	private ChampSliderPourcentage genrePourcentChp;
54
	private ChampSliderPourcentage spPourcentChp;
55
	private ChampSliderPourcentage auteurSpPourcentChp;
56
	private ChampSliderPourcentage localitePourcentChp;
57
	private ChampSliderPourcentage datePourcentChp;
58
 
59
	public CollectionFormContenu(Formulaire formulaireCourrant) {
60
		initialiserOnglet(formulaireCourrant);
61
		setId("contenu");
62
		setText(Mediateur.i18nC.collectionContenu());
63
 
64
		creerFieldsetNature();
65
		// TODO : réaliser un champ couverture géographique détaillé
66
		creerFieldsetPeriode();
67
		creerFieldsetClassement();
68
		creerFieldsetEtiquette();
69
		creerFieldsetIntegration();
70
	}
71
 
72
	private void creerFieldsetNature() {
73
		FieldSet natureFieldSet = new FieldSet();
964 jpm 74
		natureFieldSet.setHeading(i18nC.collectionNatureTitre());
858 jpm 75
		natureFieldSet.setCollapsible(true);
76
		natureFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
77
 
78
		natureChp = new ChampCaseACocher(i18nC.natureVegetaleContenu(), "natureVegetale", false);
79
		natureFieldSet.add(natureChp);
80
 
81
		specialiteChp = new TextArea();
82
		specialiteChp.setFieldLabel(i18nC.specialiteCollection());
83
		specialiteChp.setToolTip(i18nC.specialiteCollectionInfo());
84
		natureFieldSet.add(specialiteChp, new FormData(550, 0));
85
 
86
		add(natureFieldSet);
87
	}
88
 
89
	private void creerFieldsetPeriode() {
90
		FieldSet periodeFieldSet = new FieldSet();
964 jpm 91
		periodeFieldSet.setHeading(i18nC.collectionConstitutionTitre());
858 jpm 92
		periodeFieldSet.setCollapsible(true);
93
		periodeFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
94
 
95
		periodeConstitutionChp = new ChampCaseACocher(i18nC.periodeConstitution(), "siecleNaturaliste", false);
96
		periodeFieldSet.add(periodeConstitutionChp);
97
 
859 jpm 98
		ConteneurMultiChamps dateDebutConteneur = new ConteneurMultiChamps(i18nC.dateDebutCollection());
99
 
858 jpm 100
		dateDebutChp  = new DateField();
975 jpm 101
		dateDebutChp.getPropertyEditor().setFormat(UtilDate.formatDateFr);
102
		dateDebutChp.getPropertyEditor().setParseStrict(false);
103
		dateDebutChp.setFormatValue(true);
859 jpm 104
		dateDebutConteneur.ajouterChamp(dateDebutChp, new HBoxLayoutData(new Margins(0, 20, 0, 0)));
105
 
858 jpm 106
		dateDebutCombo = new ChampComboBoxListeValeurs(null, "dateDebut");
107
		dateDebutCombo.setTrie("id_valeur");
859 jpm 108
		dateDebutConteneur.ajouterChamp(dateDebutCombo);
858 jpm 109
 
859 jpm 110
		periodeFieldSet.add(dateDebutConteneur);
111
 
112
		ConteneurMultiChamps dateFinConteneur = new ConteneurMultiChamps(i18nC.dateFinCollection());
113
 
114
		dateFinChp = new DateField();
975 jpm 115
		dateFinChp.getPropertyEditor().setFormat(UtilDate.formatDateFr);
116
		dateFinChp.getPropertyEditor().setParseStrict(false);
117
		dateFinChp.setFormatValue(true);
859 jpm 118
		dateFinConteneur.ajouterChamp(dateFinChp, new HBoxLayoutData(new Margins(0, 20, 0, 0)));
119
 
858 jpm 120
		dateFinCombo = new ChampComboBoxListeValeurs(null, "dateFin");
121
		dateFinCombo.setTrie("id_valeur");
859 jpm 122
		dateFinConteneur.ajouterChamp(dateFinCombo);
858 jpm 123
 
859 jpm 124
		periodeFieldSet.add(dateFinConteneur);
125
 
975 jpm 126
		Text infoDate = new Text(i18nC.dateApproximativeInfo());
127
		periodeFieldSet.add(infoDate);
128
 
858 jpm 129
		add(periodeFieldSet);
130
	}
131
 
132
	private void creerFieldsetClassement() {
133
		FieldSet classementFieldSet = new FieldSet();
964 jpm 134
		classementFieldSet.setHeading(i18nC.collectionClassementTitre());
858 jpm 135
		classementFieldSet.setCollapsible(true);
136
		classementFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
859 jpm 137
 
975 jpm 138
		etatClassementCombo  = new ChampComboBoxListeValeurs(i18nC.etatClassementCollection(), "etatClassement", tabIndex++);
859 jpm 139
		classementFieldSet.add(etatClassementCombo);
140
 
858 jpm 141
		annotationClassementChp = new TextArea();
142
		annotationClassementChp.setFieldLabel(i18nC.annotationClassementCollection());
143
		classementFieldSet.add(annotationClassementChp, new FormData(550, 0));
144
 
859 jpm 145
		Text infoClassement = new Text(i18nC.annotationClassementCollectionInfo());
146
		classementFieldSet.add(infoClassement);
858 jpm 147
 
148
		add(classementFieldSet);
149
	}
150
 
151
	private void creerFieldsetEtiquette() {
152
		FieldSet etiquetteFieldSet = new FieldSet();
964 jpm 153
		etiquetteFieldSet.setHeading(i18nC.collectionEtiquetteTitre());
858 jpm 154
		etiquetteFieldSet.setCollapsible(true);
155
		etiquetteFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
156
 
157
		Text renseignementPoucentLabel = new Text(i18nC.renseignementEtiquetteCollection());
158
		renseignementPoucentLabel.setTagName("label");
159
		renseignementPoucentLabel.setStyleName("x-form-item-label");
160
		etiquetteFieldSet.add(renseignementPoucentLabel);
161
 
162
		auteurTitrePourcentChp = new ChampSliderPourcentage(i18nC.auteurTitrePourcentCollection());
163
		etiquetteFieldSet.add(auteurTitrePourcentChp, new FormData(200, 0));
164
 
165
		famillePourcentChp = new ChampSliderPourcentage(i18nC.famillePourcentCollection());
166
		etiquetteFieldSet.add(famillePourcentChp, new FormData(200, 0));
167
 
168
		genrePourcentChp = new ChampSliderPourcentage(i18nC.genrePourcentCollection());
169
		etiquetteFieldSet.add(genrePourcentChp, new FormData(200, 0));
170
 
171
		spPourcentChp = new ChampSliderPourcentage(i18nC.spPourcentCollection());
172
		etiquetteFieldSet.add(spPourcentChp, new FormData(200, 0));
173
 
174
		auteurSpPourcentChp = new ChampSliderPourcentage(i18nC.auteurSpPourcentCollection());
175
		etiquetteFieldSet.add(auteurSpPourcentChp, new FormData(200, 0));
176
 
177
		localitePourcentChp = new ChampSliderPourcentage(i18nC.localitePourcentCollection());
178
		etiquetteFieldSet.add(localitePourcentChp, new FormData(200, 0));
179
 
180
		datePourcentChp = new ChampSliderPourcentage(i18nC.datePourcentCollection());
181
		etiquetteFieldSet.add(datePourcentChp, new FormData(200, 0));
182
 
183
		precisionLocaliteCombo  = new ChampComboBoxListeValeurs(i18nC.precisionLocaliteCollection(), "onep", tabIndex++);
184
		etiquetteFieldSet.add(precisionLocaliteCombo);
185
 
186
		precisionDateCombo  = new ChampComboBoxListeValeurs(i18nC.precisionDateCollection(), "onep", tabIndex++);
187
		etiquetteFieldSet.add(precisionDateCombo);
188
 
189
		etiquetteAnnotationChp  = new TextArea();
190
		etiquetteAnnotationChp.setFieldLabel(i18nC.etiquetteAnnotationCollection());
191
		etiquetteAnnotationChp.setToolTip(i18nC.etiquetteAnnotationCollectionInfo());
192
		etiquetteFieldSet.add(etiquetteAnnotationChp, new FormData(550, 0));
193
 
194
		add(etiquetteFieldSet);
195
	}
196
 
954 jpm 197
	private String collecterEtiquetteRenseignement() {
198
		String renseignement = "";
199
		renseignement  += creerTypeValeur("AT", auteurTitrePourcentChp.getValeur());
200
		renseignement  += creerTypeValeur("F", famillePourcentChp.getValeur());
201
		renseignement  += creerTypeValeur("G", genrePourcentChp.getValeur());
202
		renseignement  += creerTypeValeur("SP", spPourcentChp.getValeur());
203
		renseignement  += creerTypeValeur("ASP", auteurSpPourcentChp.getValeur());
204
		renseignement  += creerTypeValeur("L", localitePourcentChp.getValeur());
205
		renseignement  += creerTypeValeur("D", datePourcentChp.getValeur());
206
		renseignement = renseignement.replaceFirst(aDonnee.SEPARATEUR_VALEURS+"$", "");
207
		return renseignement;
208
	}
209
 
210
	private String creerTypeValeur(String type, String valeur) {
211
		String retour = "";
212
		if (!UtilString.isEmpty(valeur)) {
213
			retour = type+aDonnee.SEPARATEUR_TYPE_VALEUR+valeur+aDonnee.SEPARATEUR_VALEURS;
214
		}
215
		return retour;
216
	}
217
 
218
	private void peuplerEtiquetteRenseignement(String valeurTruk) {
219
		HashMap<String,String> infos = parserEtiquetteRenseignement(valeurTruk);
220
		if (infos != null) {
221
			Iterator<String> it = infos.keySet().iterator();
222
			while (it.hasNext()) {
223
				String cle = it.next();
224
				if (cle.equals("AT")) {
225
					auteurTitrePourcentChp.peupler(infos.get(cle));
226
				} else if (cle.equals("F")) {
227
					famillePourcentChp.peupler(infos.get(cle));
228
				} else if (cle.equals("G")) {
229
					genrePourcentChp.peupler(infos.get(cle));
230
				} else if (cle.equals("SP")) {
231
					spPourcentChp.peupler(infos.get(cle));
232
				} else if (cle.equals("ASP")) {
233
					auteurSpPourcentChp.peupler(infos.get(cle));
234
				} else if (cle.equals("L")) {
235
					localitePourcentChp.peupler(infos.get(cle));
236
				} else if (cle.equals("D")) {
956 jpm 237
					datePourcentChp.peupler(infos.get(cle));
954 jpm 238
				}
239
			}
240
		}
241
	}
242
 
964 jpm 243
	public static HashMap<String,String> parserEtiquetteRenseignement(String valeurTruk) {
954 jpm 244
		HashMap<String,String> infos = null;
245
		if (!UtilString.isEmpty(valeurTruk)) {
246
			infos = new HashMap<String,String>();
247
			String[] pourcentages = valeurTruk.split(Pattern.quote(aDonnee.SEPARATEUR_VALEURS));
248
			for (int i = 0; i < pourcentages.length; i++) {
249
				String[] pourcentageIdValeur = pourcentages[i].split(Pattern.quote(aDonnee.SEPARATEUR_TYPE_VALEUR));
250
				String id = pourcentageIdValeur[0];
251
				String valeur = pourcentageIdValeur[1];
252
				infos.put(id, valeur);
253
			}
254
		}
255
		return infos;
256
	}
257
 
858 jpm 258
	private void creerFieldsetIntegration() {
259
		FieldSet integrationFieldSet = new FieldSet();
964 jpm 260
		integrationFieldSet.setHeading(i18nC.collectionIntegreeTitre());
858 jpm 261
		integrationFieldSet.setCollapsible(true);
262
		integrationFieldSet.setLayout(Formulaire.creerFormLayout(350, alignementLabelDefaut));
263
 
264
		integreCollectionCombo  = new ChampComboBoxListeValeurs(i18nC.integreCollection(), "onpi", tabIndex++);
265
		integrationFieldSet.add(integreCollectionCombo);
266
 
267
		infoIntegreCollectionCombo  = new ChampComboBoxListeValeurs(i18nC.infoIntegreCollection(), "onp", tabIndex++);
268
		integrationFieldSet.add(infoIntegreCollectionCombo);
269
 
270
		Text infoIntegration = new Text(i18nC.infoIntegrationCollection());
271
		integrationFieldSet.add(infoIntegration);
272
 
273
		add(integrationFieldSet);
274
	}
275
 
954 jpm 276
	public void peupler() {
277
		initialiserCollection();
278
		if (collectionBotanique != null) {
955 jpm 279
			natureChp.peupler(collectionBotanique.getNature());
280
			specialiteChp.setValue(collectionBotanique.getSpecialite());
954 jpm 281
 
955 jpm 282
			periodeConstitutionChp.peupler(collection.getPeriodeConstitution());
283
			dateDebutChp.setValue(UtilString.formaterEnDate(collectionBotanique.getRecolteDateDebut()));
284
			dateDebutCombo.peupler(collectionBotanique.getRecolteDateDebutType());
285
			dateFinChp.setValue(UtilString.formaterEnDate(collectionBotanique.getRecolteDateFin()));
286
			dateFinCombo.peupler(collectionBotanique.getRecolteDateFinType());
954 jpm 287
 
955 jpm 288
			etatClassementCombo.peupler(collectionBotanique.getClassementEtat());
289
			annotationClassementChp.setValue(collectionBotanique.getClassementAnnotation());
954 jpm 290
 
955 jpm 291
			peuplerEtiquetteRenseignement(collectionBotanique.getEtiquetteRenseignement());
292
			precisionLocaliteCombo.peupler(collectionBotanique.getPrecisionLocalite());
293
			precisionDateCombo.peupler(collectionBotanique.getPrecisionDate());
294
			etiquetteAnnotationChp.setValue(collectionBotanique.getAnnotationsDiverses());
954 jpm 295
 
955 jpm 296
			integreCollectionCombo.peupler(collectionBotanique.getCollectionIntegre());
297
			infoIntegreCollectionCombo.peupler(collectionBotanique.getCollectionIntegreInfo());
858 jpm 298
		}
299
	}
300
 
954 jpm 301
	public void collecter() {
302
		initialiserCollection();
303
		if (etreAccede()) {
304
			collectionBotaniqueCollectee.setNature(natureChp.getValeur());
305
			collectionBotaniqueCollectee.setSpecialite(specialiteChp.getValue());
858 jpm 306
 
954 jpm 307
			collectionCollectee.setPeriodeConstitution(periodeConstitutionChp.getValeur());
308
			collectionBotaniqueCollectee.setRecolteDateDebut(UtilDate.formaterEnString(dateDebutChp.getValue()));
309
			collectionBotaniqueCollectee.setRecolteDateDebutType(dateDebutCombo.getValeur());
310
			collectionBotaniqueCollectee.setRecolteDateFin(UtilDate.formaterEnString(dateFinChp.getValue()));
311
			collectionBotaniqueCollectee.setRecolteDateFinType(dateFinCombo.getValeur());
312
 
313
			collectionBotaniqueCollectee.setClassementEtat(etatClassementCombo.getValeur());
314
			collectionBotaniqueCollectee.setClassementAnnotation(annotationClassementChp.getValue());
315
 
316
			collectionBotaniqueCollectee.setEtiquetteRenseignement(collecterEtiquetteRenseignement());
317
			collectionBotaniqueCollectee.setPrecisionLocalite(precisionLocaliteCombo.getValeur());
318
			collectionBotaniqueCollectee.setPrecisionDate(precisionDateCombo.getValeur());
319
			collectionBotaniqueCollectee.setAnnotationsDiverses(etiquetteAnnotationChp.getValue());
320
 
321
			collectionBotaniqueCollectee.setCollectionIntegre(integreCollectionCombo.getValeur());
322
			collectionBotaniqueCollectee.setCollectionIntegreInfo(infoIntegreCollectionCombo.getValeur());
858 jpm 323
		}
324
	}
954 jpm 325
 
326
	private void initialiserCollection() {
327
		collection = ((CollectionForm) formulaire).collection;
328
		if (collection != null) {
329
			collectionBotanique = collection.getBotanique();
330
		}
331
 
332
		collectionCollectee = ((CollectionForm) formulaire).collectionCollectee;
333
		if (collectionCollectee != null) {
334
			collectionBotaniqueCollectee = collectionCollectee.getBotanique();
335
		}
336
	}
337
 
338
	public void rafraichir(Object nouvellesDonnees) {
339
		Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
340
	}
341
}