Search in sources :

Example 6 with TaskSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.

the class ProjectController method createShowNatureAction.

// Action for ShowSum, ShowMean, ShowMin, and ShowMax
protected IListenerAction createShowNatureAction(final GroupNature nature, final CogToolLID lid) {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            if (prms != null) {
                final List<TaskGroup> groups = new ArrayList<TaskGroup>();
                final List<GroupNature> oldNatures = new ArrayList<GroupNature>();
                TaskSelectionState seln = (TaskSelectionState) prms;
                AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.FAST_SELECTION);
                // Change applies only to task group instances
                for (AUndertaking task : tasks) {
                    if (task.isTaskGroup()) {
                        TaskGroup group = (TaskGroup) task;
                        GroupNature oldNature = group.getNature();
                        // record old value for undo support
                        if (oldNature != nature) {
                            oldNatures.add(oldNature);
                            groups.add(group);
                            group.setNature(nature);
                        }
                    }
                }
                // undo/redo step and add to undo manager
                if (groups.size() > 0) {
                    undoMgr.addEdit(new AUndoableEdit(lid) {

                        @Override
                        public String getPresentationName() {
                            return CHANGE_GROUP_TYPE;
                        }

                        @Override
                        public void redo() {
                            super.redo();
                            for (int i = 0; i < groups.size(); i++) {
                                TaskGroup group = groups.get(i);
                                group.setNature(nature);
                            }
                        }

                        @Override
                        public void undo() {
                            super.undo();
                            for (int i = 0; i < groups.size(); i++) {
                                TaskGroup group = groups.get(i);
                                GroupNature oldNat = oldNatures.get(i);
                                group.setNature(oldNat);
                            }
                        }
                    });
                }
            }
            return true;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

Example 7 with TaskSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.

the class ProjectController method createDemoteTaskAction.

protected IListenerAction createDemoteTaskAction() {
    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);
            if ((tasks == null) || (tasks.length == 0)) {
                interaction.protestNoSelection();
                return false;
            }
            List<String> errors = new ArrayList<String>();
            String editLabel = (tasks.length > 1) ? DEMOTE_TASKS : DEMOTE_TASK;
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(editLabel, ProjectLID.DemoteTask);
            for (AUndertaking task : tasks) {
                String demoteError = demoteTask(task, editSeq);
                if (demoteError != null) {
                    errors.add(demoteError);
                }
            }
            if (errors.size() > 0) {
                interaction.reportProblems(editLabel, errors);
            }
            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) ArrayList(java.util.ArrayList) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)

Example 8 with TaskSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.

the class ProjectController method createDeleteTaskAction.

// createDeleteDesignAction
// Action for DeleteTask
protected IListenerAction createDeleteTaskAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            TaskSelectionState selection = (TaskSelectionState) prms;
            AUndertaking[] selectedTasks = selection.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            // Can only delete if one or more tasks are currently selected.
            if ((selectedTasks != null) && (selectedTasks.length > 0)) {
                if (interaction.confirmDeleteTasks(selectedTasks)) {
                    // Delete tasks without copying to the clipboard.
                    deleteTasks(selectedTasks, null, undoMgr);
                    return true;
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
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)

Example 9 with TaskSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState 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)

Example 10 with TaskSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState in project cogtool by cogtool.

the class ProjectController method createDuplicateTasksAction.

protected IListenerAction createDuplicateTasksAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            TaskSelectionState seln = (TaskSelectionState) prms;
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
            // Can only duplicate if one or more tasks are selected
            if ((tasks != null) && (tasks.length > 0)) {
                String presentationName = (tasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
                CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTask);
                AUndertaking lastDuplicate = null;
                for (AUndertaking task : tasks) {
                    TaskParent parent = project.getTaskParent(task);
                    List<AUndertaking> parentUndertakings = parent.getUndertakings();
                    int atIndex = parentUndertakings.indexOf(task) + 1;
                    lastDuplicate = duplicateTask(task, atIndex, parent, parentUndertakings, ProjectLID.DuplicateTask, presentationName, editSeq);
                }
                // Done with undo/redo steps; add the compound change
                // to the undo manager.
                editSeq.end();
                undoMgr.addEdit(editSeq);
                if (tasks.length == 1) {
                    ui.initiateTaskRename(lastDuplicate);
                }
            } else {
                interaction.protestNoSelection();
            }
            return true;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)12 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)12 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)11 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)4 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)4 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)3 ArrayList (java.util.ArrayList)3 ObjectSaver (edu.cmu.cs.hcii.cogtool.util.ObjectSaver)2 RcvrClipboardException (edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException)2 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)2 RcvrOutOfMemoryException (edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException)2 IOException (java.io.IOException)2 GroupNature (edu.cmu.cs.hcii.cogtool.model.GroupNature)1 Task (edu.cmu.cs.hcii.cogtool.model.Task)1 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)1 DesignSelectionState (edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)1 ProjectContextSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectContextSelectionState)1 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)1 ProjectUI (edu.cmu.cs.hcii.cogtool.ui.ProjectUI)1 SelectionState (edu.cmu.cs.hcii.cogtool.ui.SelectionState)1