05/13: Revue de la zone de notification
This is an automated email from the git hooks/post-receive script. New commit to branch feature/8255 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit e7dec7b3385ffdb9537990bd65767a1ec9bf95bd Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 19 15:16:27 2016 +0200 Revue de la zone de notification --- ...dividualObservationNotificationZoneHandler.java | 260 ---------------- .../frequency/SamplingNotificationZoneHandler.java | 331 +++++++++++++++++++++ .../frequency/SamplingNotificationZoneModel.java | 44 +++ .../frequency/SamplingNotificationZoneStatus.java | 15 + .../frequency/SpeciesFrequencyUIHandler.java | 6 +- 5 files changed, 393 insertions(+), 263 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/IndividualObservationNotificationZoneHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/IndividualObservationNotificationZoneHandler.java deleted file mode 100644 index 806258c..0000000 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/IndividualObservationNotificationZoneHandler.java +++ /dev/null @@ -1,260 +0,0 @@ -package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; - -import fr.ifremer.tutti.persistence.entities.protocol.CalcifiedPiecesSamplingDefinition; -import fr.ifremer.tutti.persistence.entities.protocol.Zone; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.service.sampling.CalcifiedPiecesSamplingAlgorithmEntryNotFoundException; -import fr.ifremer.tutti.service.sampling.IndividualObservationSamplingContext; -import fr.ifremer.tutti.service.sampling.IndividualObservationSamplingStatus; -import fr.ifremer.tutti.service.sampling.SamplingListener; -import fr.ifremer.tutti.service.sampling.SizeNotDefinedOnIndividualObservationException; -import fr.ifremer.tutti.service.sampling.ZoneNotDefinedOnFishingOperationException; -import fr.ifremer.tutti.ui.swing.content.operation.catches.species.edit.SpeciesBatchRowModel; -import fr.ifremer.tutti.util.Numbers; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; - -import javax.swing.JLabel; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionListener; -import java.awt.Color; -import java.io.Closeable; - -import static org.nuiton.i18n.I18n.t; - -/** - * Pour gérer la zone de notification des observations individuelles. - * - * Created on 18/04/16. - * - * @author Tony Chemit - chemit@codelutin.com - */ -public class IndividualObservationNotificationZoneHandler implements Closeable { - - /** Logger. */ - private static final Log log = LogFactory.getLog(IndividualObservationNotificationZoneHandler.class); - - private final SpeciesFrequencyUI ui; - private final SpeciesFrequencyUIModel uiModel; - private final SpeciesFrequencyUIHandler uiHandler; - private final IndividualObservationUICache individualObservationUICache; - private final IndividualObservationBatchTableModel individualObservationTableModel; - private final JLabel samplingWarningLabel; - private final JLabel samplingSummaryLabel; - private final SamplingListener samplingListener; - private final ListSelectionListener listSelectionListener; - private final Decorator<Integer> infiniteDecorator; - private final Decorator<Species> speciesDecorator; - - public IndividualObservationNotificationZoneHandler(SpeciesFrequencyUI ui) { - this.ui = ui; - this.uiModel = ui.getModel(); - this.samplingWarningLabel = ui.getSamplingWarningLabel(); - this.samplingSummaryLabel = ui.getSamplingResumeLabel(); - this.individualObservationTableModel = (IndividualObservationBatchTableModel) ui.getObsTable().getModel(); - this.uiHandler = ui.getHandler(); - this.individualObservationUICache = uiHandler.getIndividualObservationUICache(); - this.infiniteDecorator = ui.getHandler().getDecorator(Integer.class, DecoratorService.NULL_INFINITE); - this.speciesDecorator = ui.getHandler().getDecorator(Species.class, DecoratorService.WITH_SURVEY_CODE); - // Ecoute sur le cache de données pour savoir quand il faut afficher les notifications de prélèvements - this.samplingListener = event -> { - - if (uiModel.isCanDisplayNotifications()) { - - whenSamplingNeeded(event.getStatus()); - - } - }; - - listSelectionListener = e -> { - - ListSelectionModel source = (ListSelectionModel) e.getSource(); - - if (e.getValueIsAdjusting()) { - return; - } - - if (source.isSelectionEmpty()) { - whenCanNotUseSampling("Aucune observation individuelle sélectionnée."); - return; - } - - if (getSelectedRowCount(source) > 1) { - whenCanNotUseSampling("Plusieurs observations individuelles sélectionnées."); - return; - } - - IndividualObservationBatchRowModel selectedRow = individualObservationTableModel.getEntry(source.getMinSelectionIndex()); - updateSelectedRow(selectedRow); - - }; - - } - - public void editBatch(SpeciesBatchRowModel speciesBatch) { - - if (log.isInfoEnabled()) { - log.info("Edit batch for " + speciesBatch); - } - - samplingWarningLabel.setText(""); - samplingSummaryLabel.setText(""); - - if (!uiHandler.getContext().isProtocolFilled()) { - - // pas de protocole - whenCanNotUseSampling("Pas de protocole défini."); - return; - } - - if (!uiHandler.getContext().getDataContext().getProtocol().isUseCalcifiedPieceSampling()) { - - // pas d'utilisation de l'algorithme de prélèvement des pièces calcifiées - whenCanNotUseSampling("L'utilisation de l'algorithme n'est pas activée dans le protocole."); - return; - } - - if (!individualObservationUICache.isFishingOperationWithZone()) { - - // pas de zone définie sur l'opération de pêche - whenCanNotUseSampling("Le trait n'est pas dans une zone."); - return; - } - - if (!individualObservationUICache.isSpeciesDefinedInCalcifiedPiecesSampling()) { - - // pas de définition d'algorithme sur cette espèce - whenCanNotUseSampling("L'espèce du lot n'est pas connue dans la définition de l'algorithme."); - return; - } - - individualObservationUICache.getCruiseSamplingCache().addSamplingListener(samplingListener); - - ui.getObsTable().getSelectionModel().addListSelectionListener(listSelectionListener); - - // on vide volontairement la sélection pour que la zone de notification soit bien mise à jour - whenCanNotUseSampling("Aucune observation individuelle sélectionnée."); - - - } - - @Override - public void close() { - - ui.getObsTable().getSelectionModel().removeListSelectionListener(listSelectionListener); - if (individualObservationUICache.useCruiseSamplingCache()) { - individualObservationUICache.getCruiseSamplingCache().removeSamplingListener(samplingListener); - } - - } - - public void updateSelectedRow(IndividualObservationBatchRowModel selectedRow) { - - try { - - IndividualObservationSamplingStatus status = individualObservationUICache.getIndividualObservationStatus(selectedRow); - selectedRow.setIndividualObservationSamplingStatus(status); - whenUpdateSummary(status); - - } catch (CalcifiedPiecesSamplingAlgorithmEntryNotFoundException e) { - whenCanNotUseSampling("Pas de correspondance sur l'observation individuelle sélectionnée dans le protocole."); - } catch (SizeNotDefinedOnIndividualObservationException e) { - whenCanNotUseSampling("La taille n'est pas définie sur l'observation individuelle sélectionnée."); - } catch (ZoneNotDefinedOnFishingOperationException e) { - whenCanNotUseSampling("Le trait n'est pas dans une zone."); - } - - } - - private void whenCanNotUseSampling(String message) { - samplingWarningLabel.setText("< L'algorithme de prélèvements des pièces calcifiées n'est pas utilisé >"); - samplingWarningLabel.setForeground(null); - samplingWarningLabel.setBackground(Color.LIGHT_GRAY); - samplingSummaryLabel.setText(message); - } - - private void whenSamplingNeeded(IndividualObservationSamplingStatus status) { - - if (log.isInfoEnabled()) { - log.info("samplingNeeded for " + status); - } - - samplingWarningLabel.setText(t("tutti.editSpeciesFrequencies.samplingNeeded.warning")); - samplingWarningLabel.setForeground(uiHandler.getConfig().getColorHighlightInfoForeground()); - samplingWarningLabel.setBackground(uiHandler.getConfig().getColorHighlightInfoBackground()); - displaySummary(status); - - } - - private void whenUpdateSummary(IndividualObservationSamplingStatus status) { - if (status.isOneTotalCountIsAttained()) { - samplingWarningLabel.setText(t("tutti.editSpeciesFrequencies.samplingTotalCountAttained.warning")); - samplingWarningLabel.setForeground(null); - samplingWarningLabel.setBackground(Color.LIGHT_GRAY); - } else { - samplingWarningLabel.setText(null); - } - displaySummary(status); - } - - private void displaySummary(IndividualObservationSamplingStatus event) { - - IndividualObservationSamplingContext individualObservationSamplingContext = event.getIndividualObservationSamplingContext(); - - CalcifiedPiecesSamplingDefinition calcifiedPiecesSamplingDefinition = event.getCalcifiedPiecesSamplingDefinition(); - - int nbForOperation = event.getSamplingCountInFishingOperation(); - int nbForZone = event.getSamplingCountInZone(); - int nbForCruise = event.getSamplingCountInCruise(); - - String nbForOperationLabel = getLabelForSamplingNumber(nbForOperation, calcifiedPiecesSamplingDefinition.getOperationLimitation()); - String nbForZoneLabel = getLabelForSamplingNumber(nbForZone, calcifiedPiecesSamplingDefinition.getZoneLimitation()); - String nbForCruiseLabel = getLabelForSamplingNumber(nbForCruise, calcifiedPiecesSamplingDefinition.getMaxByLenghtStep()); - - String key = speciesDecorator.toString(individualObservationSamplingContext.getSpecies()) - + " " + Numbers.convertFromMm(individualObservationSamplingContext.getLengthStep(), uiModel.getLengthStepCaracteristicUnit()) - + " " + uiModel.getLengthStepCaracteristicUnit(); - if (individualObservationSamplingContext.withGender()) { - key += " " + individualObservationSamplingContext.getGender().getDescription(); - } - if (individualObservationSamplingContext.withMaturity()) { - if (individualObservationSamplingContext.getMaturity()) { - key += " " + t("tutti.editSpeciesFrequencies.samplingNeeded.mature"); - } else { - key += " " + t("tutti.editSpeciesFrequencies.samplingNeeded.immature"); - } - } - - Decorator<Zone> zoneDecorator = ui.getHandler().getDecorator(Zone.class, null); - String zone = zoneDecorator.toString(individualObservationSamplingContext.getZone()); - String summary = t("tutti.editSpeciesFrequencies.samplingNeeded.summary", key, nbForOperationLabel, zone, nbForZoneLabel, nbForCruiseLabel); - - samplingSummaryLabel.setText(summary); - } - - /** - * Returns the number of selected rows. - * - * @return the number of selected rows, 0 if no rows are selected - */ - private int getSelectedRowCount(ListSelectionModel selectionModel) { - int iMin = selectionModel.getMinSelectionIndex(); - int iMax = selectionModel.getMaxSelectionIndex(); - int count = 0; - - for (int i = iMin; i <= iMax; i++) { - if (selectionModel.isSelectedIndex(i)) { - count++; - } - } - return count; - } - - - private String getLabelForSamplingNumber(int value, Integer max) { - - return "<strong>" + infiniteDecorator.toString(value) + "</strong> (" + infiniteDecorator.toString(max) + ")"; - } -} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneHandler.java new file mode 100644 index 0000000..0587d90 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneHandler.java @@ -0,0 +1,331 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.entities.protocol.CalcifiedPiecesSamplingDefinition; +import fr.ifremer.tutti.persistence.entities.protocol.Zone; +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.service.sampling.CalcifiedPiecesSamplingAlgorithmEntryNotFoundException; +import fr.ifremer.tutti.service.sampling.IndividualObservationSamplingContext; +import fr.ifremer.tutti.service.sampling.IndividualObservationSamplingStatus; +import fr.ifremer.tutti.service.sampling.SamplingListener; +import fr.ifremer.tutti.service.sampling.SizeNotDefinedOnIndividualObservationException; +import fr.ifremer.tutti.service.sampling.ZoneNotDefinedOnFishingOperationException; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.edit.SpeciesBatchRowModel; +import fr.ifremer.tutti.util.Numbers; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.decorator.Decorator; + +import javax.swing.JLabel; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionListener; +import java.awt.Color; +import java.beans.PropertyChangeListener; +import java.io.Closeable; + +import static org.nuiton.i18n.I18n.t; + +/** + * Pour gérer la zone de notification des observations individuelles. + * + * Created on 18/04/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class SamplingNotificationZoneHandler implements Closeable { + + /** Logger. */ + private static final Log log = LogFactory.getLog(SamplingNotificationZoneHandler.class); + + private final SpeciesFrequencyUIModel uiModel; + private final SamplingNotificationZoneModel model; + private final IndividualObservationBatchTableModel individualObservationTableModel; + private final ListSelectionModel listSelectionModel; + + private final IndividualObservationUICache individualObservationUICache; + + private final JLabel samplingWarningLabel; + private final JLabel samplingSummaryLabel; + + private final SamplingListener samplingListener; + private final ListSelectionListener listSelectionListener; + private final PropertyChangeListener modelSummaryTextChanged; + private final PropertyChangeListener modelStatusChanged; + + private final Decorator<Integer> infiniteDecorator; + private final Decorator<Species> speciesDecorator; + private final Decorator<Zone> zoneDecorator; + + private final Color colorHighlightInfoForeground; + private final Color colorHighlightInfoBackground; + + public SamplingNotificationZoneHandler(SpeciesFrequencyUI ui) { + this.uiModel = ui.getModel(); + this.samplingWarningLabel = ui.getSamplingWarningLabel(); + this.samplingSummaryLabel = ui.getSamplingResumeLabel(); + this.individualObservationTableModel = (IndividualObservationBatchTableModel) ui.getObsTable().getModel(); + this.model = new SamplingNotificationZoneModel(); + this.listSelectionModel = ui.getObsTable().getSelectionModel(); + + SpeciesFrequencyUIHandler uiHandler = ui.getHandler(); + this.individualObservationUICache = uiHandler.getIndividualObservationUICache(); + this.infiniteDecorator = uiHandler.getDecorator(Integer.class, DecoratorService.NULL_INFINITE); + this.speciesDecorator = uiHandler.getDecorator(Species.class, DecoratorService.WITH_SURVEY_CODE); + this.zoneDecorator = uiHandler.getDecorator(Zone.class, null); + this.colorHighlightInfoForeground = uiHandler.getConfig().getColorHighlightInfoForeground(); + this.colorHighlightInfoBackground = uiHandler.getConfig().getColorHighlightInfoBackground(); + + // Ecoute sur le cache de données pour savoir quand il faut afficher les notifications de prélèvements + this.samplingListener = event -> { + + if (uiModel.isCanDisplayNotifications()) { + + whenSamplingNeeded(event.getStatus()); + + } + }; + + // Ecoute le changement d'état de la zone de notification pour mettre à jour le statut + this.modelStatusChanged = event -> { + + SamplingNotificationZoneStatus newValue = (SamplingNotificationZoneStatus) event.getNewValue(); + + switch (newValue) { + + case DISABLED: + + samplingWarningLabel.setText("< L'algorithme de prélèvements des pièces calcifiées n'est pas utilisé >"); + samplingWarningLabel.setForeground(null); + samplingWarningLabel.setBackground(Color.LIGHT_GRAY); + + break; + case NEED_SAMPLING: + + samplingWarningLabel.setText(t("tutti.editSpeciesFrequencies.samplingNeeded.warning")); + samplingWarningLabel.setForeground(colorHighlightInfoForeground); + samplingWarningLabel.setBackground(colorHighlightInfoBackground); + + break; + case COUNT_ATTAINED: + + samplingWarningLabel.setText(t("tutti.editSpeciesFrequencies.samplingTotalCountAttained.warning")); + samplingWarningLabel.setForeground(null); + samplingWarningLabel.setBackground(Color.LIGHT_GRAY); + + break; + case NONE: + + samplingWarningLabel.setText(null); + samplingWarningLabel.setForeground(null); + samplingWarningLabel.setBackground(null); + + break; + } + }; + + // Ecoute le changement du texte de la zone de notification pour mettre à jour l'ui + this.modelSummaryTextChanged = event -> { + + String newValue = (String) event.getNewValue(); + samplingSummaryLabel.setText(newValue); + + }; + + // Ecoute la sélection sur le tableau des observations individuelles pour rafraîchir la zone de notification + this.listSelectionListener = event -> { + + ListSelectionModel source = (ListSelectionModel) event.getSource(); + + if (event.getValueIsAdjusting()) { + return; + } + + if (source.isSelectionEmpty()) { + whenCanNotUseSampling("Aucune observation individuelle sélectionnée."); + return; + } + + if (getSelectedRowCount(source) > 1) { + whenCanNotUseSampling("Plusieurs observations individuelles sélectionnées."); + return; + } + + IndividualObservationBatchRowModel selectedRow = individualObservationTableModel.getEntry(source.getMinSelectionIndex()); + + // on commence toujours par supprimer le status de cette ligne + selectedRow.setIndividualObservationSamplingStatus(null); + + try { + + IndividualObservationSamplingStatus status = individualObservationUICache.getIndividualObservationStatus(selectedRow); + selectedRow.setIndividualObservationSamplingStatus(status); + whenUpdateSummary(status); + + } catch (CalcifiedPiecesSamplingAlgorithmEntryNotFoundException e) { + whenCanNotUseSampling("Pas de correspondance sur l'observation individuelle sélectionnée dans le protocole."); + } catch (SizeNotDefinedOnIndividualObservationException e) { + whenCanNotUseSampling("La taille n'est pas définie sur l'observation individuelle sélectionnée."); + } catch (ZoneNotDefinedOnFishingOperationException e) { + whenCanNotUseSampling("Le trait n'est pas dans une zone."); + } + + }; + + } + + public void editBatch(SpeciesBatchRowModel speciesBatch) { + + if (log.isInfoEnabled()) { + log.info("Edit batch for " + speciesBatch); + } + + // toujours supprimer les listeners + listSelectionModel.removeListSelectionListener(listSelectionListener); + model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SAMPLING_STATUS, modelStatusChanged); + model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SUMMARY_TEXT, modelSummaryTextChanged); + if (individualObservationUICache.useCruiseSamplingCache()) { + individualObservationUICache.getCruiseSamplingCache().removeSamplingListener(samplingListener); + } + + // on les ajoutent (on peut en avoir besoin pour désactiver la zone de notification) + model.addPropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SAMPLING_STATUS, modelStatusChanged); + model.addPropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SUMMARY_TEXT, modelSummaryTextChanged); + + if (!individualObservationUICache.isProtocolFilled()) { + + // pas de protocole + stopUsingStatusNotication("Pas de protocole défini."); + return; + } + + if (!individualObservationUICache.isProtocolUseCalcifiedPieceSampling()) { + + // pas d'utilisation de l'algorithme de prélèvement des pièces calcifiées + stopUsingStatusNotication("L'utilisation de l'algorithme n'est pas activée dans le protocole."); + return; + } + + if (!individualObservationUICache.isFishingOperationWithZone()) { + + // pas de zone définie sur l'opération de pêche + stopUsingStatusNotication("Le trait n'est pas dans une zone."); + return; + } + + if (!individualObservationUICache.isSpeciesDefinedInCalcifiedPiecesSampling()) { + + // pas de définition d'algorithme sur cette espèce + stopUsingStatusNotication("L'espèce du lot n'est pas connue dans la définition de l'algorithme."); + return; + } + + Preconditions.checkState(individualObservationUICache.useCruiseSamplingCache()); + + model.reset(); + + individualObservationUICache.getCruiseSamplingCache().addSamplingListener(samplingListener); + listSelectionModel.addListSelectionListener(listSelectionListener); + + } + + @Override + public void close() { + + listSelectionModel.removeListSelectionListener(listSelectionListener); + if (individualObservationUICache.useCruiseSamplingCache()) { + individualObservationUICache.getCruiseSamplingCache().removeSamplingListener(samplingListener); + } + model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SAMPLING_STATUS, modelStatusChanged); + model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SUMMARY_TEXT, modelSummaryTextChanged); + + } + + private void whenCanNotUseSampling(String message) { + model.setSummaryText(message); + model.setSamplingNotificationZoneStatus(SamplingNotificationZoneStatus.DISABLED); + } + + private void stopUsingStatusNotication(String message) { + + whenCanNotUseSampling(message); + model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SAMPLING_STATUS, modelStatusChanged); + model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SUMMARY_TEXT, modelSummaryTextChanged); + + } + + private void whenSamplingNeeded(IndividualObservationSamplingStatus status) { + + model.setSummaryText(getSummaryText(status)); + model.setSamplingNotificationZoneStatus(SamplingNotificationZoneStatus.NEED_SAMPLING); + + } + + private void whenUpdateSummary(IndividualObservationSamplingStatus status) { + + model.setSummaryText(getSummaryText(status)); + + SamplingNotificationZoneStatus zoneStatus = status.isOneTotalCountIsAttained() ? + SamplingNotificationZoneStatus.COUNT_ATTAINED : + SamplingNotificationZoneStatus.NONE; + model.setSamplingNotificationZoneStatus(zoneStatus); + + } + + private String getSummaryText(IndividualObservationSamplingStatus status) { + + IndividualObservationSamplingContext individualObservationSamplingContext = status.getIndividualObservationSamplingContext(); + + CalcifiedPiecesSamplingDefinition calcifiedPiecesSamplingDefinition = status.getCalcifiedPiecesSamplingDefinition(); + + int nbForOperation = status.getSamplingCountInFishingOperation(); + int nbForZone = status.getSamplingCountInZone(); + int nbForCruise = status.getSamplingCountInCruise(); + + String nbForOperationLabel = getLabelForSamplingNumber(nbForOperation, calcifiedPiecesSamplingDefinition.getOperationLimitation()); + String nbForZoneLabel = getLabelForSamplingNumber(nbForZone, calcifiedPiecesSamplingDefinition.getZoneLimitation()); + String nbForCruiseLabel = getLabelForSamplingNumber(nbForCruise, calcifiedPiecesSamplingDefinition.getMaxByLenghtStep()); + + String key = speciesDecorator.toString(individualObservationSamplingContext.getSpecies()) + + " " + Numbers.convertFromMm(individualObservationSamplingContext.getLengthStep(), uiModel.getLengthStepCaracteristicUnit()) + + " " + uiModel.getLengthStepCaracteristicUnit(); + if (individualObservationSamplingContext.withGender()) { + key += " " + individualObservationSamplingContext.getGender().getDescription(); + } + if (individualObservationSamplingContext.withMaturity()) { + if (individualObservationSamplingContext.getMaturity()) { + key += " " + t("tutti.editSpeciesFrequencies.samplingNeeded.mature"); + } else { + key += " " + t("tutti.editSpeciesFrequencies.samplingNeeded.immature"); + } + } + + String zone = zoneDecorator.toString(individualObservationSamplingContext.getZone()); + + return t("tutti.editSpeciesFrequencies.samplingNeeded.summary", key, nbForOperationLabel, zone, nbForZoneLabel, nbForCruiseLabel); + + } + + /** + * Returns the number of selected rows. + * + * @return the number of selected rows, 0 if no rows are selected + */ + private int getSelectedRowCount(ListSelectionModel selectionModel) { + int iMin = selectionModel.getMinSelectionIndex(); + int iMax = selectionModel.getMaxSelectionIndex(); + int count = 0; + + for (int i = iMin; i <= iMax; i++) { + if (selectionModel.isSelectedIndex(i)) { + count++; + } + } + return count; + } + + + private String getLabelForSamplingNumber(int value, Integer max) { + return "<strong>" + infiniteDecorator.toString(value) + "</strong> (" + infiniteDecorator.toString(max) + ")"; + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneModel.java new file mode 100644 index 0000000..6e6547d --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneModel.java @@ -0,0 +1,44 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; + +import org.jdesktop.beans.AbstractSerializableBean; + +/** + * Created on 19/04/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class SamplingNotificationZoneModel extends AbstractSerializableBean { + + public static final String PROPERTY_SAMPLING_STATUS = "samplingNotificationZoneStatus"; + public static final String PROPERTY_SUMMARY_TEXT = "summaryText"; + + private SamplingNotificationZoneStatus samplingNotificationZoneStatus; + private String summaryText; + + public SamplingNotificationZoneStatus getSamplingNotificationZoneStatus() { + return samplingNotificationZoneStatus; + } + + public void setSamplingNotificationZoneStatus(SamplingNotificationZoneStatus samplingNotificationZoneStatus) { + Object oldValue = getSamplingNotificationZoneStatus(); + this.samplingNotificationZoneStatus = samplingNotificationZoneStatus; + firePropertyChange(PROPERTY_SAMPLING_STATUS, oldValue, samplingNotificationZoneStatus); + } + + public String getSummaryText() { + return summaryText; + } + + public void setSummaryText(String summaryText) { + Object oldValue = getSummaryText(); + this.summaryText = summaryText; + firePropertyChange(PROPERTY_SUMMARY_TEXT, oldValue, summaryText); + } + + public void reset() { + + setSamplingNotificationZoneStatus(SamplingNotificationZoneStatus.DISABLED); + setSummaryText("Aucune observation individuelle sélectionnée."); + + } +} diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneStatus.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneStatus.java new file mode 100644 index 0000000..6806581 --- /dev/null +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SamplingNotificationZoneStatus.java @@ -0,0 +1,15 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; + +/** + * Pour définir les différents états de la zone de notification des prélèvements. + * + * Created on 19/04/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public enum SamplingNotificationZoneStatus { + DISABLED, /* Not using algorithm */ + NEED_SAMPLING, /* Selected indivdual observation need sampling */ + COUNT_ATTAINED, /* Selected individual observation has attained one of his total count */ + NONE /* Nothing in special */ +} 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 592561c..d400df7 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 @@ -136,7 +136,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci protected IndividualObservationBatchTableHandler individualObservationBatchTableHandler; protected AverageWeightsHistogramHandler averageWeightsHistogramHandler; protected FrequenciesHistogramHandler frequenciesHistogramHandler; - protected IndividualObservationNotificationZoneHandler individualObservationNotificationZoneHandler; + protected SamplingNotificationZoneHandler samplingNotificationZoneHandler; protected Decorator<Caracteristic> caracteristicDecorator; protected Decorator<Caracteristic> caracteristicTipDecorator; @@ -481,7 +481,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci this.individualObservationBatchTableHandler = new IndividualObservationBatchTableHandler(ui); this.averageWeightsHistogramHandler = new AverageWeightsHistogramHandler(ui); this.frequenciesHistogramHandler = new FrequenciesHistogramHandler(ui); - this.individualObservationNotificationZoneHandler = new IndividualObservationNotificationZoneHandler(ui); + this.samplingNotificationZoneHandler = new SamplingNotificationZoneHandler(ui); listenValidatorValid(ui.getValidator(), model); @@ -649,7 +649,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci individualObservationBatchTableHandler.initObservationsCache(speciesBatch, getDataContext().getFishingOperation()); - individualObservationNotificationZoneHandler.editBatch(speciesBatch); + samplingNotificationZoneHandler.editBatch(speciesBatch); // individualObservationUICache.init(ui, frequencyEditor.getEditRow(), getDataContext().getFishingOperation(), model.getRows()); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm