Subversion Repositories eFlore/Applications.coel

Rev

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