branch develop updated (a8f583b -> c63afb1)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See http://git.codelutin.com/tutti.git from a8f583b Merge branch 'develop' of https://git.codelutin.com/tutti into develop new c63afb1 fixes #6124 [CAPTURE] erreur sur écran mensuration 3.7.8 The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit c63afb12131459f7cb1048dd992c0dbeb3832c31 Author: Kevin Morin <morin@codelutin.com> Date: Fri Nov 28 18:18:55 2014 +0100 fixes #6124 [CAPTURE] erreur sur écran mensuration 3.7.8 Summary of changes: .../frequency/BenthosFrequencyUIHandler.java | 40 ++++++++++++++++---- .../benthos/frequency/BenthosFrequencyUIModel.java | 44 ++++++++++++++++++++++ .../frequency/SpeciesFrequencyUIHandler.java | 42 +++++++++++++++++---- .../species/frequency/SpeciesFrequencyUIModel.java | 44 ++++++++++++++++++++++ 4 files changed, 156 insertions(+), 14 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit c63afb12131459f7cb1048dd992c0dbeb3832c31 Author: Kevin Morin <morin@codelutin.com> Date: Fri Nov 28 18:18:55 2014 +0100 fixes #6124 [CAPTURE] erreur sur écran mensuration 3.7.8 --- .../frequency/BenthosFrequencyUIHandler.java | 40 ++++++++++++++++---- .../benthos/frequency/BenthosFrequencyUIModel.java | 44 ++++++++++++++++++++++ .../frequency/SpeciesFrequencyUIHandler.java | 42 +++++++++++++++++---- .../species/frequency/SpeciesFrequencyUIModel.java | 44 ++++++++++++++++++++++ 4 files changed, 156 insertions(+), 14 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java index f309781..7ccff5e 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIHandler.java @@ -123,11 +123,15 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth @Override protected boolean isRowValid(BenthosFrequencyRowModel row) { + Float lengthStep = row.getLengthStep(); + BenthosFrequencyUIModel model = getModel(); + return row.getLengthStepCaracteristic() != null && - row.getLengthStep() != null && row.getLengthStep() > 0 && - ((row.getNumber() == null && row.getWeight() == null) || - (row.getNumber() != null && row.getNumber() > 0 && - (getModel().getNbRowsWithWeight() == 0 || row.getWeight() != null && row.getWeight() > 0))); + lengthStep != null && lengthStep > 0 && + model.numberOfRows(lengthStep) == 1 && + ((row.getNumber() == null && row.getWeight() == null) || + (row.getNumber() != null && row.getNumber() > 0 && + (model.getNbRowsWithWeight() == 0 || row.getWeight() != null && row.getWeight() > 0))); } @Override @@ -136,6 +140,7 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth BenthosFrequencyUIModel model = getModel(); model.setEmptyRows(Sets.<BenthosFrequencyRowModel>newHashSet()); + model.resetNumbersOfRows(); if (CollectionUtils.isNotEmpty(rows)) { XYSeries series = dataset.getSeries(0); @@ -146,12 +151,17 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth Float lengthStep = row.getLengthStep(); if (lengthStep != null) { - series.add(lengthStep, row.getNumber()); + model.incNumberOfRows(lengthStep); } } for (BenthosFrequencyRowModel row : rows) { recomputeRowValidState(row); + + if (row.isValid()) { + Float lengthStep = row.getLengthStep(); + series.addOrUpdate(lengthStep, row.getNumber()); + } } } model.recomputeTotalNumberAndWeight(); @@ -172,9 +182,24 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth // update rowWithWeight cache model.updateRowWithWeight(row); + boolean lengthStepModified = BenthosFrequencyRowModel.PROPERTY_LENGTH_STEP.equals(propertyName); + + if (lengthStepModified) { + Float lengthStepToDec = (Float) oldValue; + if (lengthStepToDec != null) { + model.decNumberOfRows(lengthStepToDec); + } + + Float lengthStepToInc = (Float) newValue; + if (lengthStepToInc != null) { + model.incNumberOfRows(lengthStepToInc); + } + } + // check if no row had a weight, then if one of them now has a weight, // the other ones must have one too to be valid - boolean recomputeAllRows = nbRowsWithWeight != model.getNbRowsWithWeight(); + // if the lengthstep changed, then recompute to check that there is not twice the same + boolean recomputeAllRows = nbRowsWithWeight != model.getNbRowsWithWeight() || lengthStepModified; if (recomputeAllRows) { if (log.isInfoEnabled()) { @@ -183,6 +208,7 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth for (BenthosFrequencyRowModel r : model.getRows()) { recomputeRowValidState(r); } + getTable().repaint(); } model.recomputeTotalNumberAndWeight(); @@ -371,7 +397,7 @@ public class BenthosFrequencyUIHandler extends AbstractTuttiTableUIHandler<Benth if (BenthosFrequencyRowModel.PROPERTY_LENGTH_STEP.equals(evt.getPropertyName())) { Float oldValue = (Float) evt.getOldValue(); - if (oldValue != null) { + if (oldValue != null && series.indexOf(oldValue) >= 0) { series.remove(oldValue); } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIModel.java index 06702a4..9f0f219 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/frequency/BenthosFrequencyUIModel.java @@ -22,6 +22,7 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency; * #L% */ +import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; @@ -32,7 +33,10 @@ import fr.ifremer.tutti.ui.swing.util.computable.ComputableData; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.mutable.MutableInt; +import java.util.HashMap; +import java.util.Map; import java.util.Set; /** @@ -170,6 +174,13 @@ public class BenthosFrequencyUIModel extends AbstractTuttiTableUIModel<BenthosBa */ protected Set<BenthosFrequencyRowModel> withWeightRows = Sets.newHashSet(); + /** + * Number of rows for each lengthstep + * + * @since 3.10 + */ + protected Map<Float, MutableInt> nbOfRowsByLengthStep = new HashMap<Float, MutableInt>(); + public BenthosFrequencyUIModel(WeightUnit weightUnit, SampleCategoryModel sampleCategoryModel) { super(BenthosBatchRowModel.class, null, null); @@ -459,4 +470,37 @@ public class BenthosFrequencyUIModel extends AbstractTuttiTableUIModel<BenthosBa setTotalNumber(totalNumber); setTotalComputedWeight(totalWeight); } + + public int numberOfRows(float lengthStep) { + int result = 0; + MutableInt mutableInt = nbOfRowsByLengthStep.get(lengthStep); + if (mutableInt != null) { + result = mutableInt.intValue(); + } + return result; + } + + public void resetNumbersOfRows() { + nbOfRowsByLengthStep = new HashMap<Float, MutableInt>(); + } + + public int incNumberOfRows(float lengthStep) { + MutableInt mutableInt = nbOfRowsByLengthStep.get(lengthStep); + if (mutableInt == null) { + mutableInt = new MutableInt(1); + nbOfRowsByLengthStep.put(lengthStep, mutableInt); + + } else { + mutableInt.increment(); + } + return mutableInt.intValue(); + } + + public int decNumberOfRows(float lengthStep) { + MutableInt mutableInt = nbOfRowsByLengthStep.get(lengthStep); + Preconditions.checkNotNull(mutableInt); + Preconditions.checkArgument(mutableInt.intValue() > 0); + mutableInt.decrement(); + return mutableInt.intValue(); + } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java index ab0d1d3..f89c78d 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java @@ -22,6 +22,8 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; * #L% */ +import com.google.common.base.Predicate; +import com.google.common.collect.Collections2; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -161,11 +163,15 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci @Override protected boolean isRowValid(SpeciesFrequencyRowModel row) { + Float lengthStep = row.getLengthStep(); + SpeciesFrequencyUIModel model = getModel(); + return row.getLengthStepCaracteristic() != null && - row.getLengthStep() != null && row.getLengthStep() > 0 && - ((row.getNumber() == null && row.getWeight() == null) || - (row.getNumber() != null && row.getNumber() > 0 && - (getModel().getNbRowsWithWeight() == 0 || row.getWeight() != null && row.getWeight() > 0))); + lengthStep != null && lengthStep > 0 && + model.numberOfRows(lengthStep) == 1 && + ((row.getNumber() == null && row.getWeight() == null) || + (row.getNumber() != null && row.getNumber() > 0 && + (model.getNbRowsWithWeight() == 0 || row.getWeight() != null && row.getWeight() > 0))); } @Override @@ -174,6 +180,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci SpeciesFrequencyUIModel model = getModel(); model.setEmptyRows(Sets.<SpeciesFrequencyRowModel>newHashSet()); + model.resetNumbersOfRows(); if (CollectionUtils.isNotEmpty(rows)) { XYSeries series = dataset.getSeries(0); @@ -184,12 +191,17 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci Float lengthStep = row.getLengthStep(); if (lengthStep != null) { - series.add(lengthStep, row.getNumber()); + model.incNumberOfRows(lengthStep); } } for (SpeciesFrequencyRowModel row : rows) { recomputeRowValidState(row); + + if (row.isValid()) { + Float lengthStep = row.getLengthStep(); + series.addOrUpdate(lengthStep, row.getNumber()); + } } } model.recomputeTotalNumberAndWeight(); @@ -210,9 +222,24 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci // update rowWithWeight cache model.updateRowWithWeight(row); + boolean lengthStepModified = SpeciesFrequencyRowModel.PROPERTY_LENGTH_STEP.equals(propertyName); + + if (lengthStepModified) { + Float lengthStepToDec = (Float) oldValue; + if (lengthStepToDec != null) { + model.decNumberOfRows(lengthStepToDec); + } + + Float lengthStepToInc = (Float) newValue; + if (lengthStepToInc != null) { + model.incNumberOfRows(lengthStepToInc); + } + } + // check if no row had a weight, then if one of them now has a weight, // the other ones must have one too to be valid - boolean recomputeAllRows = nbRowsWithWeight != model.getNbRowsWithWeight(); + // if the lengthstep changed, then recompute to check that there is not twice the same + boolean recomputeAllRows = nbRowsWithWeight != model.getNbRowsWithWeight() || lengthStepModified; if (recomputeAllRows) { if (log.isInfoEnabled()) { @@ -221,6 +248,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci for (SpeciesFrequencyRowModel r : model.getRows()) { recomputeRowValidState(r); } + getTable().repaint(); } model.recomputeTotalNumberAndWeight(); @@ -436,7 +464,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci if (SpeciesFrequencyRowModel.PROPERTY_LENGTH_STEP.equals(evt.getPropertyName())) { Float oldValue = (Float) evt.getOldValue(); - if (oldValue != null) { + if (oldValue != null && series.indexOf(oldValue) >= 0) { series.remove(oldValue); } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java index dc36c0f..969b816 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java @@ -22,6 +22,7 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; * #L% */ +import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; @@ -32,7 +33,10 @@ import fr.ifremer.tutti.ui.swing.util.computable.ComputableData; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableUIModel; import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.mutable.MutableInt; +import java.util.HashMap; +import java.util.Map; import java.util.Set; /** @@ -170,6 +174,13 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa */ protected Set<SpeciesFrequencyRowModel> withWeightRows = Sets.newHashSet(); + /** + * Number of rows for each lengthstep + * + * @since 3.10 + */ + protected Map<Float, MutableInt> nbOfRowsByLengthStep = new HashMap<Float, MutableInt>(); + public SpeciesFrequencyUIModel(WeightUnit weightUnit, SampleCategoryModel sampleCategoryModel) { super(SpeciesBatchRowModel.class, null, null); @@ -467,4 +478,37 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa setTotalNumber(totalNumber); setTotalComputedWeight(totalWeight); } + + public int numberOfRows(float lengthStep) { + int result = 0; + MutableInt mutableInt = nbOfRowsByLengthStep.get(lengthStep); + if (mutableInt != null) { + result = mutableInt.intValue(); + } + return result; + } + + public void resetNumbersOfRows() { + nbOfRowsByLengthStep = new HashMap<Float, MutableInt>(); + } + + public int incNumberOfRows(float lengthStep) { + MutableInt mutableInt = nbOfRowsByLengthStep.get(lengthStep); + if (mutableInt == null) { + mutableInt = new MutableInt(1); + nbOfRowsByLengthStep.put(lengthStep, mutableInt); + + } else { + mutableInt.increment(); + } + return mutableInt.intValue(); + } + + public int decNumberOfRows(float lengthStep) { + MutableInt mutableInt = nbOfRowsByLengthStep.get(lengthStep); + Preconditions.checkNotNull(mutableInt); + Preconditions.checkArgument(mutableInt.intValue() > 0); + mutableInt.decrement(); + return mutableInt.intValue(); + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm