Search in sources :

Example 6 with IListenerAction

use of edu.cmu.cs.hcii.cogtool.util.IListenerAction 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 7 with IListenerAction

use of edu.cmu.cs.hcii.cogtool.util.IListenerAction 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 8 with IListenerAction

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

the class ProjectController method createChangeTaskPositionAction.

protected IListenerAction createChangeTaskPositionAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectUI.ChangeTaskPositionParms prms = (ProjectUI.ChangeTaskPositionParms) actionParms;
            if ((prms.placeBeforeTask != null) && prms.tasks.isInSelectedHierarchy(prms.placeBeforeTask)) {
                // Nothing to do
                return false;
            }
            if ((prms.tasks == null) || (prms.tasks.getSelectedTaskCount() == 0)) {
                interaction.protestNoSelection();
                return false;
            }
            final AUndertaking[] selectedTasks = prms.tasks.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
            final TaskParent[] oldParents = new TaskParent[selectedTasks.length];
            final int[] indexes = new int[selectedTasks.length];
            final String[] oldNames = new String[selectedTasks.length];
            final TaskParent placeBeforeTaskParent = (prms.placeBeforeTask != null) ? project.getTaskParent(prms.placeBeforeTask) : project;
            final List<AUndertaking> siblings = placeBeforeTaskParent.getUndertakings();
            // If the place-before-task is selected, find the next
            // sibling that is not selected.
            AUndertaking placeBefore = prms.placeBeforeTask;
            if (prms.tasks.isTaskSelected(placeBefore)) {
                int siblingIndex = siblings.indexOf(placeBefore);
                int siblingCount = siblings.size();
                while (++siblingIndex < siblingCount) {
                    placeBefore = siblings.get(siblingIndex);
                    if (!prms.tasks.isTaskSelected(placeBefore)) {
                        break;
                    }
                }
                if (siblingIndex >= siblingCount) {
                    placeBefore = null;
                }
            }
            // Remove first so that the atIndex computation works!
            removeChildTasks(selectedTasks, oldParents, indexes);
            final int atIndex = (placeBefore != null) ? siblings.indexOf(placeBefore) : siblings.size();
            // Add each selected task as siblings before the given task
            for (int i = 0; i < selectedTasks.length; i++) {
                oldNames[i] = selectedTasks[i].getName();
                String newName = NamedObjectUtil.makeNameUnique(oldNames[i], siblings);
                if (!newName.equals(oldNames[i])) {
                    selectedTasks[i].setName(newName);
                }
                placeBeforeTaskParent.addUndertaking(atIndex + i, selectedTasks[i]);
            }
            // Create undo/redo step and add to undo manager
            IUndoableEdit edit = new AUndoableEdit(ProjectLID.ChangeTaskPosition) {

                @Override
                public String getPresentationName() {
                    return (selectedTasks.length > 1) ? MOVE_TASKS : MOVE_TASK;
                }

                @Override
                public void redo() {
                    super.redo();
                    removeChildTasks(selectedTasks, null, null);
                    // before the given task
                    for (int i = 0; i < selectedTasks.length; i++) {
                        String newName = NamedObjectUtil.makeNameUnique(oldNames[i], siblings);
                        if (!newName.equals(oldNames[i])) {
                            selectedTasks[i].setName(newName);
                        }
                        placeBeforeTaskParent.addUndertaking(atIndex + i, selectedTasks[i]);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    removeChildTasks(selectedTasks, null, null);
                    // Un-delete children; IMPORTANT: reverse order!
                    for (int i = selectedTasks.length - 1; 0 <= i; i--) {
                        if (!oldNames[i].equals(selectedTasks[i].getName())) {
                            selectedTasks[i].setName(oldNames[i]);
                        }
                        // Add to old parent at old index
                        oldParents[i].addUndertaking(indexes[i], selectedTasks[i]);
                    }
                }
            };
            undoMgr.addEdit(edit);
            return true;
        }
    };
}
Also used : DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) 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) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 9 with IListenerAction

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

the class ProjectController method createCutDesignAction.

// Action for CutDesign
protected IListenerAction createCutDesignAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignSelectionState selection = (DesignSelectionState) prms;
            Design selectedDesign = selection.getSelectedDesign();
            // Can only cut if a design is currently selected.
            if (selectedDesign != null) {
                if (interaction.confirmDeleteDesign(selectedDesign)) {
                    try {
                        ObjectSaver s = CogToolClipboard.startClipboardDesignSave(project, CogToolClipboard.SAVE_TO_CLIPBOARD);
                        // Delete selected design, copying to the clipboard
                        deleteDesign(selectedDesign, s);
                        s.finish();
                        return true;
                    } catch (IOException e) {
                        throw new RcvrClipboardException(e);
                    } catch (OutOfMemoryError error) {
                        throw new RcvrOutOfMemoryException("Cutting Design", error);
                    }
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)

Example 10 with IListenerAction

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

Aggregations

IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)94 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)29 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)29 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)23 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)23 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)21 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)19 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)17 IOException (java.io.IOException)14 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)13 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)12 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)10 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)10 DesignSelectionState (edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)10 FrameEditorSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)9 FrameSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState)9 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)8 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)8 File (java.io.File)8