Author: tchemit Date: 2013-09-25 12:48:17 +0200 (Wed, 25 Sep 2013) New Revision: 1222 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1222 Log: refs #3315: [CAPTURE] pouvoir modifier la valeur de la cat?\195?\169gorisation d'un lot (fix auto save) 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/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 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-09-25 07:22:58 UTC (rev 1221) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-09-25 10:48:17 UTC (rev 1222) @@ -474,6 +474,12 @@ //-- Other properties --// //------------------------------------------------------------------------// + public BenthosBatchRowModel getFirstAncestor(Integer sampleCategoryId) { + SampleCategory<?> sampleCategory = getSampleCategoryById(sampleCategoryId); + BenthosBatchRowModel firstAncestor = getFirstAncestor(sampleCategory); + return firstAncestor; + } + @Override public boolean isSpeciesToConfirm() { return speciesToConfirm; 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-09-25 07:22:58 UTC (rev 1221) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java 2013-09-25 10:48:17 UTC (rev 1222) @@ -265,30 +265,25 @@ } /** - * Update the sample category value of all childs of the given {@code row}. + * Update the sample category value of the given {@code row}. * - * @param row the row to walk through + * @param row the row to walk through * @param columnIndex index of the column where the sample category is * @param newValue new sample category value to set * @since 2.6 */ public void updateSampleCategorieValue(BenthosBatchRowModel row, - int sampleCategoryId, int columnIndex, Serializable newValue) { SampleCategoryColumnIdentifier<BenthosBatchRowModel> identifier = (SampleCategoryColumnIdentifier<BenthosBatchRowModel>) getIdentifier(columnIndex); - // get the first ancestor using the category to update - SampleCategory<?> sampleCategory = row.getSampleCategoryById(sampleCategoryId); - BenthosBatchRowModel firstAncestor = row.getFirstAncestor(sampleCategory); - // set category value - identifier.setCategoryValue(firstAncestor, newValue); + identifier.setCategoryValue(row, newValue); // update row shell - updateShell(firstAncestor, columnIndex); + updateShell(row, columnIndex); } protected void updateShell(BenthosBatchRowModel entry, int columnIndex) { 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-09-25 07:22:58 UTC (rev 1221) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-09-25 10:48:17 UTC (rev 1222) @@ -518,9 +518,13 @@ SampleCategoryModelEntry category = sampleCategoryModel.getCategoryById(sampleCategoryId); + // get the first ancestor row using this category + BenthosBatchRowModel firstAncestorRow = + row.getFirstAncestor(sampleCategoryId); + // get all used values for this category Set<Serializable> used = getSampleUsedValues( - row, sampleCategoryId); + firstAncestorRow, sampleCategoryId); if (category.getCaracteristic().isNumericType()) { @@ -901,11 +905,15 @@ // get his sample category Integer sampleCategoryId = tableModel.getSampleCategoryId(columnIndex); - SampleCategoryModelEntry sampleCategory = sampleCategoryModel.getCategoryById(sampleCategoryId); - Caracteristic caracteristic = sampleCategory.getCaracteristic(); + SampleCategoryModelEntry sampleCategoryEntry = sampleCategoryModel.getCategoryById(sampleCategoryId); + Caracteristic caracteristic = sampleCategoryEntry.getCaracteristic(); + // get the first ancestor row using this category + BenthosBatchRowModel firstAncestorRow = + selectedRow.getFirstAncestor(sampleCategoryId); + // get used values - Set<Serializable> usedValues = getSampleUsedValues(selectedRow, + Set<Serializable> usedValues = getSampleUsedValues(firstAncestorRow, sampleCategoryId); // get the new selected value for this category @@ -979,10 +987,12 @@ if (selectedItem != null) { // update rows values - tableModel.updateSampleCategorieValue(selectedRow, - sampleCategoryId, + tableModel.updateSampleCategorieValue(firstAncestorRow, columnIndex, selectedItem); + + // save the first ancestor row with the modified category value + saveRow(firstAncestorRow); } } @@ -1364,16 +1374,12 @@ protected Set<Serializable> getSampleUsedValues(BenthosBatchRowModel row, int sampleCategoryId) { - // get the first ancestor for the sample category - SampleCategory<?> sampleCategory = row.getSampleCategoryById(sampleCategoryId); - BenthosBatchRowModel firstAncestor = row.getFirstAncestor(sampleCategory); - Set<Serializable> usedValues = Sets.newHashSet(); List<BenthosBatchRowModel> childs; - if (firstAncestor.isBatchRoot()) { + if (row.isBatchRoot()) { // on a root must take all his brothers (but have no common ancestor...) - Species species = firstAncestor.getSpecies(); + Species species = row.getSpecies(); childs = Lists.newArrayList(); for (BenthosBatchRowModel rowToScan : getModel().getRows()) { if (rowToScan.isBatchRoot() && species.equals(rowToScan.getSpecies())) { @@ -1382,7 +1388,7 @@ } } else { // on a son, must take all the brother directly from his father - BenthosBatchRowModel parentBatch = firstAncestor.getParentBatch(); + BenthosBatchRowModel parentBatch = row.getParentBatch(); childs = parentBatch.getChildBatch(); } 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-09-25 07:22:58 UTC (rev 1221) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-09-25 10:48:17 UTC (rev 1222) @@ -576,6 +576,12 @@ //-- Other properties --// //------------------------------------------------------------------------// + public SpeciesBatchRowModel getFirstAncestor(Integer sampleCategoryId) { + SampleCategory<?> sampleCategory = getSampleCategoryById(sampleCategoryId); + SpeciesBatchRowModel firstAncestor = getFirstAncestor(sampleCategory); + return firstAncestor; + } + public List<SpeciesBatchRowModel> getChildBatch() { return childBatch; } 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-09-25 07:22:58 UTC (rev 1221) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-09-25 10:48:17 UTC (rev 1222) @@ -264,7 +264,7 @@ } /** - * Update the sample category value of all childs of the given {@code row}. + * Update the sample category value of the given {@code row}. * * @param row the row to walk through * @param columnIndex index of the column where the sample category is @@ -272,22 +272,17 @@ * @since 2.6 */ public void updateSampleCategorieValue(SpeciesBatchRowModel row, - int sampleCategoryId, int columnIndex, Serializable newValue) { SampleCategoryColumnIdentifier<SpeciesBatchRowModel> identifier = (SampleCategoryColumnIdentifier<SpeciesBatchRowModel>) getIdentifier(columnIndex); - // get the first ancestor using the category to update - SampleCategory<?> sampleCategory = row.getSampleCategoryById(sampleCategoryId); - SpeciesBatchRowModel firstAncestor = row.getFirstAncestor(sampleCategory); - // set category value - identifier.setCategoryValue(firstAncestor, newValue); + identifier.setCategoryValue(row, newValue); // update row shell - updateShell(firstAncestor, columnIndex); + updateShell(row, columnIndex); } protected void updateShell(SpeciesBatchRowModel entry, 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-09-25 07:22:58 UTC (rev 1221) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-09-25 10:48:17 UTC (rev 1222) @@ -521,9 +521,13 @@ SampleCategoryModelEntry category = sampleCategoryModel.getCategoryById(sampleCategoryId); + // get the first ancestor row using this category + SpeciesBatchRowModel firstAncestorRow = + row.getFirstAncestor(sampleCategoryId); + // get all used values for this category Set<Serializable> used = getSampleUsedValues( - row, sampleCategoryId); + firstAncestorRow, sampleCategoryId); if (category.getCaracteristic().isNumericType()) { @@ -903,11 +907,15 @@ // get his sample category Integer sampleCategoryId = tableModel.getSampleCategoryId(columnIndex); - SampleCategoryModelEntry sampleCategory = sampleCategoryModel.getCategoryById(sampleCategoryId); - Caracteristic caracteristic = sampleCategory.getCaracteristic(); + SampleCategoryModelEntry sampleCategoryEntry = sampleCategoryModel.getCategoryById(sampleCategoryId); + Caracteristic caracteristic = sampleCategoryEntry.getCaracteristic(); - // get used values - Set<Serializable> usedValues = getSampleUsedValues(selectedRow, + // get the first ancestor row using this category + SpeciesBatchRowModel firstAncestorRow = + selectedRow.getFirstAncestor(sampleCategoryId); + + // get used values of the category + Set<Serializable> usedValues = getSampleUsedValues(firstAncestorRow, sampleCategoryId); // get the new selected value for this category @@ -981,10 +989,12 @@ if (selectedItem != null) { // update rows values - tableModel.updateSampleCategorieValue(selectedRow, - sampleCategoryId, + tableModel.updateSampleCategorieValue(firstAncestorRow, columnIndex, selectedItem); + + // save the first ancestor row with the modified category value + saveRow(firstAncestorRow); } } @@ -1367,16 +1377,16 @@ protected Set<Serializable> getSampleUsedValues(SpeciesBatchRowModel row, int sampleCategoryId) { - // get the first ancestor for the sample category - SampleCategory<?> sampleCategory = row.getSampleCategoryById(sampleCategoryId); - SpeciesBatchRowModel firstAncestor = row.getFirstAncestor(sampleCategory); +// // get the first ancestor for the sample category +// SampleCategory<?> sampleCategory = row.getSampleCategoryById(sampleCategoryId); +// SpeciesBatchRowModel firstAncestor = row.getFirstAncestor(sampleCategory); Set<Serializable> usedValues = Sets.newHashSet(); List<SpeciesBatchRowModel> childs; - if (firstAncestor.isBatchRoot()) { + if (row.isBatchRoot()) { // on a root must take all his brothers (but have no common ancestor...) - Species species = firstAncestor.getSpecies(); + Species species = row.getSpecies(); childs = Lists.newArrayList(); for (SpeciesBatchRowModel rowToScan : getModel().getRows()) { if (rowToScan.isBatchRoot() && species.equals(rowToScan.getSpecies())) { @@ -1385,7 +1395,7 @@ } } else { // on a son, must take all the brother directly from his father - SpeciesBatchRowModel parentBatch = firstAncestor.getParentBatch(); + SpeciesBatchRowModel parentBatch = row.getParentBatch(); childs = parentBatch.getChildBatch(); }