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 48d0e067104b56a4afa32d552e77d17f264dcf71 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 20 02:16:51 2016 +0200 Revue du modèle de la zone de notification et de son handler --- .../frequency/SamplingNotificationZoneHandler.java | 96 +++++++++++----------- .../frequency/SamplingNotificationZoneModel.java | 12 +++ 2 files changed, 60 insertions(+), 48 deletions(-) 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 index 0587d90..9c9b2b0 100644 --- 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 @@ -8,7 +8,6 @@ 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; @@ -48,9 +47,9 @@ public class SamplingNotificationZoneHandler implements Closeable { private final JLabel samplingWarningLabel; private final JLabel samplingSummaryLabel; - private final SamplingListener samplingListener; private final ListSelectionListener listSelectionListener; private final PropertyChangeListener modelSummaryTextChanged; + private final PropertyChangeListener modelSelectedRowChanged; private final PropertyChangeListener modelStatusChanged; private final Decorator<Integer> infiniteDecorator; @@ -60,12 +59,12 @@ public class SamplingNotificationZoneHandler implements Closeable { private final Color colorHighlightInfoForeground; private final Color colorHighlightInfoBackground; - public SamplingNotificationZoneHandler(SpeciesFrequencyUI ui) { + public SamplingNotificationZoneHandler(SpeciesFrequencyUI ui, SamplingNotificationZoneModel model) { this.uiModel = ui.getModel(); this.samplingWarningLabel = ui.getSamplingWarningLabel(); this.samplingSummaryLabel = ui.getSamplingResumeLabel(); this.individualObservationTableModel = (IndividualObservationBatchTableModel) ui.getObsTable().getModel(); - this.model = new SamplingNotificationZoneModel(); + this.model = model; this.listSelectionModel = ui.getObsTable().getSelectionModel(); SpeciesFrequencyUIHandler uiHandler = ui.getHandler(); @@ -76,16 +75,6 @@ public class SamplingNotificationZoneHandler implements Closeable { 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 -> { @@ -132,6 +121,34 @@ public class SamplingNotificationZoneHandler implements Closeable { }; + this.modelSelectedRowChanged = event -> { + + IndividualObservationBatchRowModel selectedRow = (IndividualObservationBatchRowModel) event.getNewValue(); + + if (selectedRow == null) { + + whenCanNotUseSampling("Aucune observation individuelle sélectionnée."); + return; + } + + try { + + // récupération du status de l'observation individuelle + IndividualObservationSamplingStatus status = individualObservationUICache.getIndividualObservationSamplingStatus(selectedRow); + + // mise à jour de la zone de notification + 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."); + } + + }; + // Ecoute la sélection sur le tableau des observations individuelles pour rafraîchir la zone de notification this.listSelectionListener = event -> { @@ -142,7 +159,7 @@ public class SamplingNotificationZoneHandler implements Closeable { } if (source.isSelectionEmpty()) { - whenCanNotUseSampling("Aucune observation individuelle sélectionnée."); + model.setSelectedRow(null); return; } @@ -152,23 +169,7 @@ public class SamplingNotificationZoneHandler implements Closeable { } 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."); - } + model.setSelectedRow(selectedRow); }; @@ -183,13 +184,12 @@ public class SamplingNotificationZoneHandler implements Closeable { // toujours supprimer les listeners listSelectionModel.removeListSelectionListener(listSelectionListener); model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SAMPLING_STATUS, modelStatusChanged); + model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SELECTED_ROW, modelSelectedRowChanged); 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_SELECTED_ROW, modelSelectedRowChanged); model.addPropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SUMMARY_TEXT, modelSummaryTextChanged); if (!individualObservationUICache.isProtocolFilled()) { @@ -224,7 +224,6 @@ public class SamplingNotificationZoneHandler implements Closeable { model.reset(); - individualObservationUICache.getCruiseSamplingCache().addSamplingListener(samplingListener); listSelectionModel.addListSelectionListener(listSelectionListener); } @@ -233,41 +232,42 @@ public class SamplingNotificationZoneHandler implements Closeable { public void close() { listSelectionModel.removeListSelectionListener(listSelectionListener); - if (individualObservationUICache.useCruiseSamplingCache()) { - individualObservationUICache.getCruiseSamplingCache().removeSamplingListener(samplingListener); - } model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SAMPLING_STATUS, modelStatusChanged); + model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SELECTED_ROW, modelSelectedRowChanged); 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_SELECTED_ROW, modelSelectedRowChanged); model.removePropertyChangeListener(SamplingNotificationZoneModel.PROPERTY_SUMMARY_TEXT, modelSummaryTextChanged); } - private void whenSamplingNeeded(IndividualObservationSamplingStatus status) { + private void whenUpdateSummary(IndividualObservationSamplingStatus status) { model.setSummaryText(getSummaryText(status)); - model.setSamplingNotificationZoneStatus(SamplingNotificationZoneStatus.NEED_SAMPLING); - - } - private void whenUpdateSummary(IndividualObservationSamplingStatus status) { + SamplingNotificationZoneStatus zoneStatus; - model.setSummaryText(getSummaryText(status)); + if (status.isNeedSampling()) { + zoneStatus = SamplingNotificationZoneStatus.NEED_SAMPLING; + } else if (status.isOneTotalCountIsAttained()) { + zoneStatus = SamplingNotificationZoneStatus.COUNT_ATTAINED; + } else { + zoneStatus = SamplingNotificationZoneStatus.NONE; + } - SamplingNotificationZoneStatus zoneStatus = status.isOneTotalCountIsAttained() ? - SamplingNotificationZoneStatus.COUNT_ATTAINED : - SamplingNotificationZoneStatus.NONE; model.setSamplingNotificationZoneStatus(zoneStatus); } 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 index 6e6547d..1572e0d 100644 --- 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 @@ -11,7 +11,9 @@ public class SamplingNotificationZoneModel extends AbstractSerializableBean { public static final String PROPERTY_SAMPLING_STATUS = "samplingNotificationZoneStatus"; public static final String PROPERTY_SUMMARY_TEXT = "summaryText"; + public static final String PROPERTY_SELECTED_ROW = "selectedRow"; + private IndividualObservationBatchRowModel selectedRow; private SamplingNotificationZoneStatus samplingNotificationZoneStatus; private String summaryText; @@ -41,4 +43,14 @@ public class SamplingNotificationZoneModel extends AbstractSerializableBean { setSummaryText("Aucune observation individuelle sélectionnée."); } + + public IndividualObservationBatchRowModel getSelectedRow() { + return selectedRow; + } + + public void setSelectedRow(IndividualObservationBatchRowModel selectedRow) { + this.selectedRow = selectedRow; + firePropertyChange(PROPERTY_SELECTED_ROW, null /* On force la propagation de l'évènement! */, selectedRow); + } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.