2010-01-27 02:48:42 +01:00
|
|
|
package com.metaweb.gridlock.history;
|
|
|
|
|
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-01-27 02:48:42 +01:00
|
|
|
import com.metaweb.gridlock.model.Project;
|
|
|
|
import com.metaweb.gridlock.process.Process;
|
2010-02-01 04:22:35 +01:00
|
|
|
import com.metaweb.gridlock.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;
|
|
|
|
boolean _done = false;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isImmediate() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDone() {
|
|
|
|
throw new RuntimeException("Not a long-running process");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isRunning() {
|
|
|
|
throw new RuntimeException("Not a long-running process");
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
}
|