Author: tchemit Date: 2013-12-17 19:48:51 +0100 (Tue, 17 Dec 2013) New Revision: 1468 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1468 Log: fixes #4040: [CAPTURES] Mauvaise d?\195?\169coration de la cat?\195?\169gorisation Age fixes #4041: [CAPTURES] Mauvaise s?\195?\169lection de la premi?\195?\168re cat?\195?\169gorisation fixes #4042: [CAPTURES] Impossible d'ouvrir le menu contextuel sur une cat?\195?\169gorisation de type num?\195?\169rique fixes #3980: [CAPTURES] appliquer le meme comportement au clic droit + cat?\195?\169goriser le lot que ?\195?\160 la cr?\195?\169ation du lot Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-12-17 16:25:15 UTC (rev 1467) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-12-17 18:48:51 UTC (rev 1468) @@ -128,6 +128,14 @@ return bean == null ? "" : String.valueOf(bean); } }); + registerDecorator(new Decorator<Number>(Number.class) { + private static final long serialVersionUID = 1L; + + @Override + public String toString(Object bean) { + return bean == null ? "" : String.valueOf(bean); + } + }); registerDecorator(new VesselDecorator()); registerDecorator(new ProgramDecorator()); registerTuttiDecorator(Program.class, ONLY_NAME, "${name}$s", SEPARATOR, " - "); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java 2013-12-17 16:25:15 UTC (rev 1467) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java 2013-12-17 18:48:51 UTC (rev 1468) @@ -31,6 +31,8 @@ import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; +import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; @@ -453,7 +455,7 @@ TuttiProtocol protocol = service.getProtocol(); if (protocol != null) { if (log.isInfoEnabled()) { - log.info("Remove protocol: "+protocol); + log.info("Remove protocol: " + protocol); } service.setProtocol(null); } @@ -506,32 +508,110 @@ log.info("Loading lengthStepCaracteristics"); } lengthStepCaracteristics = service.getLengthStepCaracteristics(getCaracteristics()); - -// if (isProtocolFilled()) { -// -// // get loaded protocol -// protocol = getProtocol(); -// lengthStepCaracteristics = Lists.newArrayListWithCapacity( -// protocol.sizeLengthClassesPmfmId()); -// -// Map<String, Caracteristic> allCaractericsById = -// TuttiEntities.splitById(getCaracteristics()); -// -// if (!protocol.isLengthClassesPmfmIdEmpty()) { -// for (String id : protocol.getLengthClassesPmfmId()) { -// lengthStepCaracteristics.add(allCaractericsById.get(id)); -// } -// } -// } else { -// lengthStepCaracteristics = Lists.newArrayList( -// getCaracteristics()); -// } -// -// lengthStepCaracteristics = Collections.unmodifiableList(lengthStepCaracteristics); } return lengthStepCaracteristics; } + /** + * Get the best possible first sample category for the given benthos. + * <p/> + * Will look inside the protocol if there is a row for the given benthos, + * if so try then to use the first selected sample category. + * <p/> + * If selected category is null, then try to use the first one from the + * given categories. + * + * @param categories list of possible categories + * @param species species to use + * @return the best first sample category to use for the given benthos + * @since 3.0 + */ + public SampleCategoryModelEntry getBestFirstBenthosSampleCategory(List<SampleCategoryModelEntry> categories, + Species species) { + + + SpeciesProtocol speciesProtocol = null; + + if (isProtocolFilled()) { + + speciesProtocol = service.getBenthosProtocol(species); + } + + SampleCategoryModelEntry selectedCategory = getBestFirstSampleCategory(categories, speciesProtocol); + + return selectedCategory; + } + + /** + * Get the best possible first sample category for the given species. + * <p/> + * Will look inside the protocol if there is a row for the given species, + * if so try then to use the first selected sample category. + * <p/> + * If selected category is null, then try to use the first one from the + * given categories. + * + * @param categories list of possible categories + * @param species species to use + * @return the best first sample category to use for the given species + * @since 3.0 + */ + public SampleCategoryModelEntry getBestFirstSpeciesSampleCategory(List<SampleCategoryModelEntry> categories, + Species species) { + + SpeciesProtocol speciesProtocol = null; + + if (isProtocolFilled()) { + + speciesProtocol = service.getSpeciesProtocol(species); + } + + SampleCategoryModelEntry selectedCategory = getBestFirstSampleCategory(categories, speciesProtocol); + + return selectedCategory; + } + + protected SampleCategoryModelEntry getBestFirstSampleCategory(List<SampleCategoryModelEntry> categories, + SpeciesProtocol speciesProtocol) { + + SampleCategoryModelEntry selectedCategory = null; + + if (speciesProtocol != null) { + + if (!speciesProtocol.isMandatorySampleCategoryIdEmpty()) { + + // use the first category + Integer categoryId = speciesProtocol.getMandatorySampleCategoryId().get(0); + selectedCategory = sampleCategoryModel.getCategoryById(categoryId); + + if (categories.contains(selectedCategory)) { + + // ok can use this category + if (log.isInfoEnabled()) { + log.info("Use first category from protocol: " + categoryId + " :: " + selectedCategory); + } + } else { + + // can't use this category, not in universe + selectedCategory = null; + } + } + } + + if (selectedCategory == null) { + + // by default use the first one + if (!categories.isEmpty()) { + selectedCategory = categories.get(0); + + if (log.isInfoEnabled()) { + log.info("Use default first category: " + selectedCategory); + } + } + } + return selectedCategory; + } + public List<CaracteristicQualitativeValue> getGenderValues() { checkOpened(); if (genderValues == null) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-12-17 16:25:15 UTC (rev 1467) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-12-17 18:48:51 UTC (rev 1468) @@ -101,6 +101,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; +import java.util.Collections; import java.util.EnumMap; import java.util.List; import java.util.Set; @@ -523,21 +524,28 @@ // is first category ? firstCategory = sampleCategoryModel.getFirstCategoryId().equals(sampleCategoryId); - // get the first ancestor row using this category - BenthosBatchRowModel firstAncestorRow = row.getFirstAncestor(sampleCategoryId); + if (category.getCaracteristic().isNumericType()) { - // get all used values for this category - Set<Serializable> used = getSampleUsedValues( - firstAncestorRow, sampleCategoryId); + // no category available + available = Collections.emptyList(); + } else { - // get all possible values - available = Lists.newArrayList(category.getCaracteristic().getQualitativeValue()); - available.removeAll(used); + // get the first ancestor row using this category + BenthosBatchRowModel firstAncestorRow = row.getFirstAncestor(sampleCategoryId); - if (firstCategory) { + // get all used values for this category + Set<Serializable> used = getSampleUsedValues( + firstAncestorRow, sampleCategoryId); - // remove the unsorted qualitative value - TuttiEntities.removeQualitativeValue(available, qualitative_unsorted_id); + // get all possible values + available = Lists.newArrayList(category.getCaracteristic().getQualitativeValue()); + available.removeAll(used); + + if (firstCategory) { + + // remove the unsorted qualitative value + TuttiEntities.removeQualitativeValue(available, qualitative_unsorted_id); + } } } @@ -552,15 +560,8 @@ enableChangeSampleCategory = false; } else { - if (category.getCaracteristic().isNumericType()) { - - // if number then can always change it - - } else { - - // action possible only if there is still some available values - enableChangeSampleCategory = CollectionUtils.isNotEmpty(available); - } + // action possible only if there is still some available values + enableChangeSampleCategory = CollectionUtils.isNotEmpty(available); } } @@ -577,15 +578,8 @@ enableAddSampleCategory = false; } else { - if (category.getCaracteristic().isNumericType()) { - - // if number then can always change it - - } else { - - // action possible only if there is still some available values - enableAddSampleCategory = CollectionUtils.isNotEmpty(available); - } + // action possible only if there is still some available values + enableAddSampleCategory = CollectionUtils.isNotEmpty(available); } } @@ -753,6 +747,9 @@ Decorator<CaracteristicQualitativeValue> caracteristicDecorator = getDecorator(CaracteristicQualitativeValue.class, null); + Decorator<Number> numberDecorator = + getDecorator(Number.class, null); + Color computedDataColor = getConfig().getColorComputedWeights(); { // Species column @@ -779,9 +776,12 @@ n_(sampleCategoryDef.getLabel()), n_(sampleCategoryDef.getLabel())); + Decorator<? extends Serializable> decorator = + sampleCategoryDef.getCaracteristic().isNumericType() ? + numberDecorator : caracteristicDecorator; addSampleCategoryColumnToModel(columnModel, columnIdentifier, - caracteristicDecorator, + decorator, defaultRenderer, weightUnit); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIHandler.java 2013-12-17 16:25:15 UTC (rev 1467) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/create/CreateBenthosBatchUIHandler.java 2013-12-17 18:48:51 UTC (rev 1468) @@ -31,7 +31,6 @@ import fr.ifremer.shared.application.type.WeightUnit; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -263,55 +262,58 @@ source.setSampleCategory(newCategory); // reset selected category - if (log.isInfoEnabled()) { - log.info("Remove selected category before changing the categories..."); + if (log.isDebugEnabled()) { + log.debug("Remove selected category before changing the categories..."); } source.setSelectedCategory(null); // compute the selected sample category - SampleCategoryModelEntry selectedCategory = null; + SampleCategoryModelEntry selectedCategory = getDataContext().getBestFirstBenthosSampleCategory( + getUI().getCategoryComboBox().getData(), + newValue + ); - if (getDataContext().isProtocolFilled()) { +// if (getDataContext().isProtocolFilled()) { +// +// // try to find the first category from protocol +//// TuttiProtocol protocol = getDataContext().getProtocol(); +// SpeciesProtocol speciesProtocol = getPersistenceService().getBenthosProtocol(newValue); +// if (speciesProtocol != null) { +// +// // species defined in protocol +// if (speciesProtocol.sizeMandatorySampleCategoryId() > 1) { +// +// // use the second category (the first one is V/HV) +// Integer categoryId = speciesProtocol.getMandatorySampleCategoryId().get(1); +// selectedCategory = sampleCategoryModel.getCategoryById(categoryId); +// if (log.isInfoEnabled()) { +// log.info("Use category from protocol: " + categoryId + " :: " + selectedCategory); +// } +// } +// } +// } +// +// if (selectedCategory == null) { +// +// // by default use the first one +// List<SampleCategoryModelEntry> categories = +// getUI().getCategoryComboBox().getData(); +// if (!categories.isEmpty()) { +// selectedCategory = categories.get(0); +// +// if (log.isInfoEnabled()) { +// log.info("Use default first category: " + selectedCategory); +// } +// } +// } - // try to find the first category from protocol -// TuttiProtocol protocol = getDataContext().getProtocol(); - SpeciesProtocol speciesProtocol = getPersistenceService().getBenthosProtocol(newValue); - if (speciesProtocol != null) { - - // species defined in protocol - if (speciesProtocol.sizeMandatorySampleCategoryId() > 1) { - - // use the second category (the first one is V/HV) - Integer categoryId = speciesProtocol.getMandatorySampleCategoryId().get(1); - selectedCategory = sampleCategoryModel.getCategoryById(categoryId); - if (log.isInfoEnabled()) { - log.info("Use category from protocol: " + categoryId + " :: " + selectedCategory); - } - } - } + if (log.isDebugEnabled()) { + log.debug("Selected category : " + selectedCategory); } +// // force reset of selected category +// source.setSelectedCategory(null); - if (selectedCategory == null) { - - // by default use the first one - List<SampleCategoryModelEntry> categories = - getUI().getCategoryComboBox().getData(); - if (!categories.isEmpty()) { - selectedCategory = categories.get(0); - - if (log.isInfoEnabled()) { - log.info("Use default first category: " + selectedCategory); - } - } - } - - if (log.isInfoEnabled()) { - log.info("Selected category : " + selectedCategory); - } - // force reset of selected category - source.setSelectedCategory(null); - // set new selected category source.setSelectedCategory(selectedCategory); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIHandler.java 2013-12-17 16:25:15 UTC (rev 1467) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/split/SplitBenthosBatchUIHandler.java 2013-12-17 18:48:51 UTC (rev 1468) @@ -41,7 +41,6 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUI; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import jaxx.runtime.validator.swing.SwingValidator; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; @@ -264,6 +263,8 @@ // get possible the last used List<SampleCategoryModelEntry> categories = Lists.newArrayList(); + SampleCategoryModelEntry bestSampleCategory = null; + if (batch != null) { // get sample category model @@ -291,6 +292,9 @@ categories.remove(sampleCategory.getCategoryDef()); } } + + bestSampleCategory = getDataContext().getBestFirstBenthosSampleCategory(categories, + batch.getSpecies()); } SplitBenthosBatchUIModel model = getModel(); @@ -300,10 +304,9 @@ model.setSampleWeight(null); model.setCategory(categories); - if (CollectionUtils.isNotEmpty(categories)) { - model.setSelectedCategory(categories.get(0)); - } + model.setSelectedCategory(bestSampleCategory); + // keep batch (will be used to push back editing entry) model.setBatch(batch); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-12-17 16:25:15 UTC (rev 1467) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-12-17 18:48:51 UTC (rev 1468) @@ -100,6 +100,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; +import java.util.Collections; import java.util.EnumMap; import java.util.List; import java.util.Set; @@ -478,21 +479,28 @@ // get category category = sampleCategoryModel.getCategoryById(sampleCategoryId); - // get the first ancestor row using this category - SpeciesBatchRowModel firstAncestorRow = row.getFirstAncestor(sampleCategoryId); + if (category.getCaracteristic().isNumericType()) { - // get all used values for this category - Set<Serializable> used = getSampleUsedValues( - firstAncestorRow, sampleCategoryId); + // no category available + available = Collections.emptyList(); + } else { - // get all possible values - available = Lists.newArrayList(category.getCaracteristic().getQualitativeValue()); - available.removeAll(used); + // get the first ancestor row using this category + SpeciesBatchRowModel firstAncestorRow = row.getFirstAncestor(sampleCategoryId); - if (firstCategory) { + // get all used values for this category + Set<Serializable> used = getSampleUsedValues( + firstAncestorRow, sampleCategoryId); - // remove the unsorted qualitative value - TuttiEntities.removeQualitativeValue(available, qualitative_unsorted_id); + // get all possible values + available = Lists.newArrayList(category.getCaracteristic().getQualitativeValue()); + available.removeAll(used); + + if (firstCategory) { + + // remove the unsorted qualitative value + TuttiEntities.removeQualitativeValue(available, qualitative_unsorted_id); + } } } @@ -507,15 +515,8 @@ enableChangeSampleCategory = false; } else { - if (category.getCaracteristic().isNumericType()) { - - // if number then can always change it - - } else { - - // action possible only if there is still some available values - enableChangeSampleCategory = CollectionUtils.isNotEmpty(available); - } + // action possible only if there is still some available values + enableChangeSampleCategory = CollectionUtils.isNotEmpty(available); } } @@ -532,15 +533,8 @@ enableAddSampleCategory = false; } else { - if (category.getCaracteristic().isNumericType()) { - - // if number then can always change it - - } else { - - // action possible only if there is still some available values - enableAddSampleCategory = CollectionUtils.isNotEmpty(available); - } + // action possible only if there is still some available values + enableAddSampleCategory = CollectionUtils.isNotEmpty(available); } } @@ -708,6 +702,9 @@ Decorator<CaracteristicQualitativeValue> caracteristicDecorator = getDecorator(CaracteristicQualitativeValue.class, null); + Decorator<Number> numberDecorator = + getDecorator(Number.class, null); + Color computedDataColor = getConfig().getColorComputedWeights(); { // Species column @@ -734,9 +731,13 @@ n_(sampleCategoryDef.getLabel()), n_(sampleCategoryDef.getLabel())); + Decorator<? extends Serializable> decorator = + sampleCategoryDef.getCaracteristic().isNumericType() ? + numberDecorator : caracteristicDecorator; + addSampleCategoryColumnToModel(columnModel, columnIdentifier, - caracteristicDecorator, + decorator, defaultRenderer, weightUnit); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java 2013-12-17 16:25:15 UTC (rev 1467) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java 2013-12-17 18:48:51 UTC (rev 1468) @@ -31,7 +31,6 @@ import fr.ifremer.shared.application.type.WeightUnit; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -264,64 +263,67 @@ source.setSampleCategory(newCategory); // reset selected category - if (log.isInfoEnabled()) { - log.info("Remove selected category before changing the categories..."); + if (log.isDebugEnabled()) { + log.debug("Remove selected category before changing the categories..."); } source.setSelectedCategory(null); // compute the selected sample category - SampleCategoryModelEntry selectedCategory = null; + SampleCategoryModelEntry selectedCategory = getDataContext().getBestFirstSpeciesSampleCategory( + getUI().getCategoryComboBox().getData(), + newValue + ); - if (getDataContext().isProtocolFilled()) { +// if (getDataContext().isProtocolFilled()) { +// +// if (log.isInfoEnabled()) { +// log.info("Use protocol to find first category"); +// } +// // try to find the first category from protocol +//// TuttiProtocol protocol = getDataContext().getProtocol(); +// SpeciesProtocol speciesProtocol = getPersistenceService().getSpeciesProtocol(newValue); +// if (speciesProtocol != null) { +// +// if (log.isInfoEnabled()) { +// log.info("Use protocol species to find first category: " + speciesProtocol.getMandatorySampleCategoryId()); +// } +// +// // species defined in protocol +// if (!speciesProtocol.isMandatorySampleCategoryIdEmpty()) { +// +// // use the first category +// Integer categoryId = speciesProtocol.getMandatorySampleCategoryId().get(0); +// +// selectedCategory = sampleCategoryModel.getCategoryById(categoryId); +// if (log.isInfoEnabled()) { +// log.info("Use category from protocol: " + categoryId + " :: " + selectedCategory); +// } +// } +// } +// } +// +// if (selectedCategory == null) { +// +// // by default use the first one +// List<SampleCategoryModelEntry> categories = +// getUI().getCategoryComboBox().getData(); +// +// if (!categories.isEmpty()) { +// selectedCategory = categories.get(0); +// +// if (log.isInfoEnabled()) { +// log.info("Use default first category: " + selectedCategory); +// } +// } +// } - if (log.isInfoEnabled()) { - log.info("Use protocol to find first category"); - } - // try to find the first category from protocol -// TuttiProtocol protocol = getDataContext().getProtocol(); - SpeciesProtocol speciesProtocol = getPersistenceService().getSpeciesProtocol(newValue); - if (speciesProtocol != null) { - - if (log.isInfoEnabled()) { - log.info("Use protocol species to find first category: " + speciesProtocol.getMandatorySampleCategoryId()); - } - - // species defined in protocol - if (!speciesProtocol.isMandatorySampleCategoryIdEmpty()) { - - // use the first category - Integer categoryId = speciesProtocol.getMandatorySampleCategoryId().get(0); - - selectedCategory = sampleCategoryModel.getCategoryById(categoryId); - if (log.isInfoEnabled()) { - log.info("Use category from protocol: " + categoryId + " :: " + selectedCategory); - } - } - } + if (log.isDebugEnabled()) { + log.debug("Selected category : " + selectedCategory); } +// // force reset of selected category +// source.setSelectedCategory(null); - if (selectedCategory == null) { - - // by default use the first one - List<SampleCategoryModelEntry> categories = - getUI().getCategoryComboBox().getData(); - - if (!categories.isEmpty()) { - selectedCategory = categories.get(0); - - if (log.isInfoEnabled()) { - log.info("Use default first category: " + selectedCategory); - } - } - } - - if (log.isInfoEnabled()) { - log.info("Selected category : " + selectedCategory); - } - // force reset of selected category - source.setSelectedCategory(null); - // set new selected category source.setSelectedCategory(selectedCategory); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-12-17 16:25:15 UTC (rev 1467) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-12-17 18:48:51 UTC (rev 1468) @@ -41,7 +41,6 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUI; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIHandler; import jaxx.runtime.validator.swing.SwingValidator; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTable; @@ -264,6 +263,7 @@ // get possible the last used List<SampleCategoryModelEntry> categories = Lists.newArrayList(); + SampleCategoryModelEntry bestSampleCategory = null; if (batch != null) { // get sample category model @@ -291,6 +291,9 @@ categories.remove(sampleCategory.getCategoryDef()); } } + + bestSampleCategory = getDataContext().getBestFirstSpeciesSampleCategory(categories, + batch.getSpecies()); } SplitSpeciesBatchUIModel model = getModel(); @@ -300,9 +303,7 @@ model.setSampleWeight(null); model.setCategory(categories); - if (CollectionUtils.isNotEmpty(categories)) { - model.setSelectedCategory(categories.get(0)); - } + model.setSelectedCategory(bestSampleCategory); // keep batch (will be used to push back editing entry) model.setBatch(batch);