commandStack.execute(command);
}
protected void finishCurrentChange(boolean changeUndone) {
if (currentChange == null) return;
IOngoingChange change = currentChange;
currentChange = null;
// Make sure there's a placeholder on the stack.
if (ignoreEvents) {
throw new IllegalStateException();
}
if (!(commandStack.getUndoCommand() instanceof PlaceHolderCommand)) {
throw new IllegalStateException();
}
ignoreEvents = true;
try {
commandStack.undo(); // Remove placeholder.
} finally {
ignoreEvents = false;
}
Command cmd = change.createApplyCommand();
if (cmd != null) {
cmd.setLabel(change.getLabel());
if (changeUndone) {
change.restoreOldState();
} else {
// TODO: if the command is not actually executable, should we call
// restoreOldState() instead? I'm inclined not to because we've been
// using !canExecute() to elide no-op commands. But maybe we should
// rethink that (especially since IOngoingChange makes it much less
// common, and maybe confusing, to elide a command in that way?).
// TODO: above comment is obsolete. Now that no-ops are handled in
// a different way by EditModelCommandStack, we should consider calling
// restoreOldState() if canExecute() fails.
commandStack.execute(cmd);
}
} else {
change.restoreOldState();
}
}