2010-02-22 19:42:25 +01:00
|
|
|
package com.metaweb.gridworks.operations;
|
2010-02-04 21:51:44 +01:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONWriter;
|
|
|
|
|
|
|
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
2010-02-27 00:33:16 +01:00
|
|
|
import com.metaweb.gridworks.history.Change;
|
2010-02-22 05:23:25 +01:00
|
|
|
import com.metaweb.gridworks.model.AbstractOperation;
|
2010-02-04 21:51:44 +01:00
|
|
|
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;
|
2010-02-27 00:33:16 +01:00
|
|
|
import com.metaweb.gridworks.model.changes.ReconChange;
|
2010-02-04 21:51:44 +01:00
|
|
|
|
2010-02-22 05:23:25 +01:00
|
|
|
public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOperation {
|
|
|
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
|
|
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
|
|
|
String columnName = obj.getString("columnName");
|
|
|
|
|
|
|
|
return new ReconDiscardJudgmentsOperation(
|
|
|
|
engineConfig,
|
|
|
|
columnName
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
public ReconDiscardJudgmentsOperation(JSONObject engineConfig, String columnName) {
|
|
|
|
super(engineConfig, columnName, false);
|
|
|
|
}
|
2010-02-04 21:51:44 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
|
|
|
writer.object();
|
|
|
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
|
|
|
writer.key("description"); writer.value(getBriefDescription(null));
|
|
|
|
writer.key("engineConfig"); writer.value(getEngineConfig());
|
|
|
|
writer.key("columnName"); writer.value(_columnName);
|
|
|
|
writer.endObject();
|
|
|
|
}
|
2010-02-22 05:23:25 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
protected String getBriefDescription(Project project) {
|
|
|
|
return "Discard recon judgments for cells in column " + _columnName;
|
|
|
|
}
|
2010-02-04 21:51:44 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
protected String createDescription(Column column,
|
|
|
|
List<CellChange> cellChanges) {
|
|
|
|
|
|
|
|
return "Discard recon judgments for " + cellChanges.size() +
|
2010-03-06 08:43:45 +01:00
|
|
|
" cells in column " + column.getName();
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
2010-02-04 21:51:44 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges) throws Exception {
|
|
|
|
Column column = project.columnModel.getColumnByName(_columnName);
|
|
|
|
|
|
|
|
return new RowVisitor() {
|
|
|
|
int cellIndex;
|
|
|
|
List<CellChange> cellChanges;
|
|
|
|
|
|
|
|
public RowVisitor init(int cellIndex, List<CellChange> cellChanges) {
|
|
|
|
this.cellIndex = cellIndex;
|
|
|
|
this.cellChanges = cellChanges;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
2010-03-06 09:03:29 +01:00
|
|
|
Cell cell = row.getCell(cellIndex);
|
|
|
|
if (cell != null && cell.recon != null) {
|
|
|
|
Recon recon = cell.recon.dup();
|
|
|
|
recon.judgment = Judgment.None;
|
|
|
|
recon.match = null;
|
|
|
|
|
|
|
|
Cell newCell = new Cell(cell.value, recon);
|
|
|
|
|
|
|
|
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
|
|
|
|
cellChanges.add(cellChange);
|
2010-03-03 05:19:58 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}.init(column.getCellIndex(), cellChanges);
|
|
|
|
}
|
2010-02-22 05:23:25 +01:00
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
protected Change createChange(Project project, Column column, List<CellChange> cellChanges) {
|
|
|
|
return new ReconChange(
|
|
|
|
cellChanges,
|
|
|
|
_columnName,
|
|
|
|
column.getReconConfig(),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
2010-02-04 21:51:44 +01:00
|
|
|
}
|