Search in sources :

Example 11 with TaskParent

use of edu.cmu.cs.hcii.cogtool.model.TaskParent in project cogtool by cogtool.

the class ProjectController method moveTaskAction.

protected boolean moveTaskAction(TaskSelectionState seln, boolean moveEarlier) {
    AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION | TaskSelectionState.ORDER_SELECTION);
    if ((tasks == null) || (tasks.length == 0)) {
        interaction.protestNoSelection();
        return false;
    }
    if (tasks.length > 1) {
        interaction.protestTooManySelectedTasks();
        return false;
    }
    final AUndertaking task = tasks[0];
    final TaskParent parent = project.getTaskParent(task);
    List<AUndertaking> siblings = parent.getUndertakings();
    int siblingCount = siblings.size();
    if (siblingCount == 1) {
        interaction.setStatusMessage(taskIsOnlyChild);
    } else {
        final int oldTaskIndex = siblings.indexOf(task);
        IUndoableEdit edit;
        if (moveEarlier) {
            if (oldTaskIndex == 0) {
                interaction.protestCannotMoveEarlier();
                return false;
            }
            parent.removeUndertaking(task);
            parent.addUndertaking(oldTaskIndex - 1, task);
            edit = new AUndoableEdit(ProjectLID.MoveTaskEarlier) {

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

                @Override
                public void redo() {
                    super.redo();
                    parent.removeUndertaking(task);
                    parent.addUndertaking(oldTaskIndex - 1, task);
                }

                @Override
                public void undo() {
                    super.undo();
                    parent.removeUndertaking(task);
                    parent.addUndertaking(oldTaskIndex, task);
                }
            };
        } else {
            if (oldTaskIndex == siblingCount - 1) {
                interaction.protestCannotMoveLater();
                return false;
            }
            parent.removeUndertaking(task);
            parent.addUndertaking(oldTaskIndex + 1, task);
            edit = new AUndoableEdit(ProjectLID.MoveTaskEarlier) {

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

                @Override
                public void redo() {
                    super.redo();
                    parent.removeUndertaking(task);
                    parent.addUndertaking(oldTaskIndex + 1, task);
                }

                @Override
                public void undo() {
                    super.undo();
                    parent.removeUndertaking(task);
                    parent.addUndertaking(oldTaskIndex, task);
                }
            };
        }
        undoMgr.addEdit(edit);
    }
    return true;
}
Also used : 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) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 12 with TaskParent

use of edu.cmu.cs.hcii.cogtool.model.TaskParent in project cogtool by cogtool.

the class ProjectController method removeChildTasks.

/**
     * Remove child tasks, recording their old parents and indexes
     * of each child in their respective parent.  To restore,
     * add back to the old parents in reverse.
     * <p>
     * Fills in the oldParents and indexes arrays only if not <code>null</code>.
     * <p>
     * It is assumed that the oldParents and indexes arrays are the
     * exact same size as the children array.
     *
     * @param children the tasks to be removed
     * @param oldParents if not <code>null</code>, to hold the corresponding
     *                   parent for each removed task
     * @param indexes    if not <code>null</code>, to hold the index of
     *                   each removed task in its corresponding parent
     * @author mlh
     */
protected void removeChildTasks(AUndertaking[] children, TaskParent[] oldParents, int[] indexes) {
    for (int i = 0; i < children.length; i++) {
        TaskParent parent = project.getTaskParent(children[i]);
        // Save old index for undo
        if (indexes != null) {
            indexes[i] = parent.getUndertakings().indexOf(children[i]);
        }
        // Remove from old parent
        parent.removeUndertaking(children[i]);
        if (oldParents != null) {
            oldParents[i] = parent;
        }
    }
}
Also used : TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)12 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)9 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)9 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)6 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)5 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)4 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)4 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 ProjectUI (edu.cmu.cs.hcii.cogtool.ui.ProjectUI)2 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)2 IOException (java.io.IOException)2 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 ISimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)1 ImportCogToolXML (edu.cmu.cs.hcii.cogtool.model.ImportCogToolXML)1