Search in sources :

Example 66 with AUndoableEdit

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);
                }
            }
        }
    };
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Aggregations

AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)66 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)34 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)21 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)16 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)14 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)14 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)12 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)10 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)7 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)7 Design (edu.cmu.cs.hcii.cogtool.model.Design)7 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)7 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)7 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)7 DictEntry (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry)6 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)6 UndoManager (edu.cmu.cs.hcii.cogtool.util.UndoManager)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6