This is an automated email from the git hooks/post-receive script. New commit to branch feature/8130 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit c47df44b0efa7b857468d59749b1cb3f73031c58 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Mar 16 08:47:17 2016 +0100 Amélioration du chargement de l'écran (et intégration du mode de recopie) --- .../frequency/SpeciesFrequencyUIHandler.java | 329 ++++++++++++--------- 1 file changed, 191 insertions(+), 138 deletions(-) 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 08deb13..548da4f 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 @@ -30,6 +30,7 @@ import fr.ifremer.tutti.ichtyometer.feed.record.FeedReaderMeasureRecord; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.CopyIndividualObservationMode; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.protocol.Rtp; @@ -47,7 +48,6 @@ import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.FrequencyConfigurationMode; -import fr.ifremer.tutti.persistence.entities.data.CopyIndividualObservationMode; 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.SpeciesBatchRowModel; @@ -117,6 +117,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -205,7 +206,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci // we only update the frequencies if the row is valid if (row.isValid()) { if (getModel().mustCopyIndividualObservationSize() - && IndividualObservationBatchRowModel.PROPERTY_SIZE.equals(propertyName)) { + && IndividualObservationBatchRowModel.PROPERTY_SIZE.equals(propertyName)) { Float oldValue = (Float) evt.getOldValue(); Float newValue = (Float) evt.getNewValue(); @@ -219,7 +220,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci } if (getModel().mustCopyIndividualObservationWeight() - && IndividualObservationBatchRowModel.PROPERTY_WEIGHT.equals(propertyName)) { + && IndividualObservationBatchRowModel.PROPERTY_WEIGHT.equals(propertyName)) { Float oldValue = (Float) evt.getOldValue(); Float newValue = (Float) evt.getNewValue(); @@ -243,7 +244,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci // if the row's valid state changes, then remove or readd it to the frequencies if (!getModel().isRowComputationInProgress() - && IndividualObservationBatchRowModel.PROPERTY_VALID.equals(propertyName)) { + && IndividualObservationBatchRowModel.PROPERTY_VALID.equals(propertyName)) { boolean oldValue = (boolean) evt.getOldValue(); boolean newValue = (boolean) evt.getNewValue(); @@ -515,7 +516,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci // when configuration mode change, let's focus the best component (see http://forge.codelutin.com/issues/4035) model.addPropertyChangeListener(SpeciesFrequencyUIModel.PROPERTY_FREQUENCIES_CONFIGURATION_MODE, evt -> { - final FrequencyConfigurationMode newValue = (FrequencyConfigurationMode) evt.getNewValue(); + FrequencyConfigurationMode newValue = (FrequencyConfigurationMode) evt.getNewValue(); SwingUtilities.invokeLater( () -> { JComponent componentToFocus = getComponentToFocus(newValue); @@ -537,17 +538,25 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci getObsTableModel().setRows((List<IndividualObservationBatchRowModel>) evt.getNewValue()); }); + // Pour bloquer le changement du mode de recopie des observations individuelles → mensurations model.addVetoableChangeListener(SpeciesFrequencyUIModel.PROPERTY_COPY_INDIVIDUAL_OBSERVATION_MODE, evt -> { CopyIndividualObservationMode oldCopyMode = (CopyIndividualObservationMode) evt.getOldValue(); + CopyIndividualObservationMode newCopyMode = (CopyIndividualObservationMode) evt.getNewValue(); + + if (initCopyIndividualObservationMode) { - if (oldCopyMode == CopyIndividualObservationMode.NOTHING) { + if (log.isInfoEnabled()) { + log.info("Skip ask user to confirm copyIndividualObservationMode changed from " + oldCopyMode + " to " + newCopyMode); + } + return; + } + + if (CopyIndividualObservationMode.NOTHING == oldCopyMode) { long rowsWithData = model.getRows().stream() - .filter(row -> row.getLengthStep() != null - || row.getNumber() != null - || row.getWeight() != null) - .count(); + .filter(row -> row.getLengthStep() != null || row.withNumber() || row.withWeight()) + .count(); if (rowsWithData > 0) { @@ -569,10 +578,28 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci } }); + // Pour mettre à jour les mensuratuibs suite au changement du mode de recopie des observations individuelles model.addPropertyChangeListener(SpeciesFrequencyUIModel.PROPERTY_COPY_INDIVIDUAL_OBSERVATION_MODE, evt -> { - ui.getRafaleModeButton().setSelected(true); - ui.getAddIndividualObservationCheckBox().setSelected(true); + CopyIndividualObservationMode oldCopyMode = (CopyIndividualObservationMode) evt.getOldValue(); + CopyIndividualObservationMode newCopyMode = (CopyIndividualObservationMode) evt.getNewValue(); + + boolean nothingCopyMode = CopyIndividualObservationMode.NOTHING == newCopyMode; + + if (initCopyIndividualObservationMode && nothingCopyMode) { + + if (log.isInfoEnabled()) { + log.info("Skip recompute frequencies from indivudal observations for nothing mode (flag initCopyIndividualObservationMode is on), copyIndividualObservationMode changed from " + oldCopyMode + " to " + newCopyMode); + } + return; + } + + if (!nothingCopyMode) { + + ui.getRafaleModeButton().setSelected(true); + ui.getAddIndividualObservationCheckBox().setSelected(true); + + } model.setRowComputationInProgress(true); @@ -679,11 +706,12 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci String title = optionalTitle.get(); frequenciesHistogramPopup.setTitle(title + t("tutti.editSpeciesFrequencies.title")); - averageWeightsHistogramPopup.setTitle(title + weightUnit.decorateLabel(t("tutti.editSpeciesFrequencies.field.graphAverageWeight"))); + averageWeightsHistogramPopup.setTitle(title + weightUnit.decorateLabel(t("tutti.editSpeciesFrequencies.field.graphAverageWeight"))); } SpeciesBatchRowModel speciesBatch = editor.getEditRow(); + Objects.requireNonNull(speciesBatch, "Impossible d'éditer un lot non renseigné"); SpeciesFrequencyUIModel model = getModel(); model.setNextEditableRowIndex(editor.getNextEditableRowIndex()); @@ -698,195 +726,203 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci frequencyEditor = editor; Caracteristic lengthStepCaracteristic = null; + CopyIndividualObservationMode copyIndividualObservationMode = null; - List<SpeciesFrequencyRowModel> rows = Lists.newArrayList(); - List<IndividualObservationBatchRowModel> obsRows = Lists.newArrayList(); - - if (speciesBatch != null) { + List<SpeciesFrequencyRowModel> rows = new ArrayList<>(); + List<IndividualObservationBatchRowModel> obsRows = new ArrayList<>(); - Species species = speciesBatch.getSpecies(); + Species species = speciesBatch.getSpecies(); - model.setTotalWeight(speciesBatch.getWeight()); + model.setTotalWeight(speciesBatch.getWeight()); - Optional<String> speciesMaturityPmfmId = Optional.empty(); + Optional<String> speciesMaturityPmfmId = Optional.empty(); - // set rtps - TuttiProtocol protocol = getDataContext().getProtocol(); - if (protocol != null) { + // set rtps + TuttiProtocol protocol = getDataContext().getProtocol(); + if (protocol != null) { - Integer referenceTaxonId = species.getReferenceTaxonId(); - Optional<SpeciesProtocol> optSpeciesProtocol = - protocol.getSpecies().stream() - .filter(sp -> sp.getSpeciesReferenceTaxonId().equals(referenceTaxonId)) - .findFirst(); + Integer referenceTaxonId = species.getReferenceTaxonId(); + Optional<SpeciesProtocol> optSpeciesProtocol = + protocol.getSpecies().stream() + .filter(sp -> sp.getSpeciesReferenceTaxonId().equals(referenceTaxonId)) + .findFirst(); - if (optSpeciesProtocol.isPresent()) { - SpeciesProtocol speciesProtocol = optSpeciesProtocol.get(); - Rtp rtp; - CaracteristicQualitativeValue sampleCategoryValue = (CaracteristicQualitativeValue) speciesBatch.getSampleCategoryValue(sexCaracteristic.getIdAsInt()); + if (optSpeciesProtocol.isPresent()) { + SpeciesProtocol speciesProtocol = optSpeciesProtocol.get(); + Rtp rtp; + CaracteristicQualitativeValue sampleCategoryValue = (CaracteristicQualitativeValue) speciesBatch.getSampleCategoryValue(sexCaracteristic.getIdAsInt()); - if (sampleCategoryValue != null) { - - if (Sexs.isMale(sampleCategoryValue)) { - rtp = speciesProtocol.getRtpMale(); - } else if (Sexs.isFemale(sampleCategoryValue)) { - rtp = speciesProtocol.getRtpFemale(); - } else { - rtp = speciesProtocol.getRtpUndefined(); - } + if (sampleCategoryValue != null) { + if (Sexs.isMale(sampleCategoryValue)) { + rtp = speciesProtocol.getRtpMale(); + } else if (Sexs.isFemale(sampleCategoryValue)) { + rtp = speciesProtocol.getRtpFemale(); } else { rtp = speciesProtocol.getRtpUndefined(); } - model.setRtp(rtp); - speciesMaturityPmfmId = Optional.ofNullable(speciesProtocol.getMaturityPmfmId()); + } else { + rtp = speciesProtocol.getRtpUndefined(); } - } + model.setRtp(rtp); - List<SpeciesFrequencyRowModel> frequency = speciesBatch.getFrequency(); - List<IndividualObservationBatchRowModel> individualObservations = speciesBatch.getIndividualObservation(); - - // try to load existing frequency + speciesMaturityPmfmId = Optional.ofNullable(speciesProtocol.getMaturityPmfmId()); + } + } - if (CollectionUtils.isNotEmpty(frequency)) { + List<SpeciesFrequencyRowModel> frequency = speciesBatch.getFrequency(); + List<IndividualObservationBatchRowModel> individualObservations = speciesBatch.getIndividualObservation(); - SpeciesFrequencyTableModel tableModel = getTableModel(); + // + // try to load existing frequency + // - for (SpeciesFrequencyRowModel rowModel : frequency) { + if (CollectionUtils.isNotEmpty(frequency)) { - SpeciesFrequencyRowModel newRow = tableModel.createNewRow(false, false); - newRow.setLengthStepCaracteristic(rowModel.getLengthStepCaracteristic()); - newRow.setLengthStep(rowModel.getLengthStep()); - newRow.setNumber(rowModel.getNumber()); - newRow.setWeight(rowModel.getWeight()); - rows.add(newRow); - } + SpeciesFrequencyTableModel tableModel = getTableModel(); - // use first frequency row length step caracteristics + for (SpeciesFrequencyRowModel rowModel : frequency) { - SpeciesFrequencyRowModel rowModel = frequency.get(0); - lengthStepCaracteristic = rowModel.getLengthStepCaracteristic(); + SpeciesFrequencyRowModel newRow = tableModel.createNewRow(false, false); + newRow.copy(rowModel); + rows.add(newRow); - if (log.isInfoEnabled()) { - log.info("Use existing lengthStep " + - "caracteristic / step " + - decorate(lengthStepCaracteristic)); - } } - // Add maturity column if necessary + // use first frequency row length step caracteristics - Optional<Caracteristic> maturityCaracteristic = speciesMaturityPmfmId.map(maturityCaracteristics::get); + SpeciesFrequencyRowModel rowModel = frequency.get(0); + lengthStepCaracteristic = rowModel.getLengthStepCaracteristic(); - if (maturityCaracteristic.isPresent()) { - addMaturityCaracteristicColumnToModel(maturityCaracteristic.get()); + if (log.isInfoEnabled()) { + log.info("Use existing lengthStep caracteristic / step " + decorate(lengthStepCaracteristic)); } + } - // try to load existing frequency + // Add maturity column if necessary - if (CollectionUtils.isNotEmpty(individualObservations)) { + Optional<Caracteristic> maturityCaracteristic = speciesMaturityPmfmId.map(maturityCaracteristics::get); - IndividualObservationBatchTableModel tableModel = getObsTableModel(); - tableModel.setRows(new ArrayList<>()); + if (maturityCaracteristic.isPresent()) { + addMaturityCaracteristicColumnToModel(maturityCaracteristic.get()); + } - int rankOrder = 1; - for (IndividualObservationBatchRowModel rowModel : individualObservations) { + // + // try to load existing individual observations + // - IndividualObservationBatchRowModel newRow = tableModel.createNewRow(); - newRow.copyIndividualObservationBatchRowModel(rowModel); - newRow.setRankOrder(rankOrder++); - newRow.addPropertyChangeListener(obsChangedListener); - newRow.setValid(true); + if (CollectionUtils.isNotEmpty(individualObservations)) { - if (maturityCaracteristic.isPresent()) { + IndividualObservationBatchTableModel tableModel = getObsTableModel(); + tableModel.setRows(new ArrayList<>()); + int rankOrder = 1; + for (IndividualObservationBatchRowModel rowModel : individualObservations) { - Caracteristic caracteristicKey = maturityCaracteristic.get(); - Serializable caracteristicValue = newRow.getCaracteristics().remove(caracteristicKey); - newRow.getDefaultCaracteristics().putIfAbsent(caracteristicKey, caracteristicValue); + CopyIndividualObservationMode incomingCopyIndividualObservationMode = rowModel.getCopyIndividualObservationMode(); + Objects.requireNonNull(incomingCopyIndividualObservationMode, "Mode de recopie non trouvé sur l'observation individuelle: " + rowModel.getId()); + if (copyIndividualObservationMode == null) { + copyIndividualObservationMode = incomingCopyIndividualObservationMode; + } else { + if (copyIndividualObservationMode != incomingCopyIndividualObservationMode) { + throw new IllegalStateException("Plusieurs modes de recopie trouvés sur les observations individuelles du lot, ce qui est impossible"); } - - obsRows.add(newRow); } + IndividualObservationBatchRowModel newRow = tableModel.createNewRow(); + newRow.copy(rowModel); + newRow.setRankOrder(rankOrder++); + newRow.addPropertyChangeListener(obsChangedListener); + newRow.setValid(true); - // use first frequency row length step caracteristics - - if (lengthStepCaracteristic == null) { - IndividualObservationBatchRowModel rowModel = individualObservations.get(0); - lengthStepCaracteristic = rowModel.getLengthStepCaracteristic(); + if (maturityCaracteristic.isPresent()) { - if (log.isInfoEnabled()) { - log.info("Use existing lengthStep " + - "caracteristic / step " + - decorate(lengthStepCaracteristic)); - } + Caracteristic caracteristicKey = maturityCaracteristic.get(); + Serializable caracteristicValue = newRow.getCaracteristics().remove(caracteristicKey); + newRow.getDefaultCaracteristics().putIfAbsent(caracteristicKey, caracteristicValue); } - } - SpeciesBatchRowModel previousSiblingRow = frequencyEditor.getPreviousSiblingRow(); + obsRows.add(newRow); - if (lengthStepCaracteristic == null && previousSiblingRow != null) { + } - // try to get it from his previous brother row - List<SpeciesFrequencyRowModel> previousFrequency = previousSiblingRow.getFrequency(); + // use first individual observation row length step caracteristics - if (CollectionUtils.isNotEmpty(previousFrequency)) { + if (lengthStepCaracteristic == null) { + IndividualObservationBatchRowModel rowModel = individualObservations.get(0); + lengthStepCaracteristic = rowModel.getLengthStepCaracteristic(); - // use the first frequency length step caracteristic / step - SpeciesFrequencyRowModel rowModel = previousFrequency.get(0); - lengthStepCaracteristic = rowModel.getLengthStepCaracteristic(); - if (log.isInfoEnabled()) { - log.info("Use previous sibling existing lengthStep " + - "caracteristic / step " + - decorate(lengthStepCaracteristic)); - } + if (log.isInfoEnabled()) { + log.info("Use existing lengthStep caracteristic / step " + decorate(lengthStepCaracteristic)); } } - if (lengthStepCaracteristic == null) { + } else { - String lengthStepPmfmId = taxonCache.getLengthStepPmfmId(species); + // par défaut pas de mode de recopie + copyIndividualObservationMode = CopyIndividualObservationMode.NOTHING; - if (lengthStepPmfmId != null) { + } - lengthStepCaracteristic = lengthStepCaracteristics.get(lengthStepPmfmId); + if (log.isInfoEnabled()) { + log.info("CopyIndividualObservationMode: " + copyIndividualObservationMode); + } - if (log.isInfoEnabled()) { - log.info("Use existing from protocol lengthStep " + - "caracteristic / step " + - decorate(lengthStepCaracteristic)); - } + SpeciesBatchRowModel previousSiblingRow = frequencyEditor.getPreviousSiblingRow(); - } + if (lengthStepCaracteristic == null && previousSiblingRow != null) { + + // try to get it from his previous brother row + List<SpeciesFrequencyRowModel> previousFrequency = previousSiblingRow.getFrequency(); + + if (CollectionUtils.isNotEmpty(previousFrequency)) { + // use the first frequency length step caracteristic / step + SpeciesFrequencyRowModel rowModel = previousFrequency.get(0); + lengthStepCaracteristic = rowModel.getLengthStepCaracteristic(); + if (log.isInfoEnabled()) { + log.info("Use previous sibling existing lengthStep caracteristic / step " + decorate(lengthStepCaracteristic)); + } } + } - if (getContext().isIchtyometerConnected()) { + if (lengthStepCaracteristic == null) { - // let's listen the ichtyometer - listenItchtyometer(); + String lengthStepPmfmId = taxonCache.getLengthStepPmfmId(species); - } + if (lengthStepPmfmId != null) { - if (lengthStepCaracteristic == null) { - String speciesLengthStepPmfmId = taxonCache.getLengthStepPmfmId(species); - if (speciesLengthStepPmfmId == null) { - mode = FrequencyConfigurationMode.SIMPLE_COUNTING; + lengthStepCaracteristic = lengthStepCaracteristics.get(lengthStepPmfmId); + + if (log.isInfoEnabled()) { + log.info("Use existing from protocol lengthStep caracteristic / step " + decorate(lengthStepCaracteristic)); } - } - if (log.isDebugEnabled()) { - log.debug("Will edit batch row: " + speciesBatch + " with " + rows.size() + " frequency"); } - Integer number = speciesBatch.getNumber(); - if (number != null && rows.isEmpty()) { + } + + if (lengthStepCaracteristic == null) { + String speciesLengthStepPmfmId = taxonCache.getLengthStepPmfmId(species); + if (speciesLengthStepPmfmId == null) { mode = FrequencyConfigurationMode.SIMPLE_COUNTING; - model.setSimpleCount(number); } } + if (log.isInfoEnabled()) { + log.info("FrequencyConfigurationMode: " + mode); + } + + if (log.isDebugEnabled()) { + log.debug("Will edit batch row: " + speciesBatch + " with " + rows.size() + " frequency"); + } + + Integer number = speciesBatch.getNumber(); + if (number != null && rows.isEmpty()) { + mode = FrequencyConfigurationMode.SIMPLE_COUNTING; + model.setSimpleCount(number); + } + // make sure configuration mode will be rebound model.setConfigurationMode(null); model.setConfigurationMode(mode); @@ -902,7 +938,6 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci Collections.sort(rows); model.setLengthStepCaracteristic(lengthStepCaracteristic); - model.setCopyIndividualObservationMode(CopyIndividualObservationMode.NOTHING); model.setRows(rows); IndividualObservationBatchTableModel obsTableModel = getObsTableModel(); @@ -924,9 +959,27 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci // keep batch (will be used to push back editing entry) model.setBatch(speciesBatch); + // let's change the copy mode (mark it in init mode to avoid user change confirmation and some recompuations) + initCopyIndividualObservationMode = true; + try { + model.setCopyIndividualObservationMode(copyIndividualObservationMode); + } finally { + initCopyIndividualObservationMode = false; + } + + if (getContext().isIchtyometerConnected()) { + + // let's listen the ichtyometer + listenItchtyometer(); + + } + model.setModify(false); } + // Flag to mark when changing the CopyIndividualObservationMode in init + private boolean initCopyIndividualObservationMode; + public void updateFrequencyRowsNumbers(Float lengthStepToDec, Float lengthStepToInc) { if (log.isInfoEnabled()) { @@ -1137,7 +1190,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci averageWeightsChart = ChartFactory.createXYLineChart(null, t("tutti.editSpeciesFrequencies.table.header.lengthStep"), getConfig().getIndividualObservationWeightUnit() - .decorateLabel(t("tutti.editSpeciesFrequencies.averageWeight.label")), + .decorateLabel(t("tutti.editSpeciesFrequencies.averageWeight.label")), getModel().averageWeightsDataset); averageWeightsChart.clearSubtitles(); @@ -1319,7 +1372,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci break; case TableModelEvent.INSERT: - for (int i = firstRow ; i <= lastRow ; i++) { + for (int i = firstRow; i <= lastRow; i++) { IndividualObservationBatchRowModel newRow = tableModel.getRows().get(i); newRow.addPropertyChangeListener(obsChangedListener); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.