Rev 858 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.composants.ChampCaseACocher;import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;import org.tela_botanica.client.composants.ChampMultiValeursMultiTypes;import org.tela_botanica.client.composants.ChampSliderPourcentage;import org.tela_botanica.client.images.Images;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.InterneValeur;import org.tela_botanica.client.modeles.UniteBase;import org.tela_botanica.client.modeles.UniteRangement;import org.tela_botanica.client.modeles.Valeur;import org.tela_botanica.client.modeles.ValeurListe;import com.extjs.gxt.ui.client.Style.Scroll;import com.extjs.gxt.ui.client.event.ButtonEvent;import com.extjs.gxt.ui.client.event.Events;import com.extjs.gxt.ui.client.event.Listener;import com.extjs.gxt.ui.client.event.MessageBoxEvent;import com.extjs.gxt.ui.client.event.SelectionListener;import com.extjs.gxt.ui.client.event.SliderEvent;import com.extjs.gxt.ui.client.store.ListStore;import com.extjs.gxt.ui.client.widget.ContentPanel;import com.extjs.gxt.ui.client.widget.Info;import com.extjs.gxt.ui.client.widget.MessageBox;import com.extjs.gxt.ui.client.widget.Slider;import com.extjs.gxt.ui.client.widget.Text;import com.extjs.gxt.ui.client.widget.button.Button;import com.extjs.gxt.ui.client.widget.form.ComboBox;import com.extjs.gxt.ui.client.widget.form.NumberField;import com.extjs.gxt.ui.client.widget.form.SliderField;import com.extjs.gxt.ui.client.widget.form.TextField;import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;import com.extjs.gxt.ui.client.widget.grid.AggregationRowConfig;import com.extjs.gxt.ui.client.widget.grid.CellEditor;import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;import com.extjs.gxt.ui.client.widget.grid.ColumnModel;import com.extjs.gxt.ui.client.widget.grid.EditorGrid;import com.extjs.gxt.ui.client.widget.grid.Grid;import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;import com.extjs.gxt.ui.client.widget.grid.SummaryType;import com.extjs.gxt.ui.client.widget.layout.FitLayout;import com.extjs.gxt.ui.client.widget.layout.FormData;import com.extjs.gxt.ui.client.widget.layout.FormLayout;import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;import com.google.gwt.core.client.GWT;import com.google.gwt.i18n.client.NumberFormat;public class CollectionFormDescription extends FormulaireOnglet implements Rafraichissable {private ChampComboBoxListeValeurs typesCollectionBotaCombo = null;private TextField<String> coteChp = null;private NumberField nbreEchantillonChp = null;private Grid<UniteRangement> uniteRangementGrille = null;private ChampComboBoxListeValeurs etatUniteRangementCombo = null;private Grid<UniteBase> uniteBaseGrille = null;private ChampCaseACocher typePapierConservationChp = null;private ChampCaseACocher methodeConservationChp = null;private ChampSliderPourcentage specimenFixationPourcentChp = null;private ChampSliderPourcentage etiquetteFixationPourcentChp = null;private ChampCaseACocher specimentMethodeFixationChp = null;private ChampCaseACocher etiquetteMethodeFixationSurSupportChp = null;private ChampCaseACocher etiquetteMethodeFixationSurSpecimenChp = null;private ChampCaseACocher typeEcritureChp = null;private ChampComboBoxListeValeurs traitementCombo = null;private ChampCaseACocher poisonTraitementChp = null;private ChampCaseACocher insecteTraitementChp = null;private ChampComboBoxListeValeurs etatGeneralCombo = null;private ChampComboBoxListeValeurs determinationCombo = null;private ChampMultiValeursMultiTypes specimenDegradationChp = null;private ChampMultiValeursMultiTypes presentationDegradationChp = null;public CollectionFormDescription(Formulaire formulaireCourrant) {initialiserOnglet(formulaireCourrant);setId("description");setText(Mediateur.i18nC.collectionDescription());FormLayout formulaireLayout = (FormLayout) this.getLayout();formulaireLayout.setLabelAlign(LabelAlign.LEFT);formulaireLayout.setLabelWidth(300);typesCollectionBotaCombo = new ChampComboBoxListeValeurs(i18nC.typeCollectionBotanique(), "typeCollectionBota");typesCollectionBotaCombo.setTabIndex(tabIndex++);add(typesCollectionBotaCombo, new FormData(250, 0));coteChp = new TextField<String>();coteChp.setTabIndex(tabIndex++);coteChp.setFieldLabel(i18nC.cote());add(coteChp, new FormData(450, 0));nbreEchantillonChp = new NumberField();nbreEchantillonChp.setFieldLabel(i18nC.nbreEchantillon());nbreEchantillonChp.setToolTip(i18nC.nbreEchantillonInfo());nbreEchantillonChp.setFormat(NumberFormat.getFormat("#"));add(nbreEchantillonChp);creerUniteRangement();creerUniteBase();typePapierConservationChp = new ChampCaseACocher(i18nC.typePapierConservation(), "typePapier", true);add(typePapierConservationChp);methodeConservationChp = new ChampCaseACocher(i18nC.methodeConservation(), "methodeRangement", true);add(methodeConservationChp);Text fixationPoucentLabel = new Text(i18nC.fixationPourcent());add(fixationPoucentLabel);specimenFixationPourcentChp = new ChampSliderPourcentage(i18nC.specimenFixationPourcent());add(specimenFixationPourcentChp, new FormData(200, 0));etiquetteFixationPourcentChp = new ChampSliderPourcentage(i18nC.etiquetteFixationPourcent());add(etiquetteFixationPourcentChp, new FormData(200, 0));specimentMethodeFixationChp = new ChampCaseACocher(i18nC.specimenMethodeFixation(), "methodeFixation", true);add(specimentMethodeFixationChp);etiquetteMethodeFixationSurSupportChp = new ChampCaseACocher(i18nC.etiquetteMethodeFixationSurSupport(), "methodeFixation", true);add(etiquetteMethodeFixationSurSupportChp);etiquetteMethodeFixationSurSpecimenChp = new ChampCaseACocher(i18nC.etiquetteMethodeFixationSurSpecimen(), "methodeFixationSurSpecimen", true);add(etiquetteMethodeFixationSurSpecimenChp);typeEcritureChp = new ChampCaseACocher(i18nC.typeEcriture(), "typeEcriture", false);add(typeEcritureChp);traitementCombo = new ChampComboBoxListeValeurs(i18nC.collectionTraitement(), "onpi");traitementCombo.setTrie("id_valeur");add(traitementCombo, new FormData(300, 0));poisonTraitementChp = new ChampCaseACocher(i18nC.collectionTraitementPoison(), "poisonTraitement", true);add(poisonTraitementChp);insecteTraitementChp = new ChampCaseACocher(i18nC.collectionTraitementInsecte(), "insecteTraitement", true);add(insecteTraitementChp);etatGeneralCombo = new ChampComboBoxListeValeurs(i18nC.collectionEtatGeneral(), "etat");etatGeneralCombo.setToolTip(i18nC.collectionEtatGeneralInfo());etatGeneralCombo.setTrie("id_valeur");add(etatGeneralCombo, new FormData(300, 0));specimenDegradationChp = new ChampMultiValeursMultiTypes(i18nC.degradationSpecimen(), 600, true);specimenDegradationChp.initialiserType("specimenDegradation");specimenDegradationChp.initialiserCombobox("niveauImportance");add(specimenDegradationChp);presentationDegradationChp = new ChampMultiValeursMultiTypes(i18nC.degradationPresentation(), 600, true);presentationDegradationChp.initialiserType("supportDegradation");presentationDegradationChp.initialiserCombobox("niveauImportance");add(presentationDegradationChp);determinationCombo = new ChampComboBoxListeValeurs(i18nC.collectionDetermination(), "niveauDetermination");determinationCombo.setTrie("id_valeur");add(determinationCombo, new FormData(450, 0));layout();}private void creerUniteRangement() {ContentPanel panneauGrille = creerPanneauContenantGrille(i18nC.collectionUniteRangementTitre());uniteRangementGrille = creerGrilleUniteRangement();mediateur.obtenirListeValeurEtRafraichir(this, "typeUniteRangement");panneauGrille.add(uniteRangementGrille);ToolBar barreOutils = creerBarreOutilsGrilleUniteRangement();panneauGrille.setTopComponent(barreOutils);add(panneauGrille);etatUniteRangementCombo = new ChampComboBoxListeValeurs(i18nC.collectionUniteRangementEtatGeneral(), "etat");etatUniteRangementCombo.setToolTip(i18nC.collectionUniteRangementEtatGeneralInfo());etatUniteRangementCombo.setTrie("id_valeur");add(etatUniteRangementCombo, new FormData(300, 0));}private ContentPanel creerPanneauContenantGrille(String titre) {ContentPanel panneau = new ContentPanel();panneau.setHeading(titre);panneau.setIcon(Images.ICONES.table());panneau.setLayout(new FitLayout());panneau.setFrame(true);panneau.setScrollMode(Scroll.AUTO);return panneau;}private Grid<UniteRangement> creerGrilleUniteRangement() {ListStore<UniteRangement> storeGrille = new ListStore<UniteRangement>();List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();colonnes.add(new ColumnConfig("type", i18nC.collectionUniteType(), 150));NumberField champNombre = new NumberField();champNombre.setFormat(NumberFormat.getFormat("#"));CellEditor editeurNombre = new CellEditor(champNombre);ColumnConfig nombreColonne = new ColumnConfig("nombre", i18nC.collectionUniteNbre(), 50);nombreColonne.setEditor(editeurNombre);colonnes.add(nombreColonne);ListStore<InterneValeur> precisionStore = new ListStore<InterneValeur>();precisionStore.add(new InterneValeur(UniteRangement.COMPTE_APPROXIMATIF, i18nC.precisionApproximatif()));precisionStore.add(new InterneValeur(UniteRangement.COMPTE_EXACT, i18nC.precisionExact()));final ComboBox<InterneValeur> precisionCombo = new ComboBox<InterneValeur>();precisionCombo.setForceSelection(true);precisionCombo.setTriggerAction(TriggerAction.ALL);precisionCombo.setDisplayField("nom");precisionCombo.setStore(precisionStore);precisionCombo.setEditable(false);CellEditor editeurPrecision = new CellEditor(precisionCombo) {@Overridepublic Object preProcessValue(Object valeur) {InterneValeur retour = null;if (valeur != null ) {if (precisionCombo.getStore().findModel("nom", valeur.toString()) != null) {retour = precisionCombo.getStore().findModel("nom", valeur.toString());} else if (precisionCombo.getStore().findModel("abr", valeur.toString()) != null) {retour = precisionCombo.getStore().findModel("abr", valeur.toString());}}return retour;}@Overridepublic Object postProcessValue(Object valeur) {String retour = null;if (valeur != null ) {if (valeur instanceof InterneValeur) {InterneValeur valeurInterne = (InterneValeur) valeur;retour = valeurInterne.getNom();}}return retour;}};ColumnConfig precisionColonne = new ColumnConfig("precision", i18nC.collectionUnitePrecision(), 50);precisionColonne.setEditor(editeurPrecision);colonnes.add(precisionColonne);TextField<String> formatChp = new TextField<String>();formatChp.setAllowBlank(false);ColumnConfig formatColonne = new ColumnConfig("format", i18nC.collectionUniteFormat(), 100);formatColonne.setEditor(new CellEditor(formatChp));colonnes.add(formatColonne);GridSelectionModel<UniteRangement> modeleDeSelection = new GridSelectionModel<UniteRangement>();ColumnModel modeleDeColonnes = new ColumnModel(colonnes);EditorGrid<UniteRangement> grilleUniteRangement = new EditorGrid<UniteRangement>(storeGrille, modeleDeColonnes);grilleUniteRangement.setHeight(300);grilleUniteRangement.setBorders(true);grilleUniteRangement.setSelectionModel(modeleDeSelection);grilleUniteRangement.getView().setForceFit(true);grilleUniteRangement.getView().setAutoFill(true);grilleUniteRangement.setAutoExpandColumn("type");grilleUniteRangement.setStripeRows(true);grilleUniteRangement.setTrackMouseOver(true);return grilleUniteRangement;}private ToolBar creerBarreOutilsGrilleUniteRangement() {ToolBar barreOutils = new ToolBar();Button ajouterBouton = creerBoutonAjouterUniteRangement();barreOutils.add(ajouterBouton);barreOutils.add(new SeparatorToolItem());Button supprimerBouton = creerBoutonSupprimerUniteRangement();barreOutils.add(supprimerBouton);return barreOutils;}private Button creerBoutonAjouterUniteRangement() {Button bouton = new Button(i18nC.ajouter());bouton.setIcon(Images.ICONES.ajouter());bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {final MessageBox box = MessageBox.prompt(i18nC.collectionUniteType(), i18nC.collectionUniteRangementSaisirType());box.addCallback(new Listener<MessageBoxEvent>() {public void handleEvent(MessageBoxEvent be) {final UniteRangement unite = new UniteRangement();unite.setType(be.getValue());unite.setTypeAutre(true);uniteRangementGrille.getStore().add(unite);}});}});return bouton;}private Button creerBoutonSupprimerUniteRangement() {Button bouton = new Button(i18nC.supprimer());bouton.setIcon(Images.ICONES.supprimer());bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {UniteRangement uniteRangementSelectionnee = uniteRangementGrille.getSelectionModel().getSelectedItem();if (uniteRangementSelectionnee == null) {Info.display(i18nC.informationTitreGenerique(), Mediateur.i18nM.veuillezSelectionner(i18nC.selectionnerUniteRangement()));} else if (uniteRangementSelectionnee.getTypeAutre() == false) {Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerUniteRangementAjoute());} else {uniteRangementGrille.getStore().remove(uniteRangementSelectionnee);}}});return bouton;}private void creerUniteBase() {ContentPanel panneauGrille = creerPanneauContenantGrille(i18nC.collectionUniteBaseTitre());uniteBaseGrille = creerGrilleUniteBase();mediateur.obtenirListeValeurEtRafraichir(this, "typeUniteBase");panneauGrille.add(uniteBaseGrille);ToolBar barreOutils = creerBarreOutilsGrilleUniteBase();panneauGrille.setTopComponent(barreOutils);add(panneauGrille);}private Grid<UniteBase> creerGrilleUniteBase() {ListStore<UniteBase> storeGrille = new ListStore<UniteBase>();List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();colonnes.add(new ColumnConfig("type", i18nC.collectionUniteType(), 150));NumberField champNombre = new NumberField();champNombre.setFormat(NumberFormat.getFormat("#"));CellEditor editeurNombre = new CellEditor(champNombre);ColumnConfig nombreColonne = new ColumnConfig("nombre", i18nC.collectionUniteNbre(), 50);nombreColonne.setEditor(editeurNombre);colonnes.add(nombreColonne);ListStore<InterneValeur> precisionStore = new ListStore<InterneValeur>();precisionStore.add(new InterneValeur(UniteRangement.COMPTE_APPROXIMATIF, i18nC.precisionApproximatif()));precisionStore.add(new InterneValeur(UniteRangement.COMPTE_EXACT, i18nC.precisionExact()));final ComboBox<InterneValeur> precisionCombo = new ComboBox<InterneValeur>();precisionCombo.setForceSelection(true);precisionCombo.setTriggerAction(TriggerAction.ALL);precisionCombo.setDisplayField("nom");precisionCombo.setStore(precisionStore);precisionCombo.setEditable(false);CellEditor editeurPrecision = new CellEditor(precisionCombo) {@Overridepublic Object preProcessValue(Object valeur) {InterneValeur retour = null;if (valeur != null ) {if (precisionCombo.getStore().findModel("nom", valeur.toString()) != null) {retour = precisionCombo.getStore().findModel("nom", valeur.toString());} else if (precisionCombo.getStore().findModel("abr", valeur.toString()) != null) {retour = precisionCombo.getStore().findModel("abr", valeur.toString());}}return retour;}@Overridepublic Object postProcessValue(Object valeur) {String retour = null;if (valeur != null ) {if (valeur instanceof InterneValeur) {InterneValeur valeurInterne = (InterneValeur) valeur;retour = valeurInterne.getNom();}}return retour;}};ColumnConfig precisionColonne = new ColumnConfig("precision", i18nC.collectionUnitePrecision(), 50);precisionColonne.setEditor(editeurPrecision);colonnes.add(precisionColonne);TextField<String> formatChp = new TextField<String>();formatChp.setAllowBlank(false);ColumnConfig formatColonne = new ColumnConfig("format", i18nC.collectionUniteFormat(), 100);formatColonne.setEditor(new CellEditor(formatChp));colonnes.add(formatColonne);ColumnConfig partNombreColonne = new ColumnConfig("nombre_part", i18nC.collectionUniteNbre(), 50);partNombreColonne.setEditor(editeurNombre);colonnes.add(partNombreColonne);ColumnConfig partPrecisionColonne = new ColumnConfig("precision_part", i18nC.collectionUnitePrecision(), 50);partPrecisionColonne.setEditor(editeurPrecision);colonnes.add(partPrecisionColonne);ColumnConfig spNombreColonne = new ColumnConfig("nombre_sp", i18nC.collectionUniteNbre(), 50);spNombreColonne.setEditor(editeurNombre);colonnes.add(spNombreColonne);ColumnConfig spPrecisionColonne = new ColumnConfig("precision_sp", i18nC.collectionUnitePrecision(), 50);spPrecisionColonne.setEditor(editeurPrecision);colonnes.add(spPrecisionColonne);GridSelectionModel<UniteBase> modeleDeSelection = new GridSelectionModel<UniteBase>();ColumnModel modeleDeColonnes = new ColumnModel(colonnes);modeleDeColonnes.addHeaderGroup(0, 0, new HeaderGroupConfig(i18nC.collectionUniteBase(), 1, 4));modeleDeColonnes.addHeaderGroup(0, 4, new HeaderGroupConfig(i18nC.collectionUniteBasePart(), 1, 2));modeleDeColonnes.addHeaderGroup(0, 6, new HeaderGroupConfig(i18nC.collectionUniteBaseSp(), 1, 2));AggregationRowConfig<UniteBase> total = new AggregationRowConfig<UniteBase>();total.setHtml("type", "TOTAL");total.setSummaryType("nombre", SummaryType.SUM);total.setSummaryFormat("nombre", NumberFormat.getFormat("#"));total.setSummaryType("nombre_part", SummaryType.SUM);total.setSummaryFormat("nombre_part", NumberFormat.getFormat("#"));total.setSummaryType("nombre_sp", SummaryType.SUM);total.setSummaryFormat("nombre_sp", NumberFormat.getFormat("#"));modeleDeColonnes.addAggregationRow(total);EditorGrid<UniteBase> grilleUniteBase = new EditorGrid<UniteBase>(storeGrille, modeleDeColonnes);grilleUniteBase.setHeight(200);grilleUniteBase.setBorders(true);grilleUniteBase.setSelectionModel(modeleDeSelection);grilleUniteBase.getView().setForceFit(true);grilleUniteBase.getView().setAutoFill(true);grilleUniteBase.setAutoExpandColumn("type");grilleUniteBase.setStripeRows(true);grilleUniteBase.setTrackMouseOver(true);return grilleUniteBase;}private ToolBar creerBarreOutilsGrilleUniteBase() {ToolBar barreOutils = new ToolBar();Button ajouterBouton = creerBoutonAjouterUniteBase();barreOutils.add(ajouterBouton);barreOutils.add(new SeparatorToolItem());Button supprimerBouton = creerBoutonSupprimerUniteBase();barreOutils.add(supprimerBouton);return barreOutils;}private Button creerBoutonAjouterUniteBase() {Button bouton = new Button(i18nC.ajouter());bouton.setIcon(Images.ICONES.ajouter());bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {final MessageBox box = MessageBox.prompt(i18nC.collectionUniteType(), i18nC.collectionUniteBaseSaisirType());box.addCallback(new Listener<MessageBoxEvent>() {public void handleEvent(MessageBoxEvent be) {final UniteBase unite = new UniteBase();unite.setType(be.getValue());unite.setTypeAutre(true);uniteBaseGrille.getStore().add(unite);}});}});return bouton;}private Button creerBoutonSupprimerUniteBase() {Button bouton = new Button(i18nC.supprimer());bouton.setIcon(Images.ICONES.supprimer());bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {UniteBase uniteBaseSelectionnee = uniteBaseGrille.getSelectionModel().getSelectedItem();if (uniteBaseSelectionnee == null) {Info.display(i18nC.informationTitreGenerique(), Mediateur.i18nM.veuillezSelectionner(i18nC.selectionnerUniteBase()));} else if (uniteBaseSelectionnee.getTypeAutre() == false) {Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerUniteBaseAjoute());} else {uniteBaseGrille.getStore().remove(uniteBaseSelectionnee);}}});return bouton;}public void rafraichir(Object nouvellesDonnees) {if (nouvellesDonnees instanceof ValeurListe) {ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;rafraichirValeurListe(listeValeurs);} else {GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);}}private void rafraichirValeurListe(ValeurListe listeValeurs) {if (listeValeurs.getId().equals(config.getListeId("typeCollectionBota"))) {Formulaire.rafraichirComboBox(listeValeurs, typesCollectionBotaCombo);} else if (listeValeurs.getId().equals(config.getListeId("typeUniteRangement"))) {Iterator<String> it = listeValeurs.keySet().iterator();while (it.hasNext()) {Valeur valeur = listeValeurs.get(it.next());UniteRangement unite = new UniteRangement();unite.setType(valeur.getNom());unite.setTypeAutre(false);uniteRangementGrille.getStore().add(unite);}} else if (listeValeurs.getId().equals(config.getListeId("typeUniteBase"))) {Iterator<String> it = listeValeurs.keySet().iterator();while (it.hasNext()) {Valeur valeur = listeValeurs.get(it.next());UniteBase unite = new UniteBase();unite.setType(valeur.getNom());unite.setTypeAutre(false);uniteBaseGrille.getStore().add(unite);}} else {GWT.log("Gestion de la liste "+listeValeurs.getId()+" non implémenté!", null);}}}