2010-05-05 01:24:48 +02:00
|
|
|
package com.metaweb.gridworks.operations;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
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.Engine;
|
|
|
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
|
|
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
|
|
|
import com.metaweb.gridworks.history.HistoryEntry;
|
|
|
|
import com.metaweb.gridworks.model.AbstractOperation;
|
|
|
|
import com.metaweb.gridworks.model.Project;
|
|
|
|
import com.metaweb.gridworks.model.Row;
|
|
|
|
import com.metaweb.gridworks.model.changes.RowRemovalChange;
|
|
|
|
|
|
|
|
public class RowRemovalOperation extends EngineDependentOperation {
|
|
|
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
|
|
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
|
|
|
|
|
|
|
return new RowRemovalOperation(
|
|
|
|
engineConfig
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public RowRemovalOperation(JSONObject engineConfig) {
|
|
|
|
super(engineConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
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.endObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getBriefDescription(Project project) {
|
|
|
|
return "Remove rows";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
|
|
|
Engine engine = createEngine(project);
|
|
|
|
|
|
|
|
List<Integer> rowIndices = new ArrayList<Integer>();
|
|
|
|
|
2010-05-20 02:13:19 +02:00
|
|
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
2010-05-05 01:24:48 +02:00
|
|
|
filteredRows.accept(project, createRowVisitor(project, rowIndices));
|
|
|
|
|
|
|
|
return new HistoryEntry(
|
|
|
|
historyEntryID,
|
|
|
|
project,
|
|
|
|
"Remove " + rowIndices.size() + " rows",
|
|
|
|
this,
|
|
|
|
new RowRemovalChange(rowIndices)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected RowVisitor createRowVisitor(Project project, List<Integer> rowIndices) throws Exception {
|
|
|
|
return new RowVisitor() {
|
|
|
|
List<Integer> rowIndices;
|
|
|
|
|
|
|
|
public RowVisitor init(List<Integer> rowIndices) {
|
|
|
|
this.rowIndices = rowIndices;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2010-05-21 00:10:34 +02:00
|
|
|
@Override
|
|
|
|
public void start(Project project) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void end(Project project) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
2010-05-20 02:13:19 +02:00
|
|
|
public boolean visit(Project project, int rowIndex, Row row) {
|
|
|
|
rowIndices.add(rowIndex);
|
|
|
|
|
2010-05-05 01:24:48 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}.init(rowIndices);
|
|
|
|
}
|
|
|
|
}
|