From 2eccab4c7195495e3f14bda1b1a666195260d3c4 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Sat, 6 Feb 2010 06:40:17 +0000 Subject: [PATCH] We need to recompute the row context dependencies after cell and column changes, but not after recon changes. git-svn-id: http://google-refine.googlecode.com/svn/trunk@56 7d457c2a-affb-35e4-300a-418c747d4874 --- .../commands/edit/CreateProjectCommand.java | 1 + .../model/changes/ColumnAdditionChange.java | 5 +++++ .../model/changes/ColumnRemovalChange.java | 6 ++++++ .../gridworks/model/changes/MassCellChange.java | 17 ++++++++++++++--- .../gridworks/model/changes/MassRowChange.java | 4 ++++ .../operations/ApproveNewReconOperation.java | 2 +- .../model/operations/ApproveReconOperation.java | 2 +- .../model/operations/DiscardReconOperation.java | 2 +- .../EngineDependentMassCellOperation.java | 7 +++++-- .../model/operations/ReconOperation.java | 2 +- .../operations/TextTransformOperation.java | 2 +- 11 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java index bb27f08a7..51ea49db3 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/CreateProjectCommand.java @@ -43,6 +43,7 @@ public class CreateProjectCommand extends Command { ProjectManager.singleton.registerProject(project, pm); project.columnModel.update(); + project.recomputeRowContextDependencies(); redirect(response, "/project.html?project=" + project.id); } catch (Exception e) { diff --git a/src/main/java/com/metaweb/gridworks/model/changes/ColumnAdditionChange.java b/src/main/java/com/metaweb/gridworks/model/changes/ColumnAdditionChange.java index d5fa6c2b6..89c403355 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/ColumnAdditionChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/ColumnAdditionChange.java @@ -36,6 +36,8 @@ public class ColumnAdditionChange extends ColumnChange { } catch (Exception e) { e.printStackTrace(); } + project.columnModel.update(); + project.recomputeRowContextDependencies(); } } @@ -48,6 +50,9 @@ public class ColumnAdditionChange extends ColumnChange { } project.columnModel.columns.remove(_columnIndex); + + project.columnModel.update(); + project.recomputeRowContextDependencies(); } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/ColumnRemovalChange.java b/src/main/java/com/metaweb/gridworks/model/changes/ColumnRemovalChange.java index 3381a8d24..4313cee79 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/ColumnRemovalChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/ColumnRemovalChange.java @@ -34,6 +34,9 @@ public class ColumnRemovalChange extends ColumnChange { row.setCell(cellIndex, null); } + + project.columnModel.update(); + project.recomputeRowContextDependencies(); } } @@ -46,6 +49,9 @@ public class ColumnRemovalChange extends ColumnChange { for (CellAtRow cell : _oldCells) { project.rows.get(cell.row).cells.set(cellIndex, cell.cell); } + + project.columnModel.update(); + project.recomputeRowContextDependencies(); } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/MassCellChange.java b/src/main/java/com/metaweb/gridworks/model/changes/MassCellChange.java index 75b1ecddf..0e9e045d0 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/MassCellChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/MassCellChange.java @@ -9,13 +9,16 @@ import com.metaweb.gridworks.model.Row; public class MassCellChange implements Change { private static final long serialVersionUID = -933571199802688027L; - protected CellChange[] _cellChanges; - protected int _commonCellIndex; + final protected CellChange[] _cellChanges; + final protected int _commonCellIndex; + final protected boolean _updateRowContextDependencies; - public MassCellChange(List cellChanges, int commonCellIndex) { + public MassCellChange(List cellChanges, int commonCellIndex, boolean updateRowContextDependencies) { _cellChanges = new CellChange[cellChanges.size()]; _commonCellIndex = commonCellIndex; cellChanges.toArray(_cellChanges); + + _updateRowContextDependencies = updateRowContextDependencies; } @Override @@ -30,6 +33,10 @@ public class MassCellChange implements Change { if (_commonCellIndex >= 0) { project.columnModel.getColumnByCellIndex(_commonCellIndex).clearPrecomputes(); } + + if (_updateRowContextDependencies) { + project.recomputeRowContextDependencies(); + } } } @@ -45,6 +52,10 @@ public class MassCellChange implements Change { if (_commonCellIndex >= 0) { project.columnModel.getColumnByCellIndex(_commonCellIndex).clearPrecomputes(); } + + if (_updateRowContextDependencies) { + project.recomputeRowContextDependencies(); + } } } } diff --git a/src/main/java/com/metaweb/gridworks/model/changes/MassRowChange.java b/src/main/java/com/metaweb/gridworks/model/changes/MassRowChange.java index a2b5d230d..72198111e 100644 --- a/src/main/java/com/metaweb/gridworks/model/changes/MassRowChange.java +++ b/src/main/java/com/metaweb/gridworks/model/changes/MassRowChange.java @@ -23,6 +23,8 @@ public class MassRowChange implements Change { _oldRows = new ArrayList(project.rows); project.rows.clear(); project.rows.addAll(_newRows); + + project.recomputeRowContextDependencies(); } } @@ -31,6 +33,8 @@ public class MassRowChange implements Change { synchronized (project) { project.rows.clear(); project.rows.addAll(_oldRows); + + project.recomputeRowContextDependencies(); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java index abb14e088..5fbcb8de2 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java @@ -20,7 +20,7 @@ public class ApproveNewReconOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = -5205694623711144436L; public ApproveNewReconOperation(JSONObject engineConfig, int cellIndex) { - super(engineConfig, cellIndex); + super(engineConfig, cellIndex, false); } @Override diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java index 8af1d33eb..609d976ed 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java @@ -19,7 +19,7 @@ public class ApproveReconOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = 5393888241057341155L; public ApproveReconOperation(JSONObject engineConfig, int cellIndex) { - super(engineConfig, cellIndex); + super(engineConfig, cellIndex, false); } @Override diff --git a/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java index 362dfc570..8c067b3f5 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java @@ -18,7 +18,7 @@ public class DiscardReconOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = 6799029731665369179L; public DiscardReconOperation(JSONObject engineConfig, int cellIndex) { - super(engineConfig, cellIndex); + super(engineConfig, cellIndex, false); } @Override diff --git a/src/main/java/com/metaweb/gridworks/model/operations/EngineDependentMassCellOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/EngineDependentMassCellOperation.java index a1f7f8ea1..8f486195c 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/EngineDependentMassCellOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/EngineDependentMassCellOperation.java @@ -21,10 +21,13 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp private static final long serialVersionUID = -8962461328087299452L; final protected int _cellIndex; + final protected boolean _updateRowContextDependencies; - protected EngineDependentMassCellOperation(JSONObject engineConfig, int cellIndex) { + protected EngineDependentMassCellOperation( + JSONObject engineConfig, int cellIndex, boolean updateRowContextDependencies) { super(engineConfig); _cellIndex = cellIndex; + _updateRowContextDependencies = updateRowContextDependencies; } @Override @@ -43,7 +46,7 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp String description = createDescription(column, cellChanges); - MassCellChange massCellChange = new MassCellChange(cellChanges, _cellIndex); + MassCellChange massCellChange = new MassCellChange(cellChanges, _cellIndex, _updateRowContextDependencies); HistoryEntry historyEntry = new HistoryEntry( project, description, this, massCellChange); diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java index d52ebd36b..acff7c2c9 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java @@ -160,7 +160,7 @@ public class ReconOperation extends EngineDependentOperation { } } - MassCellChange massCellChange = new MassCellChange(cellChanges, _cellIndex); + MassCellChange massCellChange = new MassCellChange(cellChanges, _cellIndex, false); HistoryEntry historyEntry = new HistoryEntry( _project, _description, diff --git a/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java index 21fed9cbf..4ae7fcf1b 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java @@ -23,7 +23,7 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { final protected String _expression; public TextTransformOperation(JSONObject engineConfig, int cellIndex, String expression) { - super(engineConfig, cellIndex); + super(engineConfig, cellIndex, true); _expression = expression; }