Subversion Repositories eFlore/Applications.coel

Rev

Rev 954 | Rev 956 | 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;
806 jpm 2
 
3
import java.util.ArrayList;
948 jpm 4
import java.util.HashMap;
806 jpm 5
import java.util.Iterator;
6
import java.util.List;
7
 
8
import org.tela_botanica.client.Mediateur;
839 jpm 9
import org.tela_botanica.client.composants.ChampCaseACocher;
854 jpm 10
import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;
857 jpm 11
import org.tela_botanica.client.composants.ChampMultiValeursMultiTypes;
858 jpm 12
import org.tela_botanica.client.composants.ChampSliderPourcentage;
806 jpm 13
import org.tela_botanica.client.images.Images;
14
import org.tela_botanica.client.interfaces.Rafraichissable;
831 jpm 15
import org.tela_botanica.client.modeles.InterneValeur;
806 jpm 16
import org.tela_botanica.client.modeles.Valeur;
17
import org.tela_botanica.client.modeles.ValeurListe;
948 jpm 18
import org.tela_botanica.client.modeles.aDonnee;
19
import org.tela_botanica.client.modeles.collection.Collection;
20
import org.tela_botanica.client.modeles.collection.CollectionBotanique;
949 jpm 21
import org.tela_botanica.client.modeles.collection.UniteBase;
22
import org.tela_botanica.client.modeles.collection.UniteRangement;
948 jpm 23
import org.tela_botanica.client.util.Debug;
24
import org.tela_botanica.client.util.Pattern;
25
import org.tela_botanica.client.util.UtilNombre;
26
import org.tela_botanica.client.util.UtilString;
934 jpm 27
import org.tela_botanica.client.vues.Formulaire;
28
import org.tela_botanica.client.vues.FormulaireOnglet;
806 jpm 29
 
859 jpm 30
import com.extjs.gxt.ui.client.Style.Scroll;
831 jpm 31
import com.extjs.gxt.ui.client.event.ButtonEvent;
806 jpm 32
import com.extjs.gxt.ui.client.event.Listener;
831 jpm 33
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
34
import com.extjs.gxt.ui.client.event.SelectionListener;
806 jpm 35
import com.extjs.gxt.ui.client.store.ListStore;
36
import com.extjs.gxt.ui.client.widget.ContentPanel;
831 jpm 37
import com.extjs.gxt.ui.client.widget.Info;
38
import com.extjs.gxt.ui.client.widget.MessageBox;
839 jpm 39
import com.extjs.gxt.ui.client.widget.Text;
831 jpm 40
import com.extjs.gxt.ui.client.widget.button.Button;
41
import com.extjs.gxt.ui.client.widget.form.ComboBox;
862 jpm 42
import com.extjs.gxt.ui.client.widget.form.FieldSet;
831 jpm 43
import com.extjs.gxt.ui.client.widget.form.NumberField;
44
import com.extjs.gxt.ui.client.widget.form.TextField;
45
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
46
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
47
import com.extjs.gxt.ui.client.widget.grid.AggregationRowConfig;
48
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
806 jpm 49
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
50
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
831 jpm 51
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
806 jpm 52
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
831 jpm 53
import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;
54
import com.extjs.gxt.ui.client.widget.grid.SummaryType;
806 jpm 55
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
831 jpm 56
import com.extjs.gxt.ui.client.widget.layout.FormData;
57
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
58
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
59
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
60
import com.google.gwt.i18n.client.NumberFormat;
806 jpm 61
 
62
public class CollectionFormDescription extends FormulaireOnglet implements Rafraichissable {
63
 
948 jpm 64
	private Collection collection = null;
65
	private CollectionBotanique collectionBotanique = null;
66
	private Collection collectionCollectee = null;
67
	private CollectionBotanique collectionBotaniqueCollectee = null;
68
 
949 jpm 69
	private ListStore<InterneValeur> precisionStore = null;
858 jpm 70
	private ChampComboBoxListeValeurs typesCollectionBotaCombo = null;
71
	private NumberField nbreEchantillonChp = null;
948 jpm 72
	private EditorGrid<UniteRangement> uniteRangementGrille = null;
854 jpm 73
	private ChampComboBoxListeValeurs etatUniteRangementCombo = null;
948 jpm 74
	private EditorGrid<UniteBase> uniteBaseGrille = null;
839 jpm 75
	private ChampCaseACocher typePapierConservationChp = null;
76
	private ChampCaseACocher methodeConservationChp = null;
858 jpm 77
	private ChampSliderPourcentage specimenFixationPourcentChp = null;
78
	private ChampSliderPourcentage etiquetteFixationPourcentChp = null;
854 jpm 79
	private ChampCaseACocher specimentMethodeFixationChp = null;
80
	private ChampCaseACocher etiquetteMethodeFixationSurSupportChp = null;
81
	private ChampCaseACocher etiquetteMethodeFixationSurSpecimenChp = null;
82
	private ChampCaseACocher typeEcritureChp = null;
83
	private ChampComboBoxListeValeurs traitementCombo = null;
84
	private ChampCaseACocher poisonTraitementChp = null;
85
	private ChampCaseACocher insecteTraitementChp = null;
86
	private ChampComboBoxListeValeurs etatGeneralCombo = null;
87
	private ChampComboBoxListeValeurs determinationCombo = null;
857 jpm 88
	private ChampMultiValeursMultiTypes specimenDegradationChp = null;
89
	private ChampMultiValeursMultiTypes presentationDegradationChp = null;
955 jpm 90
 
806 jpm 91
	public CollectionFormDescription(Formulaire formulaireCourrant) {
92
		initialiserOnglet(formulaireCourrant);
93
		setId("description");
94
		setText(Mediateur.i18nC.collectionDescription());
831 jpm 95
 
96
		FormLayout formulaireLayout = (FormLayout) this.getLayout();
97
		formulaireLayout.setLabelAlign(LabelAlign.LEFT);
98
		formulaireLayout.setLabelWidth(300);
806 jpm 99
 
862 jpm 100
		creerFieldsetPrecision();
949 jpm 101
		creerStorePrecision();
862 jpm 102
		creerUniteRangement();
103
		creerUniteBase();
104
		creerFieldsetConservation();
105
		creerFieldsetEtiquette();
106
		creerFieldsetTraitement();
107
		creerFieldsetEtat();
108
 
109
		layout();
110
	}
111
 
112
	private void creerFieldsetPrecision() {
113
		FieldSet precisionFieldSet = new FieldSet();
954 jpm 114
		precisionFieldSet.setHeading(i18nC.collectionTitrePrecision());
862 jpm 115
		precisionFieldSet.setCollapsible(true);
116
		precisionFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
117
 
858 jpm 118
		typesCollectionBotaCombo = new ChampComboBoxListeValeurs(i18nC.typeCollectionBotanique(), "typeCollectionBota");
119
		typesCollectionBotaCombo.setTabIndex(tabIndex++);
862 jpm 120
		precisionFieldSet.add(typesCollectionBotaCombo, new FormData(250, 0));
858 jpm 121
 
122
		nbreEchantillonChp = new NumberField();
123
		nbreEchantillonChp.setFieldLabel(i18nC.nbreEchantillon());
124
		nbreEchantillonChp.setToolTip(i18nC.nbreEchantillonInfo());
125
		nbreEchantillonChp.setFormat(NumberFormat.getFormat("#"));
862 jpm 126
		precisionFieldSet.add(nbreEchantillonChp);
858 jpm 127
 
862 jpm 128
		this.add(precisionFieldSet);
806 jpm 129
	}
130
 
949 jpm 131
	private void creerStorePrecision() {
132
		precisionStore = new ListStore<InterneValeur>();
133
		precisionStore.add(new InterneValeur(UniteRangement.COMPTE_APPROXIMATIF, i18nC.precisionApproximatif()));
134
		precisionStore.add(new InterneValeur(UniteRangement.COMPTE_EXACT, i18nC.precisionExact()));
135
	}
136
 
137
	private String getPrecisionNom(String precisionAbr) {
138
		String precision = "";
139
		InterneValeur precisionValeur = precisionStore.findModel("abr", precisionAbr);
140
		if (precisionValeur != null) {
141
			precision = precisionValeur.getNom();
142
		}
143
		return precision;
144
	}
145
 
146
	private String getPrecisionAbr(String precisionNom) {
147
		String precision = "";
148
		InterneValeur precisionValeur = precisionStore.findModel("nom", precisionNom);
149
		if (precisionValeur != null) {
150
			precision = precisionValeur.getAbr();
151
		}
152
		return precision;
153
	}
154
 
155
	private ComboBox<InterneValeur> getChampPrecision() {
156
		ComboBox<InterneValeur> precisionCombo = new ComboBox<InterneValeur>();
157
		precisionCombo.setForceSelection(true);
158
		precisionCombo.setTriggerAction(TriggerAction.ALL);
159
		precisionCombo.setDisplayField("nom");
160
		precisionCombo.setStore(precisionStore);
161
		precisionCombo.setEditable(false);
162
		return precisionCombo;
163
	}
164
 
831 jpm 165
	private void creerUniteRangement() {
166
		ContentPanel panneauGrille = creerPanneauContenantGrille(i18nC.collectionUniteRangementTitre());
862 jpm 167
 
831 jpm 168
		uniteRangementGrille  = creerGrilleUniteRangement();
858 jpm 169
		mediateur.obtenirListeValeurEtRafraichir(this, "typeUniteRangement");
806 jpm 170
		panneauGrille.add(uniteRangementGrille);
862 jpm 171
 
831 jpm 172
		ToolBar barreOutils = creerBarreOutilsGrilleUniteRangement();
173
		panneauGrille.setTopComponent(barreOutils);
862 jpm 174
 
806 jpm 175
		add(panneauGrille);
176
	}
831 jpm 177
 
178
	private ContentPanel creerPanneauContenantGrille(String titre) {
806 jpm 179
		ContentPanel panneau = new ContentPanel();
831 jpm 180
		panneau.setHeading(titre);
806 jpm 181
		panneau.setIcon(Images.ICONES.table());
182
		panneau.setLayout(new FitLayout());
183
		panneau.setFrame(true);
859 jpm 184
		panneau.setScrollMode(Scroll.AUTO);
862 jpm 185
		panneau.setCollapsible(true);
186
		panneau.setStyleAttribute("margin", "5px 0");
806 jpm 187
 
188
		return panneau;
189
	}
190
 
948 jpm 191
	private EditorGrid<UniteRangement> creerGrilleUniteRangement() {
806 jpm 192
		ListStore<UniteRangement> storeGrille = new ListStore<UniteRangement>();
193
 
194
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
831 jpm 195
		colonnes.add(new ColumnConfig("type", i18nC.collectionUniteType(), 150));
806 jpm 196
 
831 jpm 197
		NumberField champNombre = new NumberField();
198
		champNombre.setFormat(NumberFormat.getFormat("#"));
199
 
200
		ColumnConfig nombreColonne = new ColumnConfig("nombre", i18nC.collectionUniteNbre(), 50);
948 jpm 201
		nombreColonne.setEditor(new CellEditor(champNombre));
202
		nombreColonne.setNumberFormat(NumberFormat.getFormat("#"));
831 jpm 203
		colonnes.add(nombreColonne);
949 jpm 204
 
205
		CellEditor editeurPrecision = new CellEditor(getChampPrecision()) {
831 jpm 206
			@Override
207
			public Object preProcessValue(Object valeur) {
208
				InterneValeur retour = null;
209
				if (valeur != null ) {
949 jpm 210
					if (precisionStore.findModel("nom", valeur.toString()) != null) {
211
						retour = precisionStore.findModel("nom", valeur.toString());
212
					} else if (precisionStore.findModel("abr", valeur.toString()) != null) {
213
						retour = precisionStore.findModel("abr", valeur.toString());
831 jpm 214
					}
215
				}
216
				return retour;
217
			}
218
 
219
			@Override
220
			public Object postProcessValue(Object valeur) {
221
				String retour = null;
222
				if (valeur != null ) {
223
					if (valeur instanceof InterneValeur) {
224
						InterneValeur valeurInterne = (InterneValeur) valeur;
225
						retour = valeurInterne.getNom();
226
					}
227
				}
228
				return retour;
948 jpm 229
			}
831 jpm 230
		};
231
 
232
		ColumnConfig precisionColonne = new ColumnConfig("precision", i18nC.collectionUnitePrecision(), 50);
233
		precisionColonne.setEditor(editeurPrecision);
234
		colonnes.add(precisionColonne);
235
 
236
		TextField<String> formatChp = new TextField<String>();
237
		formatChp.setAllowBlank(false);
238
 
239
		ColumnConfig formatColonne =  new ColumnConfig("format", i18nC.collectionUniteFormat(), 100);
240
		formatColonne.setEditor(new CellEditor(formatChp));
241
		colonnes.add(formatColonne);
242
 
806 jpm 243
		GridSelectionModel<UniteRangement> modeleDeSelection = new GridSelectionModel<UniteRangement>();
244
		ColumnModel modeleDeColonnes = new ColumnModel(colonnes);
245
 
948 jpm 246
		AggregationRowConfig<UniteBase> total = new AggregationRowConfig<UniteBase>();
954 jpm 247
		total.setHtml("type", i18nC.total());
948 jpm 248
		total.setSummaryType("nombre", SummaryType.SUM);
249
		total.setSummaryFormat("nombre", NumberFormat.getFormat("#"));
250
		modeleDeColonnes.addAggregationRow(total);
251
 
831 jpm 252
		EditorGrid<UniteRangement> grilleUniteRangement = new EditorGrid<UniteRangement>(storeGrille, modeleDeColonnes);
806 jpm 253
		grilleUniteRangement.setHeight(300);
254
		grilleUniteRangement.setBorders(true);
255
		grilleUniteRangement.setSelectionModel(modeleDeSelection);
256
		grilleUniteRangement.getView().setForceFit(true);
257
		grilleUniteRangement.getView().setAutoFill(true);
258
		grilleUniteRangement.setAutoExpandColumn("type");
259
		grilleUniteRangement.setStripeRows(true);
260
		grilleUniteRangement.setTrackMouseOver(true);
261
 
262
		return grilleUniteRangement;
263
	}
264
 
948 jpm 265
	private String collecterGrilleUniteRangement() {
266
		String truk = "";
267
		int nbreUnite = uniteRangementGrille.getStore().getCount();
268
		for (int i = 0; i < nbreUnite; i++) {
269
			UniteRangement unite = uniteRangementGrille.getStore().getAt(i);
270
			truk += unite.getId()+aDonnee.SEPARATEUR_TYPE_VALEUR;
271
			truk += UtilNombre.formaterEnEntier(unite.getNombre())+aDonnee.SEPARATEUR_DONNEES;
949 jpm 272
			truk += getPrecisionAbr(unite.getPrecision())+aDonnee.SEPARATEUR_DONNEES;
948 jpm 273
			truk += unite.getFormat();
274
			truk += (i == (nbreUnite - 1)) ? "" : aDonnee.SEPARATEUR_VALEURS;
275
		}
276
		return truk;
277
	}
278
 
279
	private void peuplerGrilleUniteRangement(String valeurTruk) {
280
		if (!UtilString.isEmpty(valeurTruk)) {
281
			HashMap<String,UniteRangement> unitesEnregistrees = new HashMap<String,UniteRangement>();
282
			String[] unites = valeurTruk.split(Pattern.quote(aDonnee.SEPARATEUR_VALEURS));
283
			for (int i = 0; i < unites.length; i++) {
284
				String[] uniteTypeIdDonnees = unites[i].split(Pattern.quote(aDonnee.SEPARATEUR_TYPE_VALEUR));
285
				String uniteChaineDonnees = uniteTypeIdDonnees[1];
286
				String[] uniteDonnees = uniteChaineDonnees.split(Pattern.quote(aDonnee.SEPARATEUR_DONNEES));
287
 
288
				UniteRangement uniteRangement = new UniteRangement();
289
				uniteRangement.setId(uniteTypeIdDonnees[0]);
290
				if (uniteDonnees.length > 0) {
949 jpm 291
					uniteRangement.setNombre(UtilString.formaterEnEntier(uniteDonnees[0]));
948 jpm 292
				}
293
				if (uniteDonnees.length > 1) {
949 jpm 294
					uniteRangement.setPrecision(getPrecisionNom(uniteDonnees[1]));
948 jpm 295
				}
296
				if (uniteDonnees.length > 2) {
297
					uniteRangement.setFormat(uniteDonnees[2]);
298
				}
299
				unitesEnregistrees.put(uniteTypeIdDonnees[0], uniteRangement);
300
			}
301
 
302
			ArrayList<UniteRangement> listeUniteMaj = new ArrayList<UniteRangement>();
303
			int nbreUnite = uniteRangementGrille.getStore().getCount();
304
			for (int i = 0; i < nbreUnite; i++) {
305
				UniteRangement uniteDansGrille = uniteRangementGrille.getStore().getAt(i);
306
				UniteRangement uniteEnregistree = unitesEnregistrees.get(uniteDansGrille.getId());
307
				if (uniteEnregistree != null) {
949 jpm 308
					uniteEnregistree.setType(uniteDansGrille.getType());
948 jpm 309
					listeUniteMaj.add(uniteEnregistree);
310
				} else {
311
					listeUniteMaj.add(uniteDansGrille);
312
				}
313
			}
314
			uniteRangementGrille.getStore().removeAll();
315
			uniteRangementGrille.getStore().add(listeUniteMaj);
316
			layout();
317
		}
318
	}
319
 
831 jpm 320
	private ToolBar creerBarreOutilsGrilleUniteRangement() {
321
		ToolBar barreOutils = new ToolBar();
322
 
323
		Button ajouterBouton = creerBoutonAjouterUniteRangement();
324
		barreOutils.add(ajouterBouton);
325
 
326
		barreOutils.add(new SeparatorToolItem());
327
 
328
		Button supprimerBouton = creerBoutonSupprimerUniteRangement();
862 jpm 329
		barreOutils.add(supprimerBouton);
831 jpm 330
 
862 jpm 331
		barreOutils.add(new SeparatorToolItem());
332
		barreOutils.add(new Text(i18nC.collectionUniteRangementEtatGeneralLabel()));
333
		etatUniteRangementCombo = new ChampComboBoxListeValeurs("", "etat");
334
		etatUniteRangementCombo.setEmptyText(i18nC.collectionUniteRangementEtatGeneral());
335
		etatUniteRangementCombo.setToolTip(i18nC.collectionUniteRangementEtatGeneralInfo());
336
		etatUniteRangementCombo.setTrie("id_valeur");
337
		etatUniteRangementCombo.setWidth(300);
338
		barreOutils.add(etatUniteRangementCombo);
339
 
831 jpm 340
		return barreOutils;
341
	}
342
 
343
	private Button creerBoutonAjouterUniteRangement() {
344
		Button bouton = new Button(i18nC.ajouter());
345
		bouton.setIcon(Images.ICONES.ajouter());
346
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
347
			@Override
348
			public void componentSelected(ButtonEvent ce) {
349
				final MessageBox box = MessageBox.prompt(i18nC.collectionUniteType(), i18nC.collectionUniteRangementSaisirType());
350
					box.addCallback(new Listener<MessageBoxEvent>() {
351
					public void handleEvent(MessageBoxEvent be) {
352
						final UniteRangement unite = new UniteRangement();
353
						unite.setType(be.getValue());
354
						unite.setTypeAutre(true);
355
						uniteRangementGrille.getStore().add(unite);
356
					}
357
				});
358
			}
359
		});
360
		return bouton;
361
	}
362
 
363
	private Button creerBoutonSupprimerUniteRangement() {
364
		Button bouton = new Button(i18nC.supprimer());
365
		bouton.setIcon(Images.ICONES.supprimer());
366
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
367
			@Override
368
			public void componentSelected(ButtonEvent ce) {
369
				UniteRangement uniteRangementSelectionnee = uniteRangementGrille.getSelectionModel().getSelectedItem();
370
				if (uniteRangementSelectionnee == null) {
371
					Info.display(i18nC.informationTitreGenerique(), Mediateur.i18nM.veuillezSelectionner(i18nC.selectionnerUniteRangement()));
372
				} else if (uniteRangementSelectionnee.getTypeAutre() == false) {
373
					Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerUniteRangementAjoute());
374
				} else {
375
					uniteRangementGrille.getStore().remove(uniteRangementSelectionnee);
376
				}
377
			}
378
		});
379
		return bouton;
380
	}
381
 
382
	private void creerUniteBase() {
383
		ContentPanel panneauGrille = creerPanneauContenantGrille(i18nC.collectionUniteBaseTitre());
862 jpm 384
 
831 jpm 385
		uniteBaseGrille  = creerGrilleUniteBase();
858 jpm 386
		mediateur.obtenirListeValeurEtRafraichir(this, "typeUniteBase");
831 jpm 387
		panneauGrille.add(uniteBaseGrille);
862 jpm 388
 
831 jpm 389
		ToolBar barreOutils = creerBarreOutilsGrilleUniteBase();
390
		panneauGrille.setTopComponent(barreOutils);
862 jpm 391
 
831 jpm 392
		add(panneauGrille);
393
	}
949 jpm 394
 
948 jpm 395
	private EditorGrid<UniteBase> creerGrilleUniteBase() {
831 jpm 396
		ListStore<UniteBase> storeGrille = new ListStore<UniteBase>();
397
 
398
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
399
		colonnes.add(new ColumnConfig("type", i18nC.collectionUniteType(), 150));
400
 
401
		NumberField champNombre = new NumberField();
402
		champNombre.setFormat(NumberFormat.getFormat("#"));
403
		CellEditor editeurNombre = new CellEditor(champNombre);
404
 
405
		ColumnConfig nombreColonne = new ColumnConfig("nombre", i18nC.collectionUniteNbre(), 50);
406
		nombreColonne.setEditor(editeurNombre);
948 jpm 407
		nombreColonne.setNumberFormat(NumberFormat.getFormat("#"));
831 jpm 408
		colonnes.add(nombreColonne);
409
 
949 jpm 410
		CellEditor editeurPrecision = new CellEditor(getChampPrecision()) {
831 jpm 411
			@Override
412
			public Object preProcessValue(Object valeur) {
413
				InterneValeur retour = null;
414
				if (valeur != null ) {
949 jpm 415
					if (precisionStore.findModel("nom", valeur.toString()) != null) {
416
						retour = precisionStore.findModel("nom", valeur.toString());
417
					} else if (precisionStore.findModel("abr", valeur.toString()) != null) {
418
						retour = precisionStore.findModel("abr", valeur.toString());
831 jpm 419
					}
420
				}
421
				return retour;
422
			}
423
 
424
			@Override
425
			public Object postProcessValue(Object valeur) {
426
				String retour = null;
427
				if (valeur != null ) {
428
					if (valeur instanceof InterneValeur) {
429
						InterneValeur valeurInterne = (InterneValeur) valeur;
430
						retour = valeurInterne.getNom();
431
					}
432
				}
433
				return retour;
434
			}
435
		};
436
 
437
		ColumnConfig precisionColonne = new ColumnConfig("precision", i18nC.collectionUnitePrecision(), 50);
438
		precisionColonne.setEditor(editeurPrecision);
439
		colonnes.add(precisionColonne);
440
 
441
		TextField<String> formatChp = new TextField<String>();
442
		formatChp.setAllowBlank(false);
443
 
444
		ColumnConfig formatColonne =  new ColumnConfig("format", i18nC.collectionUniteFormat(), 100);
445
		formatColonne.setEditor(new CellEditor(formatChp));
446
		colonnes.add(formatColonne);
447
 
448
		ColumnConfig partNombreColonne = new ColumnConfig("nombre_part", i18nC.collectionUniteNbre(), 50);
449
		partNombreColonne.setEditor(editeurNombre);
948 jpm 450
		partNombreColonne.setNumberFormat(NumberFormat.getFormat("#"));
831 jpm 451
		colonnes.add(partNombreColonne);
452
 
453
		ColumnConfig partPrecisionColonne = new ColumnConfig("precision_part", i18nC.collectionUnitePrecision(), 50);
454
		partPrecisionColonne.setEditor(editeurPrecision);
455
		colonnes.add(partPrecisionColonne);
456
 
457
		ColumnConfig spNombreColonne = new ColumnConfig("nombre_sp", i18nC.collectionUniteNbre(), 50);
458
		spNombreColonne.setEditor(editeurNombre);
948 jpm 459
		spNombreColonne.setNumberFormat(NumberFormat.getFormat("#"));
831 jpm 460
		colonnes.add(spNombreColonne);
461
 
462
		ColumnConfig spPrecisionColonne = new ColumnConfig("precision_sp", i18nC.collectionUnitePrecision(), 50);
463
		spPrecisionColonne.setEditor(editeurPrecision);
464
		colonnes.add(spPrecisionColonne);
465
 
466
		GridSelectionModel<UniteBase> modeleDeSelection = new GridSelectionModel<UniteBase>();
467
		ColumnModel modeleDeColonnes = new ColumnModel(colonnes);
468
		modeleDeColonnes.addHeaderGroup(0, 0, new HeaderGroupConfig(i18nC.collectionUniteBase(), 1, 4));
469
		modeleDeColonnes.addHeaderGroup(0, 4, new HeaderGroupConfig(i18nC.collectionUniteBasePart(), 1, 2));
470
		modeleDeColonnes.addHeaderGroup(0, 6, new HeaderGroupConfig(i18nC.collectionUniteBaseSp(), 1, 2));
471
 
472
		AggregationRowConfig<UniteBase> total = new AggregationRowConfig<UniteBase>();
473
		total.setHtml("type", "TOTAL");
474
		total.setSummaryType("nombre", SummaryType.SUM);
475
		total.setSummaryFormat("nombre", NumberFormat.getFormat("#"));
476
		total.setSummaryType("nombre_part", SummaryType.SUM);
477
		total.setSummaryFormat("nombre_part", NumberFormat.getFormat("#"));
478
		total.setSummaryType("nombre_sp", SummaryType.SUM);
479
		total.setSummaryFormat("nombre_sp", NumberFormat.getFormat("#"));
480
		modeleDeColonnes.addAggregationRow(total);
481
 
482
		EditorGrid<UniteBase> grilleUniteBase = new EditorGrid<UniteBase>(storeGrille, modeleDeColonnes);
483
		grilleUniteBase.setHeight(200);
484
		grilleUniteBase.setBorders(true);
485
		grilleUniteBase.setSelectionModel(modeleDeSelection);
486
		grilleUniteBase.getView().setForceFit(true);
487
		grilleUniteBase.getView().setAutoFill(true);
488
		grilleUniteBase.setAutoExpandColumn("type");
489
		grilleUniteBase.setStripeRows(true);
490
		grilleUniteBase.setTrackMouseOver(true);
491
 
492
		return grilleUniteBase;
493
	}
494
 
949 jpm 495
	private String collecterGrilleUniteBase() {
496
		String truk = "";
497
		int nbreUnite = uniteBaseGrille.getStore().getCount();
498
		for (int i = 0; i < nbreUnite; i++) {
499
			UniteBase unite = uniteBaseGrille.getStore().getAt(i);
500
			truk += unite.getId()+aDonnee.SEPARATEUR_TYPE_VALEUR;
501
			truk += UtilNombre.formaterEnEntier(unite.getNombre())+aDonnee.SEPARATEUR_DONNEES;
502
			truk += getPrecisionAbr(unite.getPrecision())+aDonnee.SEPARATEUR_DONNEES;
503
			truk += unite.getFormat()+aDonnee.SEPARATEUR_DONNEES;
504
			truk += UtilNombre.formaterEnEntier(unite.getNombrePart())+aDonnee.SEPARATEUR_DONNEES;
505
			truk += getPrecisionAbr(unite.getPrecisionPart())+aDonnee.SEPARATEUR_DONNEES;
506
			truk += UtilNombre.formaterEnEntier(unite.getNombreSp())+aDonnee.SEPARATEUR_DONNEES;
507
			truk += getPrecisionAbr(unite.getPrecisionSp());
508
			truk += (i == (nbreUnite - 1)) ? "" : aDonnee.SEPARATEUR_VALEURS;
509
		}
510
		return truk;
511
	}
512
 
513
	private void peuplerGrilleUniteBase(String valeurTruk) {
514
		if (!UtilString.isEmpty(valeurTruk)) {
515
			HashMap<String,UniteBase> unitesEnregistrees = new HashMap<String,UniteBase>();
516
			String[] unites = valeurTruk.split(Pattern.quote(aDonnee.SEPARATEUR_VALEURS));
517
			for (int i = 0; i < unites.length; i++) {
518
				String[] uniteTypeIdDonnees = unites[i].split(Pattern.quote(aDonnee.SEPARATEUR_TYPE_VALEUR));
519
				String uniteChaineDonnees = uniteTypeIdDonnees[1];
520
				String[] uniteDonnees = uniteChaineDonnees.split(Pattern.quote(aDonnee.SEPARATEUR_DONNEES));
521
 
522
				UniteBase uniteBase = new UniteBase();
523
				uniteBase.setId(uniteTypeIdDonnees[0]);
524
				if (uniteDonnees.length > 0) {
525
					uniteBase.setNombre(UtilString.formaterEnEntier(uniteDonnees[0]));
526
				}
527
				if (uniteDonnees.length > 1) {
528
					uniteBase.setPrecision(getPrecisionNom(uniteDonnees[1]));
529
				}
530
				if (uniteDonnees.length > 2) {
531
					uniteBase.setFormat(uniteDonnees[2]);
532
				}
533
				if (uniteDonnees.length > 3) {
534
					uniteBase.setNombrePart(UtilString.formaterEnEntier(uniteDonnees[3]));
535
				}
536
				if (uniteDonnees.length > 4) {
537
					uniteBase.setPrecisionPart(getPrecisionNom(uniteDonnees[4]));
538
				}
539
				if (uniteDonnees.length > 5) {
540
					uniteBase.setNombreSp(UtilString.formaterEnEntier(uniteDonnees[5]));
541
				}
542
				if (uniteDonnees.length > 6) {
543
					uniteBase.setPrecisionSp(getPrecisionNom(uniteDonnees[6]));
544
				}
545
				unitesEnregistrees.put(uniteTypeIdDonnees[0], uniteBase);
546
			}
547
 
548
			ArrayList<UniteBase> listeUniteMaj = new ArrayList<UniteBase>();
549
			int nbreUnite = uniteBaseGrille.getStore().getCount();
550
			for (int i = 0; i < nbreUnite; i++) {
551
				UniteBase uniteDansGrille = uniteBaseGrille.getStore().getAt(i);
552
				UniteBase uniteEnregistree = unitesEnregistrees.get(uniteDansGrille.getId());
553
				if (uniteEnregistree != null) {
554
					uniteEnregistree.setType(uniteDansGrille.getType());
555
					listeUniteMaj.add(uniteEnregistree);
556
				} else {
557
					listeUniteMaj.add(uniteDansGrille);
558
				}
559
			}
560
			uniteBaseGrille.getStore().removeAll();
561
			uniteBaseGrille.getStore().add(listeUniteMaj);
562
			layout();
563
		}
564
	}
565
 
831 jpm 566
	private ToolBar creerBarreOutilsGrilleUniteBase() {
567
		ToolBar barreOutils = new ToolBar();
568
 
569
		Button ajouterBouton = creerBoutonAjouterUniteBase();
570
		barreOutils.add(ajouterBouton);
571
 
572
		barreOutils.add(new SeparatorToolItem());
573
 
574
		Button supprimerBouton = creerBoutonSupprimerUniteBase();
575
		barreOutils.add(supprimerBouton);
576
 
577
		return barreOutils;
578
	}
579
 
580
	private Button creerBoutonAjouterUniteBase() {
581
		Button bouton = new Button(i18nC.ajouter());
582
		bouton.setIcon(Images.ICONES.ajouter());
583
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
584
			@Override
585
			public void componentSelected(ButtonEvent ce) {
586
				final MessageBox box = MessageBox.prompt(i18nC.collectionUniteType(), i18nC.collectionUniteBaseSaisirType());
587
					box.addCallback(new Listener<MessageBoxEvent>() {
588
					public void handleEvent(MessageBoxEvent be) {
589
						final UniteBase unite = new UniteBase();
590
						unite.setType(be.getValue());
591
						unite.setTypeAutre(true);
592
						uniteBaseGrille.getStore().add(unite);
593
					}
594
				});
595
			}
596
		});
597
		return bouton;
598
	}
599
 
600
	private Button creerBoutonSupprimerUniteBase() {
601
		Button bouton = new Button(i18nC.supprimer());
602
		bouton.setIcon(Images.ICONES.supprimer());
603
		bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {
604
			@Override
605
			public void componentSelected(ButtonEvent ce) {
606
				UniteBase uniteBaseSelectionnee = uniteBaseGrille.getSelectionModel().getSelectedItem();
607
				if (uniteBaseSelectionnee == null) {
608
					Info.display(i18nC.informationTitreGenerique(), Mediateur.i18nM.veuillezSelectionner(i18nC.selectionnerUniteBase()));
609
				} else if (uniteBaseSelectionnee.getTypeAutre() == false) {
610
					Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerUniteBaseAjoute());
611
				} else {
612
					uniteBaseGrille.getStore().remove(uniteBaseSelectionnee);
613
				}
614
			}
615
		});
616
		return bouton;
617
	}
618
 
862 jpm 619
	private void creerFieldsetConservation() {
620
		FieldSet conservationFieldSet = new FieldSet();
954 jpm 621
		conservationFieldSet.setHeading(i18nC.collectionTitreConservation());
862 jpm 622
		conservationFieldSet.setCollapsible(true);
623
		conservationFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
624
 
625
		typePapierConservationChp = new ChampCaseACocher(i18nC.typePapierConservation(), "typePapier", true);
626
		conservationFieldSet.add(typePapierConservationChp);
627
 
628
		methodeConservationChp = new ChampCaseACocher(i18nC.methodeConservation(), "methodeRangement", true);
629
		conservationFieldSet.add(methodeConservationChp);
630
 
631
		this.add(conservationFieldSet);
632
	}
633
 
634
	private void creerFieldsetEtiquette() {
635
		FieldSet etiquetteFieldSet = new FieldSet();
954 jpm 636
		etiquetteFieldSet.setHeading(i18nC.collectionTitreEtiquette());
862 jpm 637
		etiquetteFieldSet.setCollapsible(true);
638
		etiquetteFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
639
 
640
		Text fixationPoucentLabel = new Text(i18nC.fixationPourcent());
641
		etiquetteFieldSet.add(fixationPoucentLabel);
642
 
643
		specimenFixationPourcentChp = new ChampSliderPourcentage(i18nC.specimenFixationPourcent());
644
		etiquetteFieldSet.add(specimenFixationPourcentChp, new FormData(200, 0));
645
 
646
		etiquetteFixationPourcentChp = new ChampSliderPourcentage(i18nC.etiquetteFixationPourcent());
647
		etiquetteFieldSet.add(etiquetteFixationPourcentChp, new FormData(200, 0));
648
 
649
		specimentMethodeFixationChp = new ChampCaseACocher(i18nC.specimenMethodeFixation(), "methodeFixation", true);
650
		etiquetteFieldSet.add(specimentMethodeFixationChp);
651
 
652
		etiquetteMethodeFixationSurSupportChp = new ChampCaseACocher(i18nC.etiquetteMethodeFixationSurSupport(), "methodeFixation", true);
653
		etiquetteFieldSet.add(etiquetteMethodeFixationSurSupportChp);
654
 
655
		etiquetteMethodeFixationSurSpecimenChp = new ChampCaseACocher(i18nC.etiquetteMethodeFixationSurSpecimen(), "methodeFixationSurSpecimen", true);
656
		etiquetteFieldSet.add(etiquetteMethodeFixationSurSpecimenChp);
657
 
658
		typeEcritureChp = new ChampCaseACocher(i18nC.typeEcriture(), "typeEcriture", false);
659
		etiquetteFieldSet.add(typeEcritureChp);
660
 
661
		this.add(etiquetteFieldSet);
662
	}
663
 
664
	private void creerFieldsetTraitement() {
665
		FieldSet traitementFieldSet = new FieldSet();
954 jpm 666
		traitementFieldSet.setHeading(i18nC.collectionTitreTraitement());
862 jpm 667
		traitementFieldSet.setCollapsible(true);
668
		traitementFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
669
 
670
		traitementCombo  = new ChampComboBoxListeValeurs(i18nC.collectionTraitement(), "onpi");
671
		traitementCombo.setTrie("id_valeur");
672
		traitementFieldSet.add(traitementCombo, new FormData(300, 0));
673
 
674
		poisonTraitementChp = new ChampCaseACocher(i18nC.collectionTraitementPoison(), "poisonTraitement", true);
675
		traitementFieldSet.add(poisonTraitementChp);
676
 
677
		insecteTraitementChp = new ChampCaseACocher(i18nC.collectionTraitementInsecte(), "insecteTraitement", true);
678
		traitementFieldSet.add(insecteTraitementChp);
679
 
680
		this.add(traitementFieldSet);
681
	}
682
 
683
	private void creerFieldsetEtat() {
684
		FieldSet etatFieldSet = new FieldSet();
954 jpm 685
		etatFieldSet.setHeading(i18nC.collectionTitreEtatEtDegradation());
862 jpm 686
		etatFieldSet.setCollapsible(true);
687
		etatFieldSet.setLayout(Formulaire.creerFormLayout(largeurLabelDefaut, alignementLabelDefaut));
688
 
689
		etatGeneralCombo = new ChampComboBoxListeValeurs(i18nC.collectionEtatGeneral(), "etat");
690
		etatGeneralCombo.setToolTip(i18nC.collectionEtatGeneralInfo());
691
		etatGeneralCombo.setTrie("id_valeur");
692
		etatFieldSet.add(etatGeneralCombo, new FormData(300, 0));
693
 
694
		specimenDegradationChp = new ChampMultiValeursMultiTypes(i18nC.degradationSpecimen(), 150, true);
695
		specimenDegradationChp.initialiserType("specimenDegradation");
696
		specimenDegradationChp.initialiserCombobox("niveauImportance");
697
		etatFieldSet.add(specimenDegradationChp);
698
 
699
		presentationDegradationChp = new ChampMultiValeursMultiTypes(i18nC.degradationPresentation(), 150, 200, true);
700
		presentationDegradationChp.initialiserType("supportDegradation");
701
		presentationDegradationChp.initialiserCombobox("niveauImportance");
702
		etatFieldSet.add(presentationDegradationChp);
703
 
704
		determinationCombo = new ChampComboBoxListeValeurs(i18nC.collectionDetermination(), "niveauDetermination");
705
		determinationCombo.setTrie("id_valeur");
706
		etatFieldSet.add(determinationCombo, new FormData(450, 0));
707
 
708
		this.add(etatFieldSet);
709
	}
710
 
948 jpm 711
	public void peupler() {
712
		initialiserCollection();
713
		if (collectionBotanique != null) {
714
			typesCollectionBotaCombo.peupler(collectionBotanique.getType());
715
			if (!UtilString.isEmpty(collectionBotanique.getNbreEchantillon())) {
716
				nbreEchantillonChp.setValue(Integer.parseInt(collectionBotanique.getNbreEchantillon()));
717
			}
954 jpm 718
 
948 jpm 719
			peuplerGrilleUniteRangement(collectionBotanique.getUniteRangement());
954 jpm 720
			etatUniteRangementCombo.peupler(collectionBotanique.getUniteRangementEtat());
721
 
949 jpm 722
			peuplerGrilleUniteBase(collectionBotanique.getUniteBase());
954 jpm 723
 
724
			typePapierConservationChp.peupler(collectionBotanique.getConservationPapierType());
725
			methodeConservationChp.peupler(collectionBotanique.getConservationMethode());
726
 
955 jpm 727
			specimenFixationPourcentChp.peupler(collectionBotanique.getSpecimenFixationPourcent());
728
			specimenFixationPourcentChp.peupler(collectionBotanique.getEtiquetteFixationPourcent());
729
			specimentMethodeFixationChp.peupler(collectionBotanique.getSpecimenFixationMethode());
730
			etiquetteMethodeFixationSurSupportChp.peupler(collectionBotanique.getEtiquetteFixationSupport());
731
			etiquetteMethodeFixationSurSpecimenChp.peupler(collectionBotanique.getEtiquetteFixationSpecimen());
732
			typeEcritureChp.peupler(collectionBotanique.getEtiquetteEcriture());
954 jpm 733
 
955 jpm 734
			traitementCombo.peupler(collectionBotanique.getTraitement());
735
			poisonTraitementChp.peupler(collectionBotanique.getTraitementPoison());
736
			insecteTraitementChp.peupler(collectionBotanique.getTraitementInsecte());
954 jpm 737
 
955 jpm 738
			etatGeneralCombo.peupler(collectionBotanique.getEtatGeneral());
739
			specimenDegradationChp.peupler(collectionBotanique.getDegradationSpecimen());
740
			presentationDegradationChp.peupler(collectionBotanique.getDegradationPresentation());
741
			determinationCombo.peupler(collectionBotanique.getDetermination());
948 jpm 742
		}
743
	}
744
 
745
	public void collecter() {
746
		initialiserCollection();
747
		if (etreAccede()) {
748
			collectionBotaniqueCollectee.setType(typesCollectionBotaCombo.getValeur());
749
			collectionBotaniqueCollectee.setNbreEchantillon(Integer.toString(nbreEchantillonChp.getValue().intValue()));
954 jpm 750
 
948 jpm 751
			collectionBotaniqueCollectee.setUniteRangement(collecterGrilleUniteRangement());
954 jpm 752
			collectionBotaniqueCollectee.setUniteRangementEtat(etatUniteRangementCombo.getValeur());
753
 
949 jpm 754
			collectionBotaniqueCollectee.setUniteBase(collecterGrilleUniteBase());
954 jpm 755
 
756
			collectionBotaniqueCollectee.setConservationPapierType(typePapierConservationChp.getValeur());
757
			collectionBotaniqueCollectee.setConservationMethode(methodeConservationChp.getValeur());
758
 
759
			collectionBotaniqueCollectee.setSpecimenFixationPourcent(specimenFixationPourcentChp.getValeur());
760
			collectionBotaniqueCollectee.setEtiquetteFixationPourcent(specimenFixationPourcentChp.getValeur());
761
			collectionBotaniqueCollectee.setSpecimenFixationMethode(specimentMethodeFixationChp.getValeur());
762
			collectionBotaniqueCollectee.setEtiquetteFixationSupport(etiquetteMethodeFixationSurSupportChp.getValeur());
763
			collectionBotaniqueCollectee.setEtiquetteFixationSpecimen(etiquetteMethodeFixationSurSpecimenChp.getValeur());
764
			collectionBotaniqueCollectee.setEtiquetteEcriture(typeEcritureChp.getValeur());
765
 
766
			collectionBotaniqueCollectee.setTraitement(traitementCombo.getValeur());
767
			collectionBotaniqueCollectee.setTraitementPoison(poisonTraitementChp.getValeur());
768
			collectionBotaniqueCollectee.setTraitementInsecte(insecteTraitementChp.getValeur());
769
 
770
			collectionBotaniqueCollectee.setEtatGeneral(etatGeneralCombo.getValeur());
771
			collectionBotaniqueCollectee.setDegradationSpecimen(specimenDegradationChp.getValeurs());
772
			collectionBotaniqueCollectee.setDegradationPresentation(presentationDegradationChp.getValeurs());
773
			collectionBotaniqueCollectee.setDetermination(determinationCombo.getValeur());
948 jpm 774
		}
775
	}
776
 
777
	private void initialiserCollection() {
778
		collection = ((CollectionForm) formulaire).collection;
779
		if (collection != null) {
780
			collectionBotanique = collection.getBotanique();
781
		}
782
 
783
		collectionCollectee = ((CollectionForm) formulaire).collectionCollectee;
784
		if (collectionCollectee != null) {
785
			collectionBotaniqueCollectee = collectionCollectee.getBotanique();
786
		}
787
	}
788
 
806 jpm 789
	public void rafraichir(Object nouvellesDonnees) {
790
		if (nouvellesDonnees instanceof ValeurListe) {
791
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
792
			rafraichirValeurListe(listeValeurs);
793
		} else {
954 jpm 794
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
806 jpm 795
		}
796
	}
797
 
798
	private void rafraichirValeurListe(ValeurListe listeValeurs) {
954 jpm 799
		if (listeValeurs.getId().equals(config.getListeId("typeUniteRangement"))) {
806 jpm 800
			Iterator<String> it = listeValeurs.keySet().iterator();
801
			while (it.hasNext()) {
802
				Valeur valeur = listeValeurs.get(it.next());
803
				UniteRangement unite = new UniteRangement();
948 jpm 804
				unite.setId(valeur.getId());
806 jpm 805
				unite.setType(valeur.getNom());
831 jpm 806
				unite.setTypeAutre(false);
806 jpm 807
				uniteRangementGrille.getStore().add(unite);
808
			}
831 jpm 809
		} else if (listeValeurs.getId().equals(config.getListeId("typeUniteBase"))) {
810
			Iterator<String> it = listeValeurs.keySet().iterator();
811
			while (it.hasNext()) {
812
				Valeur valeur = listeValeurs.get(it.next());
813
				UniteBase unite = new UniteBase();
948 jpm 814
				unite.setId(valeur.getId());
831 jpm 815
				unite.setType(valeur.getNom());
816
				unite.setTypeAutre(false);
817
				uniteBaseGrille.getStore().add(unite);
818
			}
806 jpm 819
		} else {
954 jpm 820
			Debug.log("Gestion de la liste "+listeValeurs.getId()+" non implémenté!");
806 jpm 821
		}
822
	}
823
}