Moved concrete change classes out to their own package. Added a few change classes for columns, but they are not hooked up yet.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@36 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-04 06:00:26 +00:00
parent 863493950f
commit 720f147c09
14 changed files with 191 additions and 12 deletions

View File

@ -11,15 +11,15 @@ import javax.servlet.http.HttpServletResponse;
import com.metaweb.gridworks.browsing.Engine;
import com.metaweb.gridworks.browsing.FilteredRows;
import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.history.CellChange;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.history.MassCellChange;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Recon;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.Recon.Judgment;
import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class ApproveNewReconcileCommand extends Command {

View File

@ -11,14 +11,14 @@ import javax.servlet.http.HttpServletResponse;
import com.metaweb.gridworks.browsing.Engine;
import com.metaweb.gridworks.browsing.FilteredRows;
import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.history.CellChange;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.history.MassCellChange;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.Recon.Judgment;
import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class ApproveReconcileCommand extends Command {

View File

@ -11,13 +11,13 @@ import javax.servlet.http.HttpServletResponse;
import com.metaweb.gridworks.browsing.Engine;
import com.metaweb.gridworks.browsing.FilteredRows;
import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.history.CellChange;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.history.MassCellChange;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class DiscardReconcileCommand extends Command {

View File

@ -15,13 +15,13 @@ import com.metaweb.gridworks.browsing.FilteredRows;
import com.metaweb.gridworks.browsing.RowVisitor;
import com.metaweb.gridworks.expr.Evaluable;
import com.metaweb.gridworks.expr.Parser;
import com.metaweb.gridworks.history.CellChange;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.history.MassCellChange;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange;
import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
public class DoTextTransformCommand extends Command {

View File

@ -0,0 +1,32 @@
package com.metaweb.gridworks.history;
import com.metaweb.gridworks.model.Project;
public class ChangeSequence implements Change {
private static final long serialVersionUID = 5029993970500006428L;
final protected Change[] _changes;
public ChangeSequence(Change[] changes) {
_changes = changes;
}
@Override
public void apply(Project project) {
synchronized (project) {
for (int i = 0; i < _changes.length; i++) {
_changes[i].apply(project);
}
}
}
@Override
public void revert(Project project) {
synchronized (project) {
for (int i = _changes.length - 1; i >= 0 ; i--) {
_changes[i].apply(project);
}
}
}
}

View File

@ -41,6 +41,10 @@ public class ColumnModel implements Serializable, Jsonizable {
return _maxCellIndex;
}
public int allocateNewCellIndex() {
return ++_maxCellIndex;
}
public void setKeyCellIndex(int keyCellIndex) {
// TODO: check validity of new cell index, e.g., it's not in any group
this._keyCellIndex = keyCellIndex;

View File

@ -0,0 +1,17 @@
package com.metaweb.gridworks.model.changes;
import java.io.Serializable;
import com.metaweb.gridworks.model.Cell;
public class CellAtRow implements Serializable {
private static final long serialVersionUID = 7280920621006690944L;
final public int row;
final public Cell cell;
public CellAtRow(int row, Cell cell) {
this.row = row;
this.cell = cell;
}
}

View File

@ -1,4 +1,4 @@
package com.metaweb.gridworks.history;
package com.metaweb.gridworks.model.changes;
import java.io.Serializable;

View File

@ -0,0 +1,49 @@
package com.metaweb.gridworks.model.changes;
import java.util.List;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
public class ColumnAdditionChange extends ColumnChange {
private static final long serialVersionUID = -3938837464064526052L;
final protected String _headerLabel;
final protected int _columnIndex;
final protected CellAtRow[] _newCells;
protected int _newCellIndex;
public ColumnAdditionChange(String headerLabel, int columnIndex, List<CellAtRow> newCells) {
_headerLabel = headerLabel;
_columnIndex = columnIndex;
_newCells = new CellAtRow[newCells.size()];
newCells.toArray(_newCells);
}
@Override
public void apply(Project project) {
synchronized (project) {
_newCellIndex = project.columnModel.allocateNewCellIndex();
Column column = new Column(_newCellIndex, _headerLabel);
project.columnModel.columns.add(_columnIndex, column);
for (CellAtRow cell : _newCells) {
project.rows.get(cell.row).cells.set(_newCellIndex, cell.cell);
}
}
}
@Override
public void revert(Project project) {
synchronized (project) {
for (CellAtRow cell : _newCells) {
project.rows.get(cell.row).cells.remove(_newCellIndex);
}
project.columnModel.columns.remove(_columnIndex);
}
}
}

View File

@ -0,0 +1,7 @@
package com.metaweb.gridworks.model.changes;
import com.metaweb.gridworks.history.Change;
abstract public class ColumnChange implements Change {
private static final long serialVersionUID = 2725529838777790586L;
}

View File

@ -0,0 +1,50 @@
package com.metaweb.gridworks.model.changes;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Column;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
public class ColumnRemovalChange extends ColumnChange {
private static final long serialVersionUID = -3587865920553490108L;
final protected int _oldColumnIndex;
protected Column _oldColumn;
protected CellAtRow[] _oldCells;
public ColumnRemovalChange(int index) {
_oldColumnIndex = index;
}
@Override
public void apply(Project project) {
synchronized (project) {
_oldColumn = project.columnModel.columns.remove(_oldColumnIndex);
_oldCells = new CellAtRow[project.rows.size()];
int cellIndex = _oldColumn.getCellIndex();
for (int i = 0; i < _oldCells.length; i++) {
Row row = project.rows.get(i);
Cell oldCell = null;
if (cellIndex < row.cells.size()) {
oldCell = row.cells.get(cellIndex);
}
_oldCells[i] = new CellAtRow(i, oldCell);
}
}
}
@Override
public void revert(Project project) {
synchronized (project) {
project.columnModel.columns.add(_oldColumnIndex, _oldColumn);
int cellIndex = _oldColumn.getCellIndex();
for (CellAtRow cell : _oldCells) {
project.rows.get(cell.row).cells.set(cellIndex, cell.cell);
}
}
}
}

View File

@ -0,0 +1,19 @@
package com.metaweb.gridworks.model.changes;
import com.metaweb.gridworks.model.Project;
public class ColumnSplitChange extends ColumnChange {
@Override
public void apply(Project project) {
// TODO Auto-generated method stub
}
@Override
public void revert(Project project) {
// TODO Auto-generated method stub
}
}

View File

@ -1,7 +1,8 @@
package com.metaweb.gridworks.history;
package com.metaweb.gridworks.model.changes;
import java.util.List;
import com.metaweb.gridworks.history.Change;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;

View File

@ -20,13 +20,13 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import com.metaweb.gridworks.history.CellChange;
import com.metaweb.gridworks.history.HistoryEntry;
import com.metaweb.gridworks.history.MassCellChange;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Recon;
import com.metaweb.gridworks.model.ReconCandidate;
import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange;
import com.metaweb.gridworks.util.ParsingUtilities;
public class ReconProcess extends LongRunningProcess implements Runnable {