This is an automated email from the git hooks/post-receive script. New commit to branch feature/8146 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 189803cbc4c3b131a3739ee9125ee5e91761ff4d Author: Kevin Morin <morin@codelutin.com> Date: Fri Mar 25 16:38:58 2016 +0100 l'arrondi du poids rendait le poids négatif positif... d'où le poids total qui ne faisait qu'augmenter (fixes #8146) --- .../main/java/fr/ifremer/tutti/util/Weights.java | 4 +++ .../frequency/SpeciesFrequencyRowModel.java | 23 +++++++++++++--- .../frequency/SpeciesFrequencyTableModel.java | 31 +++++++++++----------- .../frequency/SpeciesFrequencyUIHandler.java | 30 ++++++++++++++------- 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java index a239e63..c9ddfb8 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java @@ -112,6 +112,10 @@ public class Weights { return compareWeights(v0, v1) > 0; } + public static boolean isPositive(float weight) { + return compareRawWeights(weight, 0.0f) >= 0; + } + public static boolean isEqualWeight(float v0, float v1) { return compareWeights(v0, v1) == 0; } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java index fed3d13..cf3d7d1 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java @@ -235,15 +235,32 @@ public class SpeciesFrequencyRowModel extends AbstractTuttiBeanUIModel<SpeciesBa } /** - * @param weightToAdd weight (can be negative) to add + * @param weightToAdd weight (cannot be negative) to add */ public void addToWeight(float weightToAdd) { + if (!Weights.isPositive(weightToAdd)) { + throw new IllegalArgumentException("you must add a positive weight"); + } + if (weight == null) { + weight = 0f; + } + setWeight(weightUnit.round(weight + weightToAdd)); + } + + /** + * @param weightToRemove weight (cannot be negative) to remove + */ + public void removeFromWeight(float weightToRemove) { + if (!Weights.isPositive(weightToRemove)) { + throw new IllegalArgumentException("you must remove a positive weight"); + } if (weight == null) { weight = 0f; } - if (weight + weightToAdd >= 0) { - setWeight(weight + weightToAdd); + if (Weights.isSmallerWeight(weight, weightToRemove)) { + throw new IllegalArgumentException("the weight to remove cannot be greater than the weight"); } + setWeight(weightUnit.round(weight - weightToRemove)); } public Float getRtpComputedWeight() { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java index 648e072..f0b3199 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java @@ -266,12 +266,8 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp if (oldValue != null) { modelCache.removeLengthStep(oldValue); - if (frequenciesSeries.indexOf(oldValue) >= 0) { - frequenciesSeries.remove(oldValue); - } - if (averageWeightsSeries.indexOf(oldValue) >= 0) { - averageWeightsSeries.remove(oldValue); - } + removeLengthStepFromSeries(frequenciesSeries, oldValue); + removeLengthStepFromSeries(averageWeightsSeries, oldValue); } @@ -323,13 +319,8 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp if (!row.withNumber()) { // remove the value for the lengthStep - if (frequenciesSeries.indexOf(lengthStep) >= 0) { - frequenciesSeries.remove(lengthStep); - } - - if (averageWeightsSeries.indexOf(lengthStep) >= 0) { - averageWeightsSeries.remove(lengthStep); - } + removeLengthStepFromSeries(frequenciesSeries, lengthStep); + removeLengthStepFromSeries(averageWeightsSeries, lengthStep); } else { @@ -372,9 +363,7 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp if (!row.withWeight()) { // remove the value for the lengthStep - if (averageWeightsSeries.indexOf(lengthStep) >= 0) { - averageWeightsSeries.remove(lengthStep); - } + removeLengthStepFromSeries(averageWeightsSeries, lengthStep); } else { @@ -397,6 +386,16 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp return onWeightChangedListener; } + private void removeLengthStepFromSeries(XYSeries series, Float lengthStep) { + if (series.indexOf(lengthStep) >= 0) { + if (series.getItemCount() > 1) { + series.remove(lengthStep); + } else { + series.clear(); + } + } + } + private void dettachListeners(SpeciesFrequencyRowModel result) { result.removePropertyChangeListener(SpeciesFrequencyRowModel.PROPERTY_LENGTH_STEP, getOnLengthStepChangedListener()); 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 02a042f..69a5333 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 @@ -43,13 +43,17 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.service.sampling.SamplingCodePrefix; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchTableModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.SamplingCodeCellEditor; import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.SamplingCodeCellRenderer; +import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.SamplingCodeCellEditor; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.EditSpeciesBatchPanelUI; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesOrBenthosBatchUISupport; +import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchRowModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchTableModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.EditSpeciesBatchPanelUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesOrBenthosBatchUISupport; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.edit.SpeciesBatchRowModel; @@ -95,7 +99,6 @@ import org.nuiton.decorator.Decorator; import org.nuiton.jaxx.application.ApplicationBusinessException; import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; -import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; @@ -1019,8 +1022,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci } - if (log.isInfoEnabled()) { - log.info("CopyIndividualObservationMode: " + copyIndividualObservationMode); + if (log.isDebugEnabled()) { + log.debug("copy individual observation mode : " + copyIndividualObservationMode); } SpeciesBatchRowModel previousSiblingRow = frequencyEditor.getPreviousSiblingRow(); @@ -1116,6 +1119,9 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci model.computeRowWeightWithRtp(); + model.recomputeIndividualObservationRowsValidateState(); + model.recomputeRowsValidateState(); + if (getContext().isIchtyometerConnected()) { // let's listen the ichtyometer @@ -1205,9 +1211,15 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci lengthStep = getModel().getLengthStep(lengthStep); SpeciesFrequencyRowModel row = getRowForLengthstep(lengthStep); + + boolean addToWeight = Weights.isPositive(weight); // conversion de poids - weight = Weights.convert(getConfig().getIndividualObservationWeightUnit(), weightUnit, weight); - row.addToWeight(weight); + weight = Math.abs(Weights.convert(getConfig().getIndividualObservationWeightUnit(), weightUnit, weight)); + if (addToWeight) { + row.addToWeight(weight); + } else { + row.removeFromWeight(weight); + } if (Weights.isNullOrZero(row.getWeight())) { int rowIndex = tableModel.getRowIndex(row); @@ -1852,7 +1864,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci Float weight = obsRow.getWeight(); if (CopyIndividualObservationMode.ALL == copyMode && weight != null) { // conversion de poids - weight = Weights.convert(individualObservationWeightUnit, weightUnit, weight); + weight = weightUnit.convertWeight(weight, individualObservationWeightUnit); row.addToWeight(weight); } } @@ -1885,8 +1897,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci protected void beforeOpenPopup(int modelRowIndex, int modelColumnIndex) { super.beforeOpenPopup(modelRowIndex, modelColumnIndex); - boolean sampleCodeMenusEnabled = modelRowIndex >= 0 && ui.getObsTable().getSelectedRowCount() == 1 - && getObsTableModel().getRows().get(ui.getObsTable().getSelectedRow()).withSamplingCode(); + boolean sampleCodeMenusEnabled = modelRowIndex >= 1 && ui.getObsTable().getSelectedRowCount() == 1 + && getObsTableModel().getRows().get(ui.getObsTable().getSelectedRow()).withSamplingCodeId(); ui.getEditSampleCodeMenu().setEnabled(sampleCodeMenusEnabled); ui.getDeleteSampleCodeMenu().setEnabled(sampleCodeMenusEnabled); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.