Author: tchemit Date: 2013-04-16 01:10:49 +0200 (Tue, 16 Apr 2013) New Revision: 787 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/787 Log: fixes #2253: [CAPTURE] - Esp?\195?\168ces - Le changement de poids des cat?\195?\169gories parentes ?\195?\160 partir d'une cat?\195?\169gorie fille ne fonctionne pas Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategoryColumnIdentifier.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 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/SpeciesBatchRowModel.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 trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategoryColumnIdentifier.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategoryColumnIdentifier.java 2013-04-15 23:10:19 UTC (rev 786) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategoryColumnIdentifier.java 2013-04-15 23:10:49 UTC (rev 787) @@ -56,8 +56,7 @@ String weightPropertyName, SampleCategoryEnum sampleCategoryType, String headerI18nKey, - String headerTipI18nKey - ) { + String headerTipI18nKey ) { super(propertyName, headerI18nKey, headerTipI18nKey); this.weightPropertyName = weightPropertyName; this.sampleCategoryType = sampleCategoryType; @@ -70,4 +69,8 @@ public SampleCategoryEnum getSampleCategoryType() { return sampleCategoryType; } + + public String getWeightPropertyName() { + return weightPropertyName; + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-04-15 23:10:19 UTC (rev 786) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-04-15 23:10:49 UTC (rev 787) @@ -40,6 +40,7 @@ import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -47,6 +48,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Represents a species batch (i.e a row in the batch table). @@ -841,4 +843,28 @@ @Override public void setFishingOperation(FishingOperation fishingOperation) { } + + public void collectShell(Set<BenthosBatchRowModel> collectedRows) { + + if (!isBatchLeaf()) { + + for (BenthosBatchRowModel batchChild : getChildBatch()) { + collectedRows.add(batchChild); + batchChild.collectShell(collectedRows); + } + } + } + + public BenthosBatchRowModel getFirstAncestor( SampleCategory<?> entrySampleCategory) { + BenthosBatchRowModel result = this; + if (getParentBatch() != null) { + BenthosBatchRowModel parentBatch = getParentBatch(); + SampleCategory<?> parentSampleCategory = parentBatch.getSampleCategory(entrySampleCategory.getCategoryType()); + if (ObjectUtils.equals(entrySampleCategory, parentSampleCategory)) { + + result = parentBatch.getFirstAncestor( entrySampleCategory); + } + } + return result; + } } 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-15 23:10:19 UTC (rev 786) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-04-15 23:10:49 UTC (rev 787) @@ -31,6 +31,8 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryColumnIdentifier; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.table.TableColumnModelExt; import java.util.Set; @@ -45,40 +47,44 @@ private static final long serialVersionUID = 1L; + /** Logger. */ + private static final Log log = + LogFactory.getLog(BenthosBatchTableModel.class); + public static final ColumnIdentifier<BenthosBatchRowModel> SPECIES = ColumnIdentifier.newId( BenthosBatchRowModel.PROPERTY_SPECIES, n_("tutti.editBenthosBatch.table.header.species"), n_("tutti.editBenthosBatch.table.header.species.tip")); - public static final ColumnIdentifier<BenthosBatchRowModel> SORTED_UNSORTED_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<BenthosBatchRowModel> SORTED_UNSORTED_CATEGORY = SampleCategoryColumnIdentifier.newId( BenthosBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, BenthosBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY_WEIGHT, SampleCategoryEnum.sortedUnsorted, n_("tutti.editBenthosBatch.table.header.sortedUnsortedCategory"), n_("tutti.editBenthosBatch.table.header.sortedUnsortedCategory.tip")); - public static final ColumnIdentifier<BenthosBatchRowModel> SIZE_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<BenthosBatchRowModel> SIZE_CATEGORY = SampleCategoryColumnIdentifier.newId( BenthosBatchRowModel.PROPERTY_SIZE_CATEGORY, BenthosBatchRowModel.PROPERTY_SIZE_CATEGORY_WEIGHT, SampleCategoryEnum.size, n_("tutti.editBenthosBatch.table.header.sizeCategory"), n_("tutti.editBenthosBatch.table.header.sizeCategory.tip")); - public static final ColumnIdentifier<BenthosBatchRowModel> SEX_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<BenthosBatchRowModel> SEX_CATEGORY = SampleCategoryColumnIdentifier.newId( BenthosBatchRowModel.PROPERTY_SEX_CATEGORY, BenthosBatchRowModel.PROPERTY_SEX_CATEGORY_WEIGHT, SampleCategoryEnum.sex, n_("tutti.editBenthosBatch.table.header.sexCategory"), n_("tutti.editBenthosBatch.table.header.sexCategory.tip")); - public static final ColumnIdentifier<BenthosBatchRowModel> MATURITY_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<BenthosBatchRowModel> MATURITY_CATEGORY = SampleCategoryColumnIdentifier.newId( BenthosBatchRowModel.PROPERTY_MATURITY_CATEGORY, BenthosBatchRowModel.PROPERTY_MATURITY_CATEGORY_WEIGHT, SampleCategoryEnum.maturity, n_("tutti.editBenthosBatch.table.header.maturityCategory"), n_("tutti.editBenthosBatch.table.header.maturityCategory.tip")); - public static final ColumnIdentifier<BenthosBatchRowModel> AGE_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<BenthosBatchRowModel> AGE_CATEGORY = SampleCategoryColumnIdentifier.newId( BenthosBatchRowModel.PROPERTY_AGE_CATEGORY, BenthosBatchRowModel.PROPERTY_AGE_CATEGORY_WEIGHT, SampleCategoryEnum.age, @@ -122,7 +128,7 @@ * * @since 0.2 */ - protected final Set<ColumnIdentifier<BenthosBatchRowModel>> sampleCols; + protected final Set<SampleCategoryColumnIdentifier<BenthosBatchRowModel>> sampleCols; public BenthosBatchTableModel(TableColumnModelExt columnModel) { super(columnModel, false, false); @@ -140,6 +146,17 @@ sampleCols.add(AGE_CATEGORY); } + public SampleCategoryColumnIdentifier<BenthosBatchRowModel> getCategoryIdentifierForWeightProperty(String weightPropertyName) { + SampleCategoryColumnIdentifier<BenthosBatchRowModel> result = null; + for (SampleCategoryColumnIdentifier<BenthosBatchRowModel> sampleCol : sampleCols) { + if (weightPropertyName.equals(sampleCol.getWeightPropertyName())) { + result = sampleCol; + break; + } + } + return result; + } + @Override public BenthosBatchRowModel createNewRow() { BenthosBatchRowModel result = new BenthosBatchRowModel(); @@ -155,30 +172,48 @@ int columnIndex, ColumnIdentifier<BenthosBatchRowModel> propertyName, BenthosBatchRowModel entry) { + /* if (sampleCols.contains(propertyName)) { ((SampleCategoryColumnIdentifier<BenthosBatchRowModel>) propertyName).setWeightValue(entry, aValue); } else { super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); } + */ + if (sampleCols.contains(propertyName)) { -// if (propertyName == COMPUTED_NUMBER) { -// -// // update also other columns -// fireTableCellUpdated(rowIndex, COMPUTED_WEIGHT); -// -// } else if (propertyName == COMPUTED_WEIGHT) { -// -// // update also other columns -// fireTableCellUpdated(rowIndex, COMPUTED_NUMBER); -// } - } + SampleCategoryColumnIdentifier<BenthosBatchRowModel> sampleCategoryColumnIdentifier = (SampleCategoryColumnIdentifier<BenthosBatchRowModel>) propertyName; + sampleCategoryColumnIdentifier.setWeightValue(entry, aValue); - public void updateSamplingRatio(Set<BenthosBatchRowModel> rows) { -// for (BenthosBatchRowModel row : rows) { -// int rowIndex = getRows().indexOf(row); -// fireTableCellUpdated(rowIndex, SAMPLE_WEIGHT, SAMPLING_RATIO); -// } + // must find out first ancestor with this category + SampleCategoryEnum sampleCategoryType = sampleCategoryColumnIdentifier.getSampleCategoryType(); + if (log.isDebugEnabled()) { + log.debug("Sample category: " + sampleCategoryType + " modified at row: " + rowIndex); + } + SampleCategory<?> sampleCategory = entry.getSampleCategory(sampleCategoryType); + BenthosBatchRowModel firstAncestor = entry.getFirstAncestor(sampleCategory); + + int firstRowIndex = getRowIndex(firstAncestor); + if (log.isDebugEnabled()) { + log.debug("First ancestor row: " + firstRowIndex); + } + + // must save this row now + + // get shell of the ancestor + Set<BenthosBatchRowModel> shell = Sets.newHashSet(); + firstAncestor.collectShell(shell); + + for (BenthosBatchRowModel batchRowModel : shell) { + int currentRowIndex = getRowIndex(batchRowModel); + if (log.isDebugEnabled()) { + log.debug("Update shell row: " + currentRowIndex); + } + fireTableCellUpdated(currentRowIndex, columnIndex); + } + } else { + super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); + } } @Override 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-15 23:10:19 UTC (rev 786) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-04-15 23:10:49 UTC (rev 787) @@ -42,6 +42,7 @@ 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.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryColumnIdentifier; import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryComponent; import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.create.CreateBenthosBatchUI; @@ -120,6 +121,13 @@ BenthosBatchRowModel.PROPERTY_MATURITY_CATEGORY_WEIGHT, BenthosBatchRowModel.PROPERTY_AGE_CATEGORY_WEIGHT); + public static final Set<String> SAMPLING_WEIGHT_PROPERTIES = Sets.newHashSet( + BenthosBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY_WEIGHT, + BenthosBatchRowModel.PROPERTY_SIZE_CATEGORY_WEIGHT, + BenthosBatchRowModel.PROPERTY_SEX_CATEGORY_WEIGHT, + BenthosBatchRowModel.PROPERTY_MATURITY_CATEGORY_WEIGHT, + BenthosBatchRowModel.PROPERTY_AGE_CATEGORY_WEIGHT); + private final EnumMap<TableViewMode, RowFilter<BenthosBatchTableModel, Integer>> tableFilters; public BenthosBatchUIHandler(TuttiUI<?, ?> parentUi, @@ -278,8 +286,45 @@ Object oldValue, Object newValue) { - if (SAMPLING_PROPERTIES.contains(propertyName)) { + 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); + + SampleCategoryEnum sampleCategoryType = sampleCategoryColumnIdentifier.getSampleCategoryType(); + SampleCategory<?> sampleCategory = row.getSampleCategory(sampleCategoryType); + BenthosBatchRowModel firstAncestorRow = row.getFirstAncestor(sampleCategory); + int firstAncestorIndex = tableModel.getRowIndex(firstAncestorRow); + if (rowIndex != firstAncestorIndex) { + + // ancestor is not this row + // then only save ancestor + + if (log.isInfoEnabled()) { + log.info("Sample category " + sampleCategoryType + + " weight was modified, First ancestor row: " + + firstAncestorIndex + " will save it"); + } + saveRow(firstAncestorRow); + + // when row valid state has changed, recompute action enabled states + recomputeBatchActionEnable(); + + cleanrRowMonitor(); + + return; + } + + // modified sample weight is a leaf + // will save it after + + } else if (SAMPLING_PROPERTIES.contains(propertyName)) { + // species has changed, recompute valid property recomputeRowValidState(row); } @@ -290,6 +335,25 @@ 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) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-04-15 23:10:19 UTC (rev 786) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-04-15 23:10:49 UTC (rev 787) @@ -40,6 +40,7 @@ import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -47,6 +48,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; /** * Represents a species batch (i.e a row in the batch table). @@ -800,4 +802,28 @@ this.computedOrNotWeight = computedOrNotWeight; } + + public void collectShell(Set<SpeciesBatchRowModel> collectedRows) { + + if (!isBatchLeaf()) { + + for (SpeciesBatchRowModel batchChild : getChildBatch()) { + collectedRows.add(batchChild); + batchChild.collectShell(collectedRows); + } + } + } + + public SpeciesBatchRowModel getFirstAncestor( SampleCategory<?> entrySampleCategory) { + SpeciesBatchRowModel result = this; + if (getParentBatch() != null) { + SpeciesBatchRowModel parentBatch = getParentBatch(); + SampleCategory<?> parentSampleCategory = parentBatch.getSampleCategory(entrySampleCategory.getCategoryType()); + if (ObjectUtils.equals(entrySampleCategory, parentSampleCategory)) { + + result = parentBatch.getFirstAncestor( entrySampleCategory); + } + } + return result; + } } 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-15 23:10:19 UTC (rev 786) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-04-15 23:10:49 UTC (rev 787) @@ -31,6 +31,8 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryColumnIdentifier; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.table.TableColumnModelExt; import java.util.Set; @@ -45,40 +47,44 @@ private static final long serialVersionUID = 1L; + /** Logger. */ + private static final Log log = + LogFactory.getLog(SpeciesBatchTableModel.class); + public static final ColumnIdentifier<SpeciesBatchRowModel> SPECIES = ColumnIdentifier.newId( SpeciesBatchRowModel.PROPERTY_SPECIES, n_("tutti.editSpeciesBatch.table.header.species"), n_("tutti.editSpeciesBatch.table.header.species")); - public static final ColumnIdentifier<SpeciesBatchRowModel> SORTED_UNSORTED_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<SpeciesBatchRowModel> SORTED_UNSORTED_CATEGORY = SampleCategoryColumnIdentifier.newId( SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY, SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY_WEIGHT, SampleCategoryEnum.sortedUnsorted, n_("tutti.editSpeciesBatch.table.header.sortedUnsortedCategory"), n_("tutti.editSpeciesBatch.table.header.sortedUnsortedCategory")); - public static final ColumnIdentifier<SpeciesBatchRowModel> SIZE_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<SpeciesBatchRowModel> SIZE_CATEGORY = SampleCategoryColumnIdentifier.newId( SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY, SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY_WEIGHT, SampleCategoryEnum.size, n_("tutti.editSpeciesBatch.table.header.sizeCategory"), n_("tutti.editSpeciesBatch.table.header.sizeCategory")); - public static final ColumnIdentifier<SpeciesBatchRowModel> SEX_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<SpeciesBatchRowModel> SEX_CATEGORY = SampleCategoryColumnIdentifier.newId( SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY, SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY_WEIGHT, SampleCategoryEnum.sex, n_("tutti.editSpeciesBatch.table.header.sexCategory"), n_("tutti.editSpeciesBatch.table.header.sexCategory")); - public static final ColumnIdentifier<SpeciesBatchRowModel> MATURITY_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<SpeciesBatchRowModel> MATURITY_CATEGORY = SampleCategoryColumnIdentifier.newId( SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY, SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY_WEIGHT, SampleCategoryEnum.maturity, n_("tutti.editSpeciesBatch.table.header.maturityCategory"), n_("tutti.editSpeciesBatch.table.header.maturityCategory")); - public static final ColumnIdentifier<SpeciesBatchRowModel> AGE_CATEGORY = SampleCategoryColumnIdentifier.newId( + public static final SampleCategoryColumnIdentifier<SpeciesBatchRowModel> AGE_CATEGORY = SampleCategoryColumnIdentifier.newId( SpeciesBatchRowModel.PROPERTY_AGE_CATEGORY, SpeciesBatchRowModel.PROPERTY_AGE_CATEGORY_WEIGHT, SampleCategoryEnum.age, @@ -122,7 +128,7 @@ * * @since 0.2 */ - protected final Set<ColumnIdentifier<SpeciesBatchRowModel>> sampleCols; + protected final Set<SampleCategoryColumnIdentifier<SpeciesBatchRowModel>> sampleCols; public SpeciesBatchTableModel(TableColumnModelExt columnModel) { super(columnModel, false, false); @@ -140,6 +146,17 @@ sampleCols.add(AGE_CATEGORY); } + public SampleCategoryColumnIdentifier<SpeciesBatchRowModel> getCategoryIdentifierForWeightProperty(String weightPropertyName) { + SampleCategoryColumnIdentifier<SpeciesBatchRowModel> result = null; + for (SampleCategoryColumnIdentifier<SpeciesBatchRowModel> sampleCol : sampleCols) { + if (weightPropertyName.equals(sampleCol.getWeightPropertyName())) { + result = sampleCol; + break; + } + } + return result; + } + @Override public SpeciesBatchRowModel createNewRow() { SpeciesBatchRowModel result = new SpeciesBatchRowModel(); @@ -157,30 +174,54 @@ SpeciesBatchRowModel entry) { if (sampleCols.contains(propertyName)) { - ((SampleCategoryColumnIdentifier<SpeciesBatchRowModel>) propertyName).setWeightValue(entry, aValue); + SampleCategoryColumnIdentifier<SpeciesBatchRowModel> sampleCategoryColumnIdentifier = (SampleCategoryColumnIdentifier<SpeciesBatchRowModel>) propertyName; + sampleCategoryColumnIdentifier.setWeightValue(entry, aValue); + + // must find out first ancestor with this category + SampleCategoryEnum sampleCategoryType = sampleCategoryColumnIdentifier.getSampleCategoryType(); + if (log.isDebugEnabled()) { + log.debug("Sample category: " + sampleCategoryType + " modified at row: " + rowIndex); + } + SampleCategory<?> sampleCategory = entry.getSampleCategory(sampleCategoryType); + SpeciesBatchRowModel firstAncestor = entry.getFirstAncestor(sampleCategory); + + int firstRowIndex = getRowIndex(firstAncestor); + if (log.isDebugEnabled()) { + log.debug("First ancestor row: " + firstRowIndex); + } + + // must save this row now + + // get shell of the ancestor + Set<SpeciesBatchRowModel> shell = Sets.newHashSet(); + firstAncestor.collectShell(shell); + + for (SpeciesBatchRowModel batchRowModel : shell) { + int currentRowIndex = getRowIndex(batchRowModel); + if (log.isDebugEnabled()) { + log.debug("Update shell row: " + currentRowIndex); + } + fireTableCellUpdated(currentRowIndex, columnIndex); + } } else { super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); } + } -// if (propertyName == COMPUTED_NUMBER) { +// @Override +// public void setValueAt(Object aValue, +// int rowIndex, +// int columnIndex, +// ColumnIdentifier<SpeciesBatchRowModel> propertyName, +// SpeciesBatchRowModel entry) { +// if (sampleCols.contains(propertyName)) { // -// // update also other columns -// fireTableCellUpdated(rowIndex, COMPUTED_WEIGHT); -// -// } else if (propertyName == COMPUTED_WEIGHT) { -// -// // update also other columns -// fireTableCellUpdated(rowIndex, COMPUTED_NUMBER); +// ((SampleCategoryColumnIdentifier<SpeciesBatchRowModel>) propertyName).setWeightValue(entry, aValue); +// } else { +// super.setValueAt(aValue, rowIndex, columnIndex, propertyName, entry); // } - } +// } - public void updateSamplingRatio(Set<SpeciesBatchRowModel> rows) { -// for (SpeciesBatchRowModel row : rows) { -// int rowIndex = getRows().indexOf(row); -// fireTableCellUpdated(rowIndex, SAMPLE_WEIGHT, SAMPLING_RATIO); -// } - } - @Override protected boolean isCellEditable(int rowIndex, int columnIndex, 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-15 23:10:19 UTC (rev 786) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-04-15 23:10:49 UTC (rev 787) @@ -45,6 +45,7 @@ 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.EditCatchesUIModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryColumnIdentifier; import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryComponent; import fr.ifremer.tutti.ui.swing.content.operation.catches.TableViewMode; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.create.CreateSpeciesBatchUI; @@ -122,6 +123,13 @@ SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY_WEIGHT, SpeciesBatchRowModel.PROPERTY_AGE_CATEGORY_WEIGHT); + public static final Set<String> SAMPLING_WEIGHT_PROPERTIES = Sets.newHashSet( + SpeciesBatchRowModel.PROPERTY_SORTED_UNSORTED_CATEGORY_WEIGHT, + SpeciesBatchRowModel.PROPERTY_SIZE_CATEGORY_WEIGHT, + SpeciesBatchRowModel.PROPERTY_SEX_CATEGORY_WEIGHT, + SpeciesBatchRowModel.PROPERTY_MATURITY_CATEGORY_WEIGHT, + SpeciesBatchRowModel.PROPERTY_AGE_CATEGORY_WEIGHT); + private final EnumMap<TableViewMode, RowFilter<SpeciesBatchTableModel, Integer>> tableFilters; public SpeciesBatchUIHandler(TuttiUI<?, ?> parentUi, @@ -302,8 +310,45 @@ Object oldValue, Object newValue) { - if (SAMPLING_PROPERTIES.contains(propertyName)) { + 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); + + SampleCategoryEnum sampleCategoryType = sampleCategoryColumnIdentifier.getSampleCategoryType(); + SampleCategory<?> sampleCategory = row.getSampleCategory(sampleCategoryType); + SpeciesBatchRowModel firstAncestorRow = row.getFirstAncestor(sampleCategory); + int firstAncestorIndex = tableModel.getRowIndex(firstAncestorRow); + if (rowIndex != firstAncestorIndex) { + + // ancestor is not this row + // then only save ancestor + + if (log.isInfoEnabled()) { + log.info("Sample category " + sampleCategoryType + + " weight was modified, First ancestor row: " + + firstAncestorIndex + " will save it"); + } + saveRow(firstAncestorRow); + + // when row valid state has changed, recompute action enabled states + recomputeBatchActionEnable(); + + cleanrRowMonitor(); + + return; + } + + // modified sample weight is a leaf + // will save it after + + } else if (SAMPLING_PROPERTIES.contains(propertyName)) { + // species has changed, recompute valid property recomputeRowValidState(row); } @@ -314,6 +359,25 @@ recomputeBatchActionEnable(); } +// @Override +// protected void onRowModified(int rowIndex, +// SpeciesBatchRowModel 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<SpeciesBatchRowModel> rowMonitor, SpeciesBatchRowModel row) { @@ -339,7 +403,7 @@ } } else { - //FIXME See how to delete rows ? Or moreover how to save tehem... + //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()); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2013-04-15 23:10:19 UTC (rev 786) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2013-04-15 23:10:49 UTC (rev 787) @@ -510,6 +510,11 @@ } } + + protected void cleanrRowMonitor() { + rowMonitor.clearModified(); + } + protected final void recomputeRowValidState(R row) { // recompute row valid state