branch develop updated (1c4a770 -> 203236b)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git from 1c4a770 livrable #8231 Merge branch 'feature/8231' into develop new 34abc60 grand nettoyage de printemps + fixes #8232 new 203236b Livrable #8232 Merge branch 'feature/8232' into develop The 2 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 203236b85d731042062d2587a128bc2376329d24 Merge: 1c4a770 34abc60 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 11 18:17:36 2016 +0200 Livrable #8232 Merge branch 'feature/8232' into develop commit 34abc6093784e533b9eb093f03ee33d3ac3d67bd Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 11 18:17:26 2016 +0200 grand nettoyage de printemps + fixes #8232 Summary of changes: .../IndividualObservationBatchTableModel.java | 16 +- .../frequency/SpeciesFrequencyTableModel.java | 167 +++++++++++++++++++++ .../frequency/SpeciesFrequencyUIHandler.java | 129 ++++------------ .../species/frequency/SpeciesFrequencyUIModel.java | 4 + .../frequency/actions/RemoveObservationAction.java | 27 ++-- 5 files changed, 227 insertions(+), 116 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 https://gitlab.nuiton.org/codelutin/tutti.git commit 34abc6093784e533b9eb093f03ee33d3ac3d67bd Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 11 18:17:26 2016 +0200 grand nettoyage de printemps + fixes #8232 --- .../IndividualObservationBatchTableModel.java | 16 +- .../frequency/SpeciesFrequencyTableModel.java | 167 +++++++++++++++++++++ .../frequency/SpeciesFrequencyUIHandler.java | 129 ++++------------ .../species/frequency/SpeciesFrequencyUIModel.java | 4 + .../frequency/actions/RemoveObservationAction.java | 27 ++-- 5 files changed, 227 insertions(+), 116 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchTableModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchTableModel.java index 5b0322e..f7cb8ae 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchTableModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/individualobservation/IndividualObservationBatchTableModel.java @@ -107,7 +107,7 @@ public class IndividualObservationBatchTableModel extends AbstractApplicationTab SpeciesFrequencyUIModel parentModel, TableColumnModelExt columnModel) { super(columnModel, true, false); - this.parentModel=parentModel; + this.parentModel = parentModel; this.weightUnit = weightUnit; // Lorsque la caracteristique de maturité change, on met à jour defaultCaracteristicsMap this.parentModel.addPropertyChangeListener(SpeciesFrequencyUIModel.PROPERTY_MATURITY_CARACTERISTIC, new PropertyChangeListener() { @@ -115,10 +115,10 @@ public class IndividualObservationBatchTableModel extends AbstractApplicationTab public void propertyChange(PropertyChangeEvent evt) { Caracteristic oldValue = (Caracteristic) evt.getOldValue(); Caracteristic newValue = (Caracteristic) evt.getNewValue(); - if (oldValue!=null) { + if (oldValue != null) { defaultCaracteristicsMap.remove(oldValue); } - if (newValue!=null) { + if (newValue != null) { defaultCaracteristicsMap.put(newValue, null); } @@ -231,7 +231,7 @@ public class IndividualObservationBatchTableModel extends AbstractApplicationTab IndividualObservationBatchRowModel result = null; - for (int i = rows.size() - 1 ; i >= 0 ; i--) { + for (int i = rows.size() - 1; i >= 0; i--) { IndividualObservationBatchRowModel row = rows.get(i); // if the row has no data set, then it could be the empty row we are looking for Set<Caracteristic> notNullCaracteristics = defaultCaracteristicsMap.keySet().stream() @@ -250,4 +250,12 @@ public class IndividualObservationBatchTableModel extends AbstractApplicationTab return result; } + public void recomputeRankOrders(int firstRow) { + + for (int i = firstRow; i < getRowCount(); i++) { + getRows().get(i).setRankOrder(i + 1); + } + + } + } 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 f0b3199..faae041 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 @@ -22,9 +22,14 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; * #L% */ +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.data.CopyIndividualObservationMode; import fr.ifremer.tutti.type.WeightUnit; +import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchRowModel; import fr.ifremer.tutti.util.Weights; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.table.TableColumnModelExt; import org.jfree.data.xy.XYSeries; import org.nuiton.jaxx.application.swing.table.AbstractApplicationTableModel; @@ -32,7 +37,10 @@ import org.nuiton.jaxx.application.swing.table.ColumnIdentifier; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.Optional; import static org.nuiton.i18n.I18n.n; @@ -44,6 +52,9 @@ import static org.nuiton.i18n.I18n.n; */ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<SpeciesFrequencyRowModel> { + /** Logger. */ + private static final Log log = LogFactory.getLog(SpeciesFrequencyTableModel.class); + private static final long serialVersionUID = 1L; public static final ColumnIdentifier<SpeciesFrequencyRowModel> LENGTH_STEP = ColumnIdentifier.newId( @@ -411,4 +422,160 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp result.addPropertyChangeListener(SpeciesFrequencyRowModel.PROPERTY_NUMBER, getOnNumberChangedListener()); } + + private void removeRow(SpeciesFrequencyRowModel row) { + + int rowIndex = getRowIndex(row); + removeRow(rowIndex); + uiModel.getRowCache().remove(row.getLengthStep()); + + } + + public SpeciesFrequencyRowModel getOrCreateRowForLengthStep(float lengthstep) { + + // obtenir la classe de taille (en fonction de la précision de la méthode de mensuration) + float realLengthStep = uiModel.getLengthStep(lengthstep); + + Map<Float, SpeciesFrequencyRowModel> rowCache = uiModel.getRowCache(); + + SpeciesFrequencyRowModel row = rowCache.get(realLengthStep); + + if (row == null) { + row = createNewRow(); + row.setLengthStep(realLengthStep); + rowCache.put(realLengthStep, row); + + // get new index + List<Float> steps = Lists.newArrayList(rowCache.keySet()); + steps.add(realLengthStep); + Collections.sort(steps); + + int indexToInsert = steps.indexOf(realLengthStep); + addNewRow(indexToInsert, row); + } + + return row; + + } + + public Optional<SpeciesFrequencyRowModel> getOptionalRowForLengthStep(float lengthstep) { + + // obtenir la classe de taille (en fonction de la précision de la méthode de mensuration) + float realLengthStep = uiModel.getLengthStep(lengthstep); + + Map<Float, SpeciesFrequencyRowModel> rowCache = uiModel.getRowCache(); + + SpeciesFrequencyRowModel row = rowCache.get(realLengthStep); + return Optional.ofNullable(row); + + } + + public void incrementFrequencyRowsNumbers(IndividualObservationBatchRowModel row) { + if (row.withSize()) { + incrementFrequencyRowsNumbers(row.getSize()); + } + } + + public void incrementFrequencyRowsNumbers(float lengthStepToIncrement) { + + if (log.isInfoEnabled()) { + log.info("incrementFrequencyRowsNumbers" + lengthStepToIncrement); + } + + SpeciesFrequencyRowModel row = getOrCreateRowForLengthStep(lengthStepToIncrement); + + row.incNumber(); + updateRow(row); + + } + + public void decrementFrequencyRowsNumbers(IndividualObservationBatchRowModel row) { + if (row.withSize()) { + decrementFrequencyRowsNumbers(row.getSize()); + } + } + + public void decrementFrequencyRowsNumbers(float lengthStepToDecrement) { + + if (log.isInfoEnabled()) { + log.info("decrementFrequencyRowsNumbers " + lengthStepToDecrement); + } + + Optional<SpeciesFrequencyRowModel> optionalRow = getOptionalRowForLengthStep(lengthStepToDecrement); + + if (optionalRow.isPresent()) { + + SpeciesFrequencyRowModel row = optionalRow.get(); + row.decNumber(); + + if (!row.withNumber()) { + + // Plus d'occurrence de cette classe de taille, on la supprime + if (log.isInfoEnabled()) { + log.info("Remove length class " + row + " from frequencies."); + } + + removeRow(row); + + } else { + updateRow(row); + } + + } + + } + + public void addWeightToFrequencyRow(IndividualObservationBatchRowModel row, float weight) { + if (row.withSize()) { + addWeightToFrequencyRow(row.getSize(), weight); + } + } + + public void addWeightToFrequencyRow(float lengthStep, float weight) { + + if (log.isInfoEnabled()) { + log.info("add weight to frequency (lengthStep: " + lengthStep + "): " + weight); + } + + Preconditions.checkState(Weights.isPositive(weight)); + + SpeciesFrequencyRowModel row = getOrCreateRowForLengthStep(lengthStep); + + // conversion de poids + weight = Weights.convert(uiModel.getIndividualObservationWeightUnit(), weightUnit, weight); + row.addToWeight(weight); + + updateRow(row); + + } + + public void removeWeightToFrequencyRow(IndividualObservationBatchRowModel row, float weight) { + if (row.withSize()) { + removeWeightToFrequencyRow(row.getSize(), weight); + } + } + + public void removeWeightToFrequencyRow(float lengthStep, float weight) { + + if (log.isInfoEnabled()) { + log.info("remove weight to frequency (lengthStep: " + lengthStep + "): " + weight); + } + + Preconditions.checkState(Weights.isPositive(weight)); + + Optional<SpeciesFrequencyRowModel> optionalRow = getOptionalRowForLengthStep(lengthStep); + + if (optionalRow.isPresent()) { + + SpeciesFrequencyRowModel row = optionalRow.get(); + + // conversion de poids + weight = Weights.convert(uiModel.getIndividualObservationWeightUnit(), weightUnit, weight); + row.removeFromWeight(weight); + + updateRow(row); + } + + } + } \ No newline at end of file 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 e1e0437..5762aef 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 @@ -237,13 +237,22 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci // we only update the frequencies if the row is valid if (row.isValid() && model.mustCopyIndividualObservationSize()) { - updateFrequencyRowsNumbers(oldValue, newValue); + if (oldValue != null) { + getTableModel().decrementFrequencyRowsNumbers(oldValue); + } + if (newValue != null) { + getTableModel().incrementFrequencyRowsNumbers(newValue); + } Float weight = row.getWeight(); if (model.mustCopyIndividualObservationWeight() && weight != null) { - updateFrequencyRowsWeights(oldValue, -weight); - updateFrequencyRowsWeights(newValue, weight); + if (oldValue != null) { + getTableModel().removeWeightToFrequencyRow(oldValue, weight); + } + if (newValue != null) { + getTableModel().addWeightToFrequencyRow(newValue, weight); + } } } } @@ -267,7 +276,11 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci } if (weightToAdd != null) { - updateFrequencyRowsWeights(row.getSize(), weightToAdd); + if (Weights.isPositive(weightToAdd)) { + getTableModel().addWeightToFrequencyRow(row, weightToAdd); + } else { + getTableModel().removeWeightToFrequencyRow(row, -weightToAdd); + } } } break; @@ -294,8 +307,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci } } - CaracteristicQualitativeValue oldGender = (CaracteristicQualitativeValue) model.getGender(oldValue); - CaracteristicQualitativeValue newGender = (CaracteristicQualitativeValue) model.getGender(newValue); + CaracteristicQualitativeValue oldGender = model.getGender(oldValue); + CaracteristicQualitativeValue newGender = model.getGender(newValue); if (!Objects.equals(oldGender, newGender)) { individualObservationUICache.decrementsObservationNb(oldGender, maturity, row.getSize()); individualObservationUICache.incrementsObservationNb(newGender, maturity, row.getSize(), row.getOptionalSamplingCode()); @@ -325,14 +338,15 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci boolean newValue = (boolean) evt.getNewValue(); if (oldValue && model.mustCopyIndividualObservationSize()) { - updateFrequencyRowsNumbers(row.getSize(), null); + + getTableModel().decrementFrequencyRowsNumbers(row); } if (newValue) { if (model.mustCopyIndividualObservationSize()) { - updateFrequencyRowsNumbers(null, row.getSize()); + getTableModel().incrementFrequencyRowsNumbers(row); } if (model.mustCopyIndividualObservationWeight()) { - updateFrequencyRowsWeights(row.getSize(), row.getWeight()); + getTableModel().addWeightToFrequencyRow(row, row.getWeight()); } } } @@ -985,73 +999,6 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci return individualObservationUICache; } - public void updateFrequencyRowsNumbers(Float lengthStepToDec, Float lengthStepToInc) { - if (log.isInfoEnabled()) { - log.info("updateFrequencyRowsNumbers " + lengthStepToDec + ", " + lengthStepToInc); - } - - SpeciesFrequencyTableModel tableModel = getTableModel(); - - if (lengthStepToDec != null) { - lengthStepToDec = getModel().getLengthStep(lengthStepToDec); - - SpeciesFrequencyRowModel row = getModel().getRowCache().get(lengthStepToDec); - - if (row != null) { - row.decNumber(); - - if (!row.withNumber()) { - int rowIndex = tableModel.getRowIndex(row); - tableModel.removeRow(rowIndex); - getModel().getRowCache().remove(lengthStepToDec); - - } else { - tableModel.updateRow(row); - } - } - } - - if (lengthStepToInc != null) { - lengthStepToInc = getModel().getLengthStep(lengthStepToInc); - - SpeciesFrequencyRowModel row = getRowForLengthstep(lengthStepToInc); - row.incNumber(); - tableModel.updateRow(row); - } - } - - public void updateFrequencyRowsWeights(Float lengthStep, Float weight) { - if (log.isInfoEnabled()) { - log.info("updateFrequencyRowsWeights " + lengthStep + ", " + weight); - } - if (lengthStep != null && weight != null) { - - SpeciesFrequencyTableModel tableModel = getTableModel(); - - lengthStep = getModel().getLengthStep(lengthStep); - - SpeciesFrequencyRowModel row = getRowForLengthstep(lengthStep); - - boolean addToWeight = Weights.isPositive(weight); - // conversion de poids - 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); - tableModel.removeRow(rowIndex); - getModel().getRowCache().remove(lengthStep); - - } else { - tableModel.updateRow(row); - } - } - } - //------------------------------------------------------------------------// //-- Internal methods --// //------------------------------------------------------------------------// @@ -1400,9 +1347,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci tableModel.addNewRow(); } else { - for (int i = firstRow; i < tableModel.getRowCount(); i++) { - tableModel.getRows().get(i).setRankOrder(i + 1); - } + tableModel.recomputeRankOrders(firstRow); } break; @@ -1412,7 +1357,9 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci newRow.addPropertyChangeListener(obsChangedListener); if (getModel().mustCopyIndividualObservationSize()) { - updateFrequencyRowsNumbers(null, newRow.getSize()); + + getTableModel().incrementFrequencyRowsNumbers(newRow); + } getModel().recomputeIndividualObservationRowValidState(newRow); @@ -1687,28 +1634,6 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci return label + " (" + unit + ")"; } - protected SpeciesFrequencyRowModel getRowForLengthstep(float lengthstep) { - Map<Float, SpeciesFrequencyRowModel> rowCache = getModel().getRowCache(); - - SpeciesFrequencyRowModel row = rowCache.get(lengthstep); - - if (row == null) { - row = getTableModel().createNewRow(); - row.setLengthStep(lengthstep); - rowCache.put(lengthstep, row); - - // get new index - List<Float> steps = Lists.newArrayList(rowCache.keySet()); - steps.add(lengthstep); - Collections.sort(steps); - - int indexToInsert = steps.indexOf(lengthstep); - getTableModel().addNewRow(indexToInsert, row); - } - - return row; - } - protected void reloadRowsFromIndividualObservations() { SpeciesFrequencyUIModel model = getModel(); CopyIndividualObservationMode copyMode = model.getCopyIndividualObservationMode(); 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 e8e6cd2..93a31b7 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 @@ -1165,4 +1165,8 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa public void setGenderValueToDefaultCaracterictis(IndividualObservationBatchRowModel result, CaracteristicQualitativeValue gender) { result.getDefaultCaracteristics().put(sexCaracteristic, gender); } + + public WeightUnit getIndividualObservationWeightUnit() { + return individualObservationWeightUnit; + } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/RemoveObservationAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/RemoveObservationAction.java index 4839a19..6517d51 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/RemoveObservationAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/actions/RemoveObservationAction.java @@ -79,27 +79,34 @@ public class RemoveObservationAction extends SimpleActionSupport<SpeciesFrequenc SpeciesFrequencyUIModel model = ui.getModel(); SpeciesFrequencyUIHandler handler = ui.getHandler(); - + IndividualObservationUICache individualObservationUICache = handler.getIndividualObservationUICache(); - rowsToDelete.forEach(row -> { - if (row.withSize()) { + // Attention, on ne traite ici que les observations individuelles qui ont une taille + rowsToDelete.stream().filter(IndividualObservationBatchRowModel::withSize).forEach(row -> { - if (model.mustCopyIndividualObservationWeight() && row.withWeight()) { - handler.updateFrequencyRowsWeights(row.getSize(), -row.getWeight()); - } + // doit-on enlever le poids dans les mensurations ? + boolean removeWeight = model.isCopyIndividualObservationAll() && row.withWeight(); - if (model.mustCopyIndividualObservationSize()) { - handler.updateFrequencyRowsNumbers(row.getSize(), null); - } + // doit-on enlever une classe de taille dans les mensurations ? + boolean removeSize = removeWeight || model.isCopyIndividualObservationSize(); - individualObservationUICache.decrements(row); + if (removeWeight) { + handler.getTableModel().removeWeightToFrequencyRow(row, row.getWeight()); + } + if (removeSize) { + handler.getTableModel().decrementFrequencyRowsNumbers(row); } + + individualObservationUICache.decrements(row); model.removeIndividualObservationRowInError(row); + }); int minSelection = obsTable.getSelectionModel().getMinSelectionIndex(); int maxSelection = obsTable.getSelectionModel().getMaxSelectionIndex(); + + //FIXME On devrait faire un seul appel vers le table model obsTableModel.getRows().removeAll(rowsToDelete); obsTableModel.fireTableRowsDeleted(minSelection, maxSelection); -- 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 https://gitlab.nuiton.org/codelutin/tutti.git commit 203236b85d731042062d2587a128bc2376329d24 Merge: 1c4a770 34abc60 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 11 18:17:36 2016 +0200 Livrable #8232 Merge branch 'feature/8232' into develop .../IndividualObservationBatchTableModel.java | 16 +- .../frequency/SpeciesFrequencyTableModel.java | 167 +++++++++++++++++++++ .../frequency/SpeciesFrequencyUIHandler.java | 129 ++++------------ .../species/frequency/SpeciesFrequencyUIModel.java | 4 + .../frequency/actions/RemoveObservationAction.java | 27 ++-- 5 files changed, 227 insertions(+), 116 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm