branch develop updated (0c7254c -> cb1949a)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See http://git.codelutin.com/tutti.git from 0c7254c refs #6916 le bouton de choix des synonymes d'espèce ne capture plus le focus new cb1949a on ne modifie pas le modèle tant qu'on est dans le thread de l'action longue (refs #7020) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit cb1949a028d1331bed3a4f12d7435eee24cedd49 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 18:38:39 2015 +0200 on ne modifie pas le modèle tant qu'on est dans le thread de l'action longue (refs #7020) Summary of changes: .../catches/actions/ComputeBatchWeightsAction.java | 366 ++++++++++++++------- .../catches/benthos/BenthosBatchTableModel.java | 8 +- .../catches/species/SpeciesBatchTableModel.java | 8 +- 3 files changed, 266 insertions(+), 116 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit cb1949a028d1331bed3a4f12d7435eee24cedd49 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 27 18:38:39 2015 +0200 on ne modifie pas le modèle tant qu'on est dans le thread de l'action longue (refs #7020) --- .../catches/actions/ComputeBatchWeightsAction.java | 366 ++++++++++++++------- .../catches/benthos/BenthosBatchTableModel.java | 8 +- .../catches/species/SpeciesBatchTableModel.java | 8 +- 3 files changed, 266 insertions(+), 116 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java index 672cf03..cf0b659 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java @@ -39,19 +39,27 @@ import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport; 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.SampleCategoryAble; +import fr.ifremer.tutti.ui.swing.content.operation.catches.SampleCategoryColumnIdentifier; import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesBatchNaturalOrderComparator; import fr.ifremer.tutti.ui.swing.content.operation.catches.SpeciesSortMode; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchTableModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchTableModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; -import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.util.Numbers; +import jaxx.runtime.swing.JTables; +import org.jdesktop.swingx.JXTable; +import org.jdesktop.swingx.table.TableColumnExt; +import org.nuiton.jaxx.application.swing.table.ColumnIdentifier; import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; +import javax.swing.table.TableColumn; import java.util.List; +import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -63,13 +71,32 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo protected final WeightCleaningService cleaningService; + protected List<SpeciesBatchRowModel> speciesBatchRows; + + protected List<BenthosBatchRowModel> benthosBatchRows; + + protected CatchBatch catchBatch; + + protected Boolean modified; + + protected Integer tabInError; + public ComputeBatchWeightsAction(EditCatchesUIHandler handler) { super(handler, true); - cleaningService = getContext().getWeightCleaningService(); + this.cleaningService = getContext().getWeightCleaningService(); } @Override public boolean prepareAction() throws Exception { + + // Clean internal states + + speciesBatchRows = null; + benthosBatchRows = null; + catchBatch = null; + modified = null; + tabInError = null; + boolean doAction = super.prepareAction(); if (doAction) { @@ -107,104 +134,42 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo WeightComputingService weightComputingService = getContext().getWeightComputingService(); EditCatchesUIModel model = getModel(); - model.setLoadingData(true); + String operationId = model.getFishingOperation().getId(); // --------- // Compute species batches // --------- - BatchContainer<SpeciesBatch> computedSpeciesBatches; Float totalSpeciesSortedWeight; - String operationId = model.getFishingOperation().getId(); + BatchContainer<SpeciesBatch> computedSpeciesBatches; + try { - computedSpeciesBatches = - weightComputingService.getComputedSpeciesBatches(operationId); + computedSpeciesBatches = weightComputingService.getComputedSpeciesBatches(operationId); totalSpeciesSortedWeight = computeSpeciesBatches(persistenceService, computedSpeciesBatches); } catch (TuttiWeightComputingException e) { - getUI().getTabPane().setSelectedIndex(1); - - int index = e.getIndex(); - SpeciesBatchUIModel speciesBatchUIModel = getUI().getSpeciesTabContent().getModel(); - - SpeciesBatchRowModel row; - - if (speciesBatchUIModel.getSpeciesSortMode() != SpeciesSortMode.NONE) { - - // must resort rows in natural order (in service we use this order) - List<SpeciesBatchRowModel> rows = Lists.newArrayList(speciesBatchUIModel.getRows()); - SpeciesBatchNaturalOrderComparator.sort(rows); - // get the row - row = rows.get(index); - // get the correct rowIndex in the sorted list - index = speciesBatchUIModel.getRows().indexOf(row); - - } else { - - // correct order can directly get row from list - List<SpeciesBatchRowModel> rows = speciesBatchUIModel.getRows(); - row = rows.get(index); - - } - - int column; - if (SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT.equals(e.getProperty())) { - column = getFinestCategoryColumn(row.getFinestCategory().getCategoryId()); - } else { - column = 6; - } - TuttiUIUtil.doSelectCell(getUI().getSpeciesTabContent().getTable(), index, column); + tabInError = 1; throw e; + } // --------- // Compute benthos batches // --------- - BatchContainer<BenthosBatch> computedBenthosBatches; Float totalBenthosSortedWeight; + BatchContainer<BenthosBatch> computedBenthosBatches; + try { - computedBenthosBatches = - weightComputingService.getComputedBenthosBatches(operationId); + computedBenthosBatches = weightComputingService.getComputedBenthosBatches(operationId); totalBenthosSortedWeight = computeBenthosBatches(persistenceService, computedBenthosBatches); } catch (TuttiWeightComputingException e) { - getUI().getTabPane().setSelectedIndex(2); - - int index = e.getIndex(); - - BenthosBatchUIModel benthosBatchUIModel = getUI().getBenthosTabContent().getModel(); - - BenthosBatchRowModel row; - if (benthosBatchUIModel.getSpeciesSortMode() != SpeciesSortMode.NONE) { - - // must resort rows in natural order (in service we use this order) - List<BenthosBatchRowModel> rows = Lists.newArrayList(benthosBatchUIModel.getRows()); - SpeciesBatchNaturalOrderComparator.sort(rows); - // get the row - row = rows.get(index); - // get the correct rowIndex in the sorted list - index = benthosBatchUIModel.getRows().indexOf(row); - - } else { - - // correct order can directly get row from list - List<BenthosBatchRowModel> rows = benthosBatchUIModel.getRows(); - row = rows.get(index); - - } - - - int column; - if (BenthosBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT.equals(e.getProperty())) { - column = getFinestCategoryColumn(row.getFinestCategory().getCategoryId()); - } else { - column = 6; - } - TuttiUIUtil.doSelectCell(getUI().getBenthosTabContent().getTable(), index, column); + tabInError = 2; throw e; + } // --------- @@ -214,15 +179,18 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo BatchContainer<MarineLitterBatch> computedMarineLitterBatches; try { computedMarineLitterBatches = - weightComputingService.getComputedMarineLitterBatches(operationId, - model.getMarineLitterTotalWeight()); + weightComputingService.getComputedMarineLitterBatches(operationId, model.getMarineLitterTotalWeight()); } catch (TuttiWeightComputingException e) { - getUI().getTabPane().setSelectedIndex(3); - TuttiUIUtil.doSelectCell(getUI().getMarineLitterTabContent().getTable(), e.getIndex(), 3); + + tabInError = 3; throw e; + } + modified = model.isModify(); + catchBatch = model.toEntity(); + // --------- // Check species rates // --------- @@ -252,9 +220,13 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.NO_OPTION) { - model.setSpeciesTotalSortedWeight(null); - model.setSpeciesTotalSortedComputedWeight(totalSpeciesSortedWeight); + + catchBatch.setSpeciesTotalSortedWeight(null); + catchBatch.setSpeciesTotalSortedComputedWeight(totalSpeciesSortedWeight); + modified = true; + } + } // --------- @@ -285,29 +257,78 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.NO_OPTION) { - model.setBenthosTotalSortedWeight(null); - model.setBenthosTotalSortedComputedWeight(totalBenthosSortedWeight); + + catchBatch.setBenthosTotalSortedWeight(null); + catchBatch.setBenthosTotalSortedComputedWeight(totalBenthosSortedWeight); + modified = true; + } } -// persistenceService.recomputeCatchBatchSampleRatios(operationId); - - boolean modified = model.isModify(); - CatchBatch catchBatch = model.toEntity(); weightComputingService.computeCatchBatchWeights(catchBatch, computedSpeciesBatches, computedBenthosBatches, computedMarineLitterBatches); - model.fromEntity(catchBatch); - model.setLoadingData(false); - model.setModify(modified); } @Override public void postSuccessAction() { super.postSuccessAction(); + afterAction(); + + getUI().repaint(); + //TCHEMIT-2015-04-27 Plus besoin car le champs qui posait problème n'existe plus +// // see http://forge.codelutin.com/issues/3853 +// SwingUtilities.invokeLater( +// new Runnable() { +// @Override +// public void run() { +// getUI().getComputeSpeciesBatchButton().requestFocus(); +// } +// } +// ); + } + + protected void afterAction() { + + EditCatchesUIModel editCatchesUIModel = getModel(); + + editCatchesUIModel.setLoadingData(true); + + try { + + if (speciesBatchRows != null) { + + getUI().getSpeciesTabContent().getModel().setRows(speciesBatchRows); + + } + + if (benthosBatchRows != null) { + + getUI().getBenthosTabContent().getModel().setRows(benthosBatchRows); + + } + + if (catchBatch != null) { + + editCatchesUIModel.fromEntity(catchBatch); + + } + + if (modified != null) { + + editCatchesUIModel.setModify(modified); + + } + + } finally { + + editCatchesUIModel.setLoadingData(false); + + } + // keep sortMode // see https://forge.codelutin.com/issues/5699 @@ -335,16 +356,43 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo } } - getUI().repaint(); - // see http://forge.codelutin.com/issues/3853 - SwingUtilities.invokeLater( - new Runnable() { - @Override - public void run() { - getUI().getComputeSpeciesBatchButton().requestFocus(); - } - } - ); + } + + @Override + public void postFailedAction(Throwable error) { + + afterAction(); + + if (error instanceof TuttiWeightComputingException) { + + // elevation error + TuttiWeightComputingException e = (TuttiWeightComputingException) error; + + getUI().getTabPane().setSelectedIndex(tabInError); + + switch (tabInError) { + + case 1: + // species error + treatSpeciesBatchError(e); + + break; + + case 2: + + // benthos error + treatBenthosBatchError(e); + + break; + + case 3: + // marine litter error + JTables.doSelectCell(getUI().getMarineLitterTabContent().getTable(), e.getIndex(), 3); + + } + + } + } //------------------------------------------------------------------------// @@ -355,10 +403,10 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo Float totalSortedWeight = 0f; if (computedSpeciesBatches != null) { - List<SpeciesBatchRowModel> rows = Lists.newArrayList(); + speciesBatchRows = Lists.newArrayList(); List<SpeciesBatch> children = computedSpeciesBatches.getChildren(); for (SpeciesBatch batch : children) { - SpeciesBatchRowModel row = getUI().getSpeciesTabContent().getHandler().loadBatch(batch, null, rows); + SpeciesBatchRowModel row = getUI().getSpeciesTabContent().getHandler().loadBatch(batch, null, speciesBatchRows); if (persistenceService.isVracBatch(row)) { SampleCategory<?> sampleCategory = row.getFirstSampleCategory(); Float weight = Numbers.getValueOrComputedValue( @@ -367,7 +415,7 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo totalSortedWeight += weight; } } - getUI().getSpeciesTabContent().getModel().setRows(rows); +// getUI().getSpeciesTabContent().getModel().setRows(speciesBatchRows); } return totalSortedWeight; @@ -377,10 +425,10 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo Float totalSortedWeight = 0f; if (computedBenthosBatches != null) { - List<BenthosBatchRowModel> rows = Lists.newArrayList(); + benthosBatchRows = Lists.newArrayList(); List<BenthosBatch> children = computedBenthosBatches.getChildren(); for (BenthosBatch batch : children) { - BenthosBatchRowModel row = getUI().getBenthosTabContent().getHandler().loadBatch(batch, null, rows); + BenthosBatchRowModel row = getUI().getBenthosTabContent().getHandler().loadBatch(batch, null, benthosBatchRows); if (persistenceService.isVracBatch(row)) { SampleCategory<?> sampleCategory = row.getFirstSampleCategory(); @@ -390,22 +438,112 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo totalSortedWeight += weight; } } - getUI().getBenthosTabContent().getModel().setRows(rows); +// getUI().getBenthosTabContent().getModel().setRows(benthosBatchRows); } return totalSortedWeight; } - protected int getFinestCategoryColumn(Integer categoryId) { - int column = 1; + protected void treatSpeciesBatchError(TuttiWeightComputingException e) { + + int index = e.getIndex(); + SpeciesBatchUIModel speciesBatchUIModel = getUI().getSpeciesTabContent().getModel(); - List<Integer> samplingOrderIds = getConfig().getSamplingOrderIds(); + SpeciesBatchRowModel row; - int index = samplingOrderIds.indexOf(categoryId); - if (index > -1) { - column += index + 1; + if (speciesBatchUIModel.getSpeciesSortMode() != SpeciesSortMode.NONE) { + + // must resort rows in natural order (in service we use this order) + List<SpeciesBatchRowModel> rows = Lists.newArrayList(speciesBatchUIModel.getRows()); + SpeciesBatchNaturalOrderComparator.sort(rows); + // get the row + row = rows.get(index); + // get the correct rowIndex in the sorted list + index = speciesBatchUIModel.getRows().indexOf(row); + + } else { + + // correct order can directly get row from list + List<SpeciesBatchRowModel> rows = speciesBatchUIModel.getRows(); + row = rows.get(index); + + } + + JXTable table = getUI().getSpeciesTabContent().getTable(); + SpeciesBatchTableModel tableModel = (SpeciesBatchTableModel) table.getModel(); + Set<SampleCategoryColumnIdentifier<SpeciesBatchRowModel>> sampleCols = tableModel.getSampleCols(); + selectBatchCell(table, index, row, e.getProperty(), sampleCols, SpeciesBatchTableModel.WEIGHT); + + } + + protected void treatBenthosBatchError(TuttiWeightComputingException e) { + + int index = e.getIndex(); + + BenthosBatchUIModel benthosBatchUIModel = getUI().getBenthosTabContent().getModel(); + + BenthosBatchRowModel row; + if (benthosBatchUIModel.getSpeciesSortMode() != SpeciesSortMode.NONE) { + + // must resort rows in natural order (in service we use this order) + List<BenthosBatchRowModel> rows = Lists.newArrayList(benthosBatchUIModel.getRows()); + SpeciesBatchNaturalOrderComparator.sort(rows); + // get the row + row = rows.get(index); + // get the correct rowIndex in the sorted list + index = benthosBatchUIModel.getRows().indexOf(row); + + } else { + + // correct order can directly get row from list + List<BenthosBatchRowModel> rows = benthosBatchUIModel.getRows(); + row = rows.get(index); + + } + + JXTable table = getUI().getBenthosTabContent().getTable(); + BenthosBatchTableModel tableModel = (BenthosBatchTableModel) table.getModel(); + Set<SampleCategoryColumnIdentifier<BenthosBatchRowModel>> sampleCols = tableModel.getSampleCols(); + + selectBatchCell(table, index, row, e.getProperty(), sampleCols, BenthosBatchTableModel.WEIGHT); + + } + + protected <R extends SampleCategoryAble> void selectBatchCell(JXTable table, + int index, + SampleCategoryAble row, + String property, + Set<SampleCategoryColumnIdentifier<R>> sampleCols, + ColumnIdentifier<R> weightColumn) { + + ColumnIdentifier columnIdentifier = weightColumn; + + if (SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT.equals(property)) { + + // get category column for category + Integer categoryId = row.getFinestCategory().getCategoryId(); + for (SampleCategoryColumnIdentifier<R> sampleCol : sampleCols) { + if (categoryId.equals(sampleCol.getSampleCategoryId())) { + columnIdentifier = sampleCol; + break; + } + } + + } + + int column = 0; + TableColumnExt columnExt = table.getColumnExt(columnIdentifier); + int modelIndex = columnExt.getModelIndex(); + for (TableColumn tableColumn : table.getColumns(false)) { + + if (columnExt.equals(tableColumn) || tableColumn.getModelIndex() > modelIndex) { + break; + } + column++; } - return column; + JTables.doSelectCell(table, index, column); + } + } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java index bcb388e..1404bfb 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchTableModel.java @@ -23,6 +23,7 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.benthos; */ import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; @@ -130,7 +131,7 @@ public class BenthosBatchTableModel extends AbstractApplicationTableModel<Bentho frequencyCols.add(COMPUTED_NUMBER); frequencyCols.add(WEIGHT); - sampleCols = Sets.newHashSet(); + Set<SampleCategoryColumnIdentifier<BenthosBatchRowModel>> sampleCols = Sets.newLinkedHashSet(); Enumeration<TableColumn> columns = columnModel.getColumns(); while (columns.hasMoreElements()) { TableColumn tableColumn = columns.nextElement(); @@ -141,6 +142,11 @@ public class BenthosBatchTableModel extends AbstractApplicationTableModel<Bentho sampleCols.add(categoryColumnIdentifier); } } + this.sampleCols = ImmutableSet.copyOf(sampleCols); + } + + public Set<SampleCategoryColumnIdentifier<BenthosBatchRowModel>> getSampleCols() { + return sampleCols; } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java index 790c320..ba3855f 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java @@ -23,6 +23,7 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.species; */ import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; @@ -130,7 +131,7 @@ public class SpeciesBatchTableModel extends AbstractApplicationTableModel<Specie frequencyCols.add(COMPUTED_NUMBER); frequencyCols.add(WEIGHT); - sampleCols = Sets.newHashSet(); + Set<SampleCategoryColumnIdentifier<SpeciesBatchRowModel>> sampleCols = Sets.newLinkedHashSet(); Enumeration<TableColumn> columns = columnModel.getColumns(); while (columns.hasMoreElements()) { @@ -140,6 +141,11 @@ public class SpeciesBatchTableModel extends AbstractApplicationTableModel<Specie sampleCols.add((SampleCategoryColumnIdentifier<SpeciesBatchRowModel>) identifier); } } + this.sampleCols = ImmutableSet.copyOf(sampleCols); + } + + public Set<SampleCategoryColumnIdentifier<SpeciesBatchRowModel>> getSampleCols() { + return sampleCols; } @Override -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm