Search in sources :

Example 1 with TaskSelectionState

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

the class ProjectController method createCopyTaskAction.

// createRenameDesignAction
// Action for CopyTask
protected IListenerAction createCopyTaskAction() {
    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);
            // Can only copy to clipboard if one or more tasks are selected
            if ((tasks != null) && (tasks.length > 0)) {
                try {
                    ObjectSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
                    for (AUndertaking task : tasks) {
                        s.saveObject(task);
                    }
                    s.finish();
                    if (tasks.length == 1) {
                        interaction.setStatusMessage(TASK_COPIED);
                    } else {
                        interaction.setStatusMessage(TASKS_COPIED);
                    }
                    return true;
                } catch (IOException e) {
                    throw new RcvrClipboardException(e);
                } catch (OutOfMemoryError error) {
                    throw new RcvrOutOfMemoryException("Copying Tasks", error);
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException)

Example 2 with TaskSelectionState

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

the class ProjectController method createNewTaskAction.

// Action for NewTask
protected IListenerAction createNewTaskAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            TaskSelectionState selection = (TaskSelectionState) prms;
            // Figure out what the selection is
            AUndertaking[] selectedTasks = selection.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
            Task newTask = null;
            if ((selectedTasks == null) || (selectedTasks.length == 0)) {
                // No task selection -- add a new root task
                String newTaskName = computeNewTaskName(project, DEFAULT_TASK_PREFIX);
                newTask = addTask(project, project.getUndertakings().size(), newTaskName);
            } else {
                // At least one selected task: add a new sibling after
                // Multiple selected tasks:
                //   if all tasks have same parent,
                //          add new sibling after last selection
                //   if tasks do not have same parent,
                //          add new root task after last selected root
                //          but, if no selected root, add new root at end
                // Get parent
                TaskGroup parent = selection.getSelectedTaskParent();
                if (parent == null) {
                    String newTaskName = computeNewTaskName(project, DEFAULT_TASK_PREFIX);
                    newTask = addTask(project, findLastSelectedRoot(selectedTasks), newTaskName);
                } else {
                    String newTaskName = computeNewTaskName(parent, DEFAULT_TASK_PREFIX);
                    AUndertaking last = selectedTasks[selectedTasks.length - 1];
                    newTask = addTask(parent, parent.getUndertakings().indexOf(last) + 1, newTaskName);
                }
            }
            // Task is automatically selected when added -- rename
            // Cannot put this into the ui because of undo/redo
            ui.initiateTaskRename(newTask);
            return true;
        }
    };
}
Also used : Task(edu.cmu.cs.hcii.cogtool.model.Task) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 3 with TaskSelectionState

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

the class ProjectController method createPromoteTaskAction.

protected IListenerAction createPromoteTaskAction() {
    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) ? PROMOTE_TASKS : PROMOTE_TASK;
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(editLabel, ProjectLID.PromoteTask);
            for (AUndertaking task : tasks) {
                String promoteError = promoteTask(task, ProjectLID.PromoteTask, editSeq);
                if (promoteError != null) {
                    errors.add(promoteError);
                }
            }
            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 4 with TaskSelectionState

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

the class ProjectController method createCutTaskAction.

// Action for CutTask
protected IListenerAction createCutTaskAction() {
    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 cut if one or more tasks are currently selected.
            if ((selectedTasks != null) && (selectedTasks.length > 0)) {
                try {
                    ObjectSaver saver = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyTasks, CogToolClipboard.SAVE_TO_CLIPBOARD);
                    deleteTasks(selectedTasks, saver, undoMgr);
                    // flush!
                    saver.finish();
                    return true;
                } catch (IOException e) {
                    throw new RcvrClipboardException("Could not execute cut", e);
                } catch (OutOfMemoryError error) {
                    throw new RcvrOutOfMemoryException("Cutting Tasks", error);
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException)

Example 5 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