if (!movedOne) {
// Do not generate any undo action if no move happened.
return;
}
UndoAction undoAction = new UndoAction() {
public void execute() {
try {
// Undo has to reverse the order of the do.
if ((type == TO_FIRST) || (type == UP)) {
// Traverse the list in forward order.
Iterator targetIterator = targets.iterator();
for (int i = 0; i < targets.size(); i++) {
NamedObj target = (NamedObj) targetIterator.next();
target.moveToIndex(priorIndexes[i]);
}
} else {
// Traverse the list in reverse order.
ListIterator targetIterator = targets
.listIterator(targets.size());
for (int i = targets.size() - 1; i >= 0; i--) {
NamedObj target = (NamedObj) targetIterator
.previous();
target.moveToIndex(priorIndexes[i]);
}
}
} catch (IllegalActionException e) {
// This should only be thrown if the target
// has no container, which in theory is not
// possible.
throw new InternalErrorException(e);
}
// Create redo action.
UndoAction redoAction = new UndoAction() {
public void execute() {
move(targets, type, context);
}
};