2010-02-11 07:44:48 +01:00
|
|
|
package com.metaweb.gridworks.model.operations;
|
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONWriter;
|
|
|
|
|
|
|
|
import com.metaweb.gridworks.history.Change;
|
|
|
|
import com.metaweb.gridworks.history.HistoryEntry;
|
|
|
|
import com.metaweb.gridworks.model.AbstractOperation;
|
|
|
|
import com.metaweb.gridworks.model.Project;
|
|
|
|
import com.metaweb.gridworks.protograph.Protograph;
|
|
|
|
|
2010-02-19 00:27:40 +01:00
|
|
|
public class SaveProtographOperation extends AbstractOperation {
|
2010-02-11 07:44:48 +01:00
|
|
|
private static final long serialVersionUID = 3134524625206033285L;
|
|
|
|
|
|
|
|
final protected Protograph _protograph;
|
|
|
|
|
|
|
|
public SaveProtographOperation(
|
|
|
|
Protograph protograph
|
|
|
|
) {
|
|
|
|
_protograph = protograph;
|
|
|
|
}
|
|
|
|
|
2010-02-19 00:27:40 +01:00
|
|
|
protected String getBriefDescription() {
|
|
|
|
return "Save schema skeleton";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected HistoryEntry createHistoryEntry(Project project) throws Exception {
|
2010-02-11 07:44:48 +01:00
|
|
|
String description = "Save schema-alignment protograph";
|
|
|
|
|
|
|
|
Change change = new ProtographChange(_protograph);
|
2010-02-19 00:27:40 +01:00
|
|
|
|
|
|
|
return new HistoryEntry(project, description, SaveProtographOperation.this, change);
|
2010-02-11 07:44:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
2010-02-17 02:30:09 +01:00
|
|
|
|
|
|
|
writer.object();
|
|
|
|
writer.key("op"); writer.value("save-protograph");
|
|
|
|
writer.key("description"); writer.value("Save protograph");
|
|
|
|
writer.key("protograph"); _protograph.write(writer, options);
|
|
|
|
writer.endObject();
|
2010-02-11 07:44:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static public class ProtographChange implements Change {
|
|
|
|
private static final long serialVersionUID = -564820111174473901L;
|
|
|
|
|
|
|
|
final protected Protograph _newProtograph;
|
|
|
|
protected Protograph _oldProtograph;
|
|
|
|
|
|
|
|
public ProtographChange(Protograph protograph) {
|
|
|
|
_newProtograph = protograph;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void apply(Project project) {
|
|
|
|
synchronized (project) {
|
|
|
|
_oldProtograph = project.protograph;
|
|
|
|
project.protograph = _newProtograph;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void revert(Project project) {
|
|
|
|
synchronized (project) {
|
|
|
|
project.protograph = _oldProtograph;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|