Search in sources :

Example 41 with CompoundUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.

the class ProjectController method createDuplicateTaskFullAction.

protected IListenerAction createDuplicateTaskFullAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectUI.ChangeTaskPositionParms.class;
        }

        public boolean performAction(Object actionParms) {
            ProjectUI.ChangeTaskPositionParms prms = (ProjectUI.ChangeTaskPositionParms) actionParms;
            if ((prms.tasks == null) || (prms.tasks.getSelectedTaskCount() == 0)) {
                interaction.protestNoSelection();
                return false;
            }
            AUndertaking[] selectedTasks = prms.tasks.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
            TaskParent placeBeforeTaskParent = (prms.placeBeforeTask != null) ? project.getTaskParent(prms.placeBeforeTask) : project;
            List<AUndertaking> siblings = placeBeforeTaskParent.getUndertakings();
            int atIndex = (prms.placeBeforeTask != null) ? siblings.indexOf(prms.placeBeforeTask) : siblings.size();
            String presentationName = (selectedTasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTaskFull);
            AUndertaking lastDuplicate = null;
            for (int i = 0; i < selectedTasks.length; i++) {
                lastDuplicate = duplicateTask(selectedTasks[i], atIndex + i, placeBeforeTaskParent, siblings, ProjectLID.DuplicateTaskFull, presentationName, editSeq);
            }
            // Done with undo/redo steps; add the compound change
            // to the undo manager.
            editSeq.end();
            undoMgr.addEdit(editSeq);
            if (selectedTasks.length == 1) {
                ui.initiateTaskRename(lastDuplicate);
            }
            return true;
        }
    };
}
Also used : ProjectUI(edu.cmu.cs.hcii.cogtool.ui.ProjectUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 42 with CompoundUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.

the class ProjectController method createUngroupAction.

protected IListenerAction createUngroupAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return TaskSelectionState.class;
        }

        public boolean performAction(Object prms) {
            TaskSelectionState seln = (TaskSelectionState) prms;
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION | TaskSelectionState.TASK_GROUPS_ONLY);
            if ((tasks == null) || (tasks.length == 0)) {
                interaction.protestNoSelection();
                return false;
            }
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(L10N.get("PC.Ungroup", "Ungroup"), ProjectLID.Ungroup);
            for (AUndertaking task : tasks) {
                if (task.isTaskGroup()) {
                    TaskGroup group = (TaskGroup) task;
                    List<AUndertaking> childTasks = group.getUndertakings();
                    int numChildTasks = childTasks.size();
                    if (numChildTasks > 0) {
                        AUndertaking[] promoteTasks = new AUndertaking[numChildTasks];
                        childTasks.toArray(promoteTasks);
                        for (int j = numChildTasks - 1; j >= 0; j--) {
                            promoteTask(promoteTasks[j], ProjectLID.Ungroup, editSeq);
                        }
                    }
                }
            }
            deleteTasks(tasks, null, editSeq);
            if (editSeq.isSignificant()) {
                editSeq.end();
                undoMgr.addEdit(editSeq);
            }
            return true;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)42 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)19 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)13 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)13 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)12 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)10 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)9 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)8 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)7 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)6 Design (edu.cmu.cs.hcii.cogtool.model.Design)6 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)6 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)6 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)6 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)5 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)5 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 CogToolLID (edu.cmu.cs.hcii.cogtool.CogToolLID)4 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)4