Subversion Repositories eFlore/Applications.coel

Rev

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