use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class SNIFACTCmd method addTasksToGroup.
/**
* Creates an undoable edit for the action of adding the list of tasks
* stored in the execution context to the given task group.
*/
protected static IUndoableEdit addTasksToGroup(final Project project, final TaskGroup group, final SNIFACTExecContext context, final String undoLabel) {
return new AUndoableEdit(ProjectLID.RecomputeScript) {
protected Map<ITaskDesign, TaskApplication>[] associatedTAs = null;
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return undoLabel;
}
@Override
public void redo() {
super.redo();
recoverMgrs = false;
List<AUndertaking> tasks = context.getTasks();
for (int i = 0; i < tasks.size(); i++) {
AUndertaking curTask = tasks.get(i);
group.addUndertaking(curTask);
project.restoreRemovedTaskApplications(associatedTAs[i]);
}
}
@Override
@SuppressWarnings("unchecked")
public void undo() {
super.undo();
recoverMgrs = true;
List<AUndertaking> tasks = context.getTasks();
int size = tasks.size();
if (associatedTAs == null) {
associatedTAs = new Map[size];
}
// delete children; IMPORTANT: reverse order!
for (int i = tasks.size() - 1; 0 <= i; i--) {
AUndertaking curTask = tasks.get(i);
associatedTAs[i] = project.taskApplicationsForRemovedTask(curTask);
group.removeUndertaking(curTask);
}
}
@Override
public void die() {
super.die();
if (recoverMgrs) {
for (Map<ITaskDesign, TaskApplication> associatedTA : associatedTAs) {
UndoManagerRecovery.recoverScriptManagers(project, associatedTA, true);
}
}
}
};
}
Aggregations