2010-02-22 19:42:25 +01:00
|
|
|
package com.metaweb.gridworks.operations;
|
2010-02-04 21:51:44 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
import com.metaweb.gridworks.browsing.Engine;
|
|
|
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
|
|
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
2010-02-27 00:33:16 +01:00
|
|
|
import com.metaweb.gridworks.history.Change;
|
2010-02-04 21:51:44 +01:00
|
|
|
import com.metaweb.gridworks.history.HistoryEntry;
|
|
|
|
import com.metaweb.gridworks.model.Column;
|
|
|
|
import com.metaweb.gridworks.model.Project;
|
|
|
|
import com.metaweb.gridworks.model.changes.CellChange;
|
|
|
|
import com.metaweb.gridworks.model.changes.MassCellChange;
|
|
|
|
|
|
|
|
abstract public class EngineDependentMassCellOperation extends EngineDependentOperation {
|
2010-03-03 05:19:58 +01:00
|
|
|
final protected String _columnName;
|
|
|
|
final protected boolean _updateRowContextDependencies;
|
|
|
|
|
|
|
|
protected EngineDependentMassCellOperation(
|
|
|
|
JSONObject engineConfig, String columnName, boolean updateRowContextDependencies) {
|
|
|
|
super(engineConfig);
|
|
|
|
_columnName = columnName;
|
|
|
|
_updateRowContextDependencies = updateRowContextDependencies;
|
|
|
|
}
|
2010-02-04 21:51:44 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
|
|
|
|
Engine engine = createEngine(project);
|
|
|
|
|
|
|
|
Column column = project.columnModel.getColumnByName(_columnName);
|
|
|
|
if (column == null) {
|
|
|
|
throw new Exception("No column named " + _columnName);
|
|
|
|
}
|
|
|
|
|
|
|
|
List<CellChange> cellChanges = new ArrayList<CellChange>(project.rows.size());
|
|
|
|
|
|
|
|
FilteredRows filteredRows = engine.getAllFilteredRows(false);
|
|
|
|
filteredRows.accept(project, createRowVisitor(project, cellChanges));
|
|
|
|
|
|
|
|
String description = createDescription(column, cellChanges);
|
|
|
|
|
|
|
|
return new HistoryEntry(
|
|
|
|
project, description, this, createChange(project, column, cellChanges));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Change createChange(Project project, Column column, List<CellChange> cellChanges) {
|
|
|
|
return new MassCellChange(
|
2010-03-06 08:43:45 +01:00
|
|
|
cellChanges, column.getName(), _updateRowContextDependencies);
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges) throws Exception;
|
|
|
|
abstract protected String createDescription(Column column, List<CellChange> cellChanges);
|
2010-02-04 21:51:44 +01:00
|
|
|
}
|