Author: kmorin Date: 2013-04-20 14:17:16 +0200 (Sat, 20 Apr 2013) New Revision: 836 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/836 Log: fixes #1987 [PROTOCOLE] - Gestion des contr?\195?\180les/infos obligatoires en validation Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-04-20 11:38:50 UTC (rev 835) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-04-20 12:17:16 UTC (rev 836) @@ -230,7 +230,7 @@ // must have filled a species to edit this column BenthosBatchRowModel entry = getEntry(rowIndex); - result = entry.isValid() && entry.isBatchLeaf(); + result = entry.isBatchLeaf(); } else if (sampleCols.contains(propertyName)) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-04-20 11:38:50 UTC (rev 835) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-04-20 12:17:16 UTC (rev 836) @@ -35,9 +35,12 @@ import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; +import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.operation.AbstractTuttiBatchTableUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; @@ -275,7 +278,30 @@ // a row is valid if species category is not empty and valid // then if any of none empty category is valid - boolean result = row.getSpecies() != null; + Species species = row.getSpecies(); + boolean result = species != null; + if (result && row.isBatchLeaf()) { + if (TuttiUIContext.VALIDATION_CONTEXT_VALIDATE.equals(getContext().getValidationContext())) { + TuttiProtocol protocol = getDataContext().getProtocol(); + if (protocol != null) { + List<SpeciesProtocol> speciesProtocols = protocol.getBenthos(); + for (SpeciesProtocol speciesProtocol : speciesProtocols) { + if (species.getReferenceTaxonId().equals( + speciesProtocol.getSpeciesReferenceTaxonId())) { + + result = (!speciesProtocol.isSizeEnabled() || row.getSizeCategoryValue() != null) + && (!speciesProtocol.isSexEnabled() || row.getSexCategoryValue() != null) + && (!speciesProtocol.isMaturityEnabled() || row.getMaturityCategoryValue() != null) + && (!speciesProtocol.isAgeEnabled() || row.getAgeCategoryValue() != null) + && (!speciesProtocol.isCountIfNoFrequencyEnabled() + || !CollectionUtils.isEmpty(row.getFrequency()) + || row.getNumber() != null); + } + } + } + } + } + return result; } @@ -286,13 +312,13 @@ Object oldValue, Object newValue) { + recomputeRowValidState(row); + if (SAMPLING_WEIGHT_PROPERTIES.contains(propertyName)) { // sampling category weight has changed, must then save the top // ancestor row - recomputeRowValidState(row); - BenthosBatchTableModel tableModel = getTableModel(); SampleCategoryColumnIdentifier<BenthosBatchRowModel> sampleCategoryColumnIdentifier = tableModel.getCategoryIdentifierForWeightProperty(propertyName); @@ -322,11 +348,6 @@ // modified sample weight is a leaf // will save it after - - } else if (SAMPLING_PROPERTIES.contains(propertyName)) { - - // species has changed, recompute valid property - recomputeRowValidState(row); } saveSelectedRowIfNeeded(); @@ -335,54 +356,27 @@ recomputeBatchActionEnable(); } -// @Override -// protected void onRowModified(int rowIndex, -// BenthosBatchRowModel row, -// String propertyName, -// Object oldValue, -// Object newValue) { -// -// if (SAMPLING_PROPERTIES.contains(propertyName)) { -// -// // species has changed, recompute valid property -// recomputeRowValidState(row); -// } -// -// saveSelectedRowIfNeeded(); -// -// // when row valid state has changed, recompute action enabled states -// recomputeBatchActionEnable(); -// } - @Override protected void saveSelectedRowIfRequired(TuttiBeanMonitor<BenthosBatchRowModel> rowMonitor, BenthosBatchRowModel row) { - if (row.isValid()) { - // there is a valid bean attached to the monitor - if (rowMonitor.wasModified()) { + // there is a valid bean attached to the monitor + if (rowMonitor.wasModified()) { - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + row + " was modified, will save it"); - } + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + row + " was modified, will save it"); + } - showInformationMessage( - "[ Captures - Benthos ] " + - "Sauvegarde des modifications de " + row + '.'); + showInformationMessage( + "[ Captures - Benthos ] " + + "Sauvegarde des modifications de " + row + '.'); - rowMonitor.setBean(null); - saveRow(row); - rowMonitor.setBean(row); + rowMonitor.setBean(null); + saveRow(row); + rowMonitor.setBean(row); - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - //FIXME See how to delete rows ? Or moreover how to save tehem... - if (log.isWarnEnabled()) { - log.warn("Will not remove not valid speciesBatch: " + row.getId()); - } + // clear modified flag on the monitor + rowMonitor.clearModified(); } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-04-20 11:38:50 UTC (rev 835) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-04-20 12:17:16 UTC (rev 836) @@ -236,7 +236,7 @@ // must have filled a species to edit this column SpeciesBatchRowModel entry = getEntry(rowIndex); - result = entry.isValid() && entry.isBatchLeaf(); + result = entry.isBatchLeaf(); } else if (sampleCols.contains(propertyName)) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-04-20 11:38:50 UTC (rev 835) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-04-20 12:17:16 UTC (rev 836) @@ -278,7 +278,7 @@ // then if any of none empty category is valid Species species = row.getSpecies(); boolean result = species != null; - if (result) { + if (result && row.isBatchLeaf()) { if (TuttiUIContext.VALIDATION_CONTEXT_VALIDATE.equals(getContext().getValidationContext())) { TuttiProtocol protocol = getDataContext().getProtocol(); if (protocol != null) { @@ -310,13 +310,13 @@ Object oldValue, Object newValue) { + recomputeRowValidState(row); + if (SAMPLING_WEIGHT_PROPERTIES.contains(propertyName)) { // sampling category weight has changed, must then save the top // ancestor row - recomputeRowValidState(row); - SpeciesBatchTableModel tableModel = getTableModel(); SampleCategoryColumnIdentifier<SpeciesBatchRowModel> sampleCategoryColumnIdentifier = tableModel.getCategoryIdentifierForWeightProperty(propertyName); @@ -346,11 +346,6 @@ // modified sample weight is a leaf // will save it after - - } else if (SAMPLING_PROPERTIES.contains(propertyName)) { - - // species has changed, recompute valid property - recomputeRowValidState(row); } saveSelectedRowIfNeeded(); @@ -381,32 +376,24 @@ @Override protected void saveSelectedRowIfRequired(TuttiBeanMonitor<SpeciesBatchRowModel> rowMonitor, SpeciesBatchRowModel row) { - if (row.isValid()) { - // there is a valid bean attached to the monitor - if (rowMonitor.wasModified()) { + // there is a valid bean attached to the monitor + if (rowMonitor.wasModified()) { - // monitored bean was modified, save it - if (log.isInfoEnabled()) { - log.info("Row " + row + " was modified, will save it"); - } + // monitored bean was modified, save it + if (log.isInfoEnabled()) { + log.info("Row " + row + " was modified, will save it"); + } - showInformationMessage( - "[ Captures - Espèces ] " + - "Sauvegarde des modifications de " + row + '.'); + showInformationMessage( + "[ Captures - Espèces ] " + + "Sauvegarde des modifications de " + row + '.'); - rowMonitor.setBean(null); - saveRow(row); - rowMonitor.setBean(row); + rowMonitor.setBean(null); + saveRow(row); + rowMonitor.setBean(row); - // clear modified flag on the monitor - rowMonitor.clearModified(); - } - } else { - - //FIXME See how to delete rows ? Or moreover how to save them... - if (log.isWarnEnabled()) { - log.warn("Will not remove not valid speciesBatch: " + row.getId()); - } + // clear modified flag on the monitor + rowMonitor.clearModified(); } }