2010-02-03 03:29:47 +01:00
|
|
|
package com.metaweb.gridworks.history;
|
2010-01-27 02:48:42 +01:00
|
|
|
|
2010-02-01 09:31:50 +01:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
2010-02-01 20:16:09 +01:00
|
|
|
import org.json.JSONWriter;
|
2010-02-01 09:31:50 +01:00
|
|
|
|
2010-02-03 03:29:47 +01:00
|
|
|
import com.metaweb.gridworks.model.Project;
|
|
|
|
import com.metaweb.gridworks.process.Process;
|
|
|
|
import com.metaweb.gridworks.process.ProcessManager;
|
2010-01-27 02:48:42 +01:00
|
|
|
|
|
|
|
public class HistoryProcess extends Process {
|
|
|
|
final protected Project _project;
|
2010-02-01 09:31:50 +01:00
|
|
|
final protected long _lastDoneID;
|
|
|
|
final protected String _description;
|
2010-02-03 22:57:38 +01:00
|
|
|
|
|
|
|
protected boolean _done = false;
|
2010-02-01 09:31:50 +01:00
|
|
|
|
2010-01-27 02:48:42 +01:00
|
|
|
public HistoryProcess(Project project, long lastDoneID) {
|
|
|
|
_project = project;
|
|
|
|
_lastDoneID = lastDoneID;
|
2010-02-01 09:31:50 +01:00
|
|
|
|
|
|
|
if (_lastDoneID == 0) {
|
|
|
|
_description = "Undo all";
|
|
|
|
} else {
|
|
|
|
HistoryEntry entry = _project.history.getEntry(_lastDoneID);
|
|
|
|
_description = "Undo/redo until after " + entry.description;
|
|
|
|
}
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cancel() {
|
2010-02-01 09:31:50 +01:00
|
|
|
throw new RuntimeException("Not a long-running process");
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isImmediate() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void performImmediate() {
|
|
|
|
_project.history.undoRedo(_lastDoneID);
|
2010-02-01 09:31:50 +01:00
|
|
|
_done = true;
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
|
2010-02-01 04:22:35 +01:00
|
|
|
public void startPerforming(ProcessManager manager) {
|
2010-02-01 09:31:50 +01:00
|
|
|
throw new RuntimeException("Not a long-running process");
|
|
|
|
}
|
|
|
|
|
2010-02-01 20:16:09 +01:00
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
2010-02-01 09:31:50 +01:00
|
|
|
|
2010-02-01 20:16:09 +01:00
|
|
|
writer.object();
|
|
|
|
writer.key("description"); writer.value(_description);
|
|
|
|
writer.key("immediate"); writer.value(true);
|
|
|
|
writer.key("status"); writer.value(_done ? "done" : "pending");
|
|
|
|
writer.endObject();
|
2010-02-01 09:31:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDone() {
|
|
|
|
throw new RuntimeException("Not a long-running process");
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRunning() {
|
|
|
|
throw new RuntimeException("Not a long-running process");
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
}
|