Search in sources :

Example 6 with TaskGroup

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

the class ScriptViewerUI method getSelectedScript.

protected Script getSelectedScript(DefaultModelGeneratorState stepState) {
    SWTList swtList = view.getScriptEditorList();
    if (stepState == null) {
        TaskGroup group = (TaskGroup) task;
        List<AUndertaking> tasks = group.getUndertakings();
        int numTasks = tasks.size();
        for (int i = numTasks - 1; i >= 0; i--) {
            AUndertaking t = tasks.get(i);
            TaskApplication ta = project.getTaskApplication(t, design);
            if (ta != null) {
                return ta.getOnlyScript();
            }
        }
    }
    TableItem item = swtList.getItemList().get(stepState);
    return (Script) item.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
}
Also used : SWTList(edu.cmu.cs.hcii.cogtool.view.SWTList) Script(edu.cmu.cs.hcii.cogtool.model.Script) SWTListGroupScript(edu.cmu.cs.hcii.cogtool.view.SWTListGroupScript) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TableItem(org.eclipse.swt.widgets.TableItem) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 7 with TaskGroup

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

the class ProjectController method promoteTask.

protected String promoteTask(final AUndertaking task, CogToolLID lid, IUndoableEditSequence editSeq) {
    final TaskGroup parent = task.getTaskGroup();
    if (parent == null) {
        return cannotPromoteTaskError + ": " + task.getFullName();
    }
    List<AUndertaking> siblings = parent.getUndertakings();
    final int indexInParent = siblings.indexOf(task);
    final TaskParent grandparent = project.getTaskParent(parent);
    List<AUndertaking> uncles = grandparent.getUndertakings();
    final int newTaskIndex = uncles.indexOf(parent) + 1;
    final String oldTaskName = task.getName();
    final int adoptedSiblingCount = siblings.size() - indexInParent - 1;
    final AUndertaking asUndertaking = ((task instanceof TaskGroup) || (adoptedSiblingCount == 0)) ? task : new TaskGroup(task.getName(), GroupNature.SUM);
    final TaskGroup asTaskGroup = asUndertaking.isTaskGroup() ? (TaskGroup) asUndertaking : null;
    // Must treat associated task-applications as deleted if the
    // promotion changed the undertaking from a task to a task group.
    final Map<ITaskDesign, TaskApplication> assocTAs = (asUndertaking != task) ? project.taskApplicationsForRemovedTask(task) : null;
    final AUndertaking[] adoptedSiblings = (adoptedSiblingCount > 0) ? new AUndertaking[adoptedSiblingCount] : null;
    final String[] oldSiblingNames = (adoptedSiblingCount > 0) ? new String[adoptedSiblingCount] : null;
    // Delete task and later siblings from parent
    parent.removeUndertaking(task);
    for (int i = 0; i < adoptedSiblingCount; i++) {
        adoptedSiblings[i] = siblings.get(indexInParent);
        if (oldSiblingNames != null) {
            oldSiblingNames[i] = adoptedSiblings[i].getName();
        }
        parent.removeUndertaking(adoptedSiblings[i]);
        // Insert later siblings as children of asTaskGroup
        makeTaskNameUnique(asTaskGroup, adoptedSiblings[i]);
        asTaskGroup.addUndertaking(adoptedSiblings[i]);
    }
    // Insert task at newTaskIndex into grandparent
    makeTaskNameUnique(grandparent, asUndertaking);
    grandparent.addUndertaking(newTaskIndex, asUndertaking);
    // Create undoable edit
    IUndoableEdit edit = new AUndoableEdit(lid) {

        protected Map<ITaskDesign, TaskApplication> associatedTAs = assocTAs;

        protected boolean recoverMgrs = true;

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

        @Override
        public void redo() {
            super.redo();
            recoverMgrs = true;
            associatedTAs = (asUndertaking != task) ? project.taskApplicationsForRemovedTask(task) : null;
            for (int i = 0; i < adoptedSiblingCount; i++) {
                parent.removeUndertaking(adoptedSiblings[i]);
                makeTaskNameUnique(asTaskGroup, adoptedSiblings[i]);
                asTaskGroup.addUndertaking(adoptedSiblings[i]);
            }
            parent.removeUndertaking(task);
            makeTaskNameUnique(grandparent, asUndertaking);
            grandparent.addUndertaking(newTaskIndex, asUndertaking);
        }

        @Override
        public void undo() {
            super.undo();
            recoverMgrs = false;
            grandparent.removeUndertaking(asUndertaking);
            task.setName(oldTaskName);
            parent.addUndertaking(indexInParent, task);
            if (asUndertaking != task) {
                project.restoreRemovedTaskApplications(associatedTAs);
            }
            for (int i = 0; i < adoptedSiblingCount; i++) {
                asTaskGroup.removeUndertaking(adoptedSiblings[i]);
                if (oldSiblingNames != null) {
                    adoptedSiblings[i].setName(oldSiblingNames[i]);
                }
                parent.addUndertaking(indexInParent + i + 1, adoptedSiblings[i]);
            }
        }

        @Override
        public void die() {
            super.die();
            if (recoverMgrs && (asUndertaking != task)) {
                recoverManagers(task, associatedTAs);
            }
        }
    };
    editSeq.addEdit(edit);
    return null;
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with TaskGroup

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

the class ProjectController method addTaskGroup.

// createNewTaskGroupAction
/**
     * Add a new task group inside an existing task group.
     *
     * @param parent the task parent where the task will be added
     * @param prev the task immediately before the position
     *             of the new task group (or null for first position)
     * @param selection tasks to be moved into new group as children
     * @param lid the undo/redo command token
     * @param presentationName the undo/redo command label
     * @param editSeq the undo/redo sequence to hold the new edit
     * @return created and added task group
     */
protected TaskGroup addTaskGroup(TaskParent parent, int atIndex, String newGroupName, AUndertaking[] children, CogToolLID lid, String presentationName, IUndoableEditSequence editSeq) {
    TaskGroup newGroup = new TaskGroup(newGroupName, GroupNature.SUM);
    // Add to parent at index
    parent.addUndertaking(atIndex, newGroup);
    TaskParent[] oldParents = new TaskParent[children.length];
    int[] indexes = new int[children.length];
    // Move children & create undo
    removeChildTasks(children, oldParents, indexes);
    addToTaskGroup(children, newGroup);
    // Create undo/redo step and add to undo manager
    editSeq.addEdit(createNewTaskGroupUndo(parent, atIndex, newGroup, oldParents, indexes, children, lid, presentationName));
    return newGroup;
}
Also used : TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 9 with TaskGroup

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

the class ProjectController method demoteTask.

protected String demoteTask(final AUndertaking task, IUndoableEditSequence editSeq) {
    final TaskParent parent = project.getTaskParent(task);
    List<AUndertaking> siblings = parent.getUndertakings();
    final int indexInParent = siblings.indexOf(task);
    if (indexInParent == 0) {
        return cannotDemoteTaskError + ": " + task.getFullName();
    }
    final String oldTaskName = task.getName();
    final AUndertaking prevSibling = siblings.get(indexInParent - 1);
    final TaskGroup siblingAsTaskGroup = (prevSibling instanceof TaskGroup) ? (TaskGroup) prevSibling : new TaskGroup(prevSibling.getName(), GroupNature.SUM);
    if (siblingAsTaskGroup.getUndertakings().size() > 0) {
        AUndertaking firstTask = siblingAsTaskGroup.getUndertakings().get(0);
        if (firstTask.isSpawned()) {
            return cannotDemoteIntoGroupError;
        }
    }
    // Must treat sibling's task-applications as deleted if the
    // demotion changed it from a task to a task group
    final Map<ITaskDesign, TaskApplication> siblingAssocTAs = (siblingAsTaskGroup != prevSibling) ? project.taskApplicationsForRemovedTask(prevSibling) : null;
    // Remove task from parent and replace previousSibling with
    // new task group if not already one.
    parent.removeUndertaking(task);
    if (siblingAsTaskGroup != prevSibling) {
        parent.removeUndertaking(prevSibling);
        parent.addUndertaking(indexInParent - 1, siblingAsTaskGroup);
    }
    // Insert task as the last child of siblingAsTaskGroup
    makeTaskNameUnique(siblingAsTaskGroup, task);
    siblingAsTaskGroup.addUndertaking(task);
    // Create undoable edit
    IUndoableEdit edit = new AUndoableEdit(ProjectLID.DemoteTask) {

        protected Map<ITaskDesign, TaskApplication> siblingTAs = siblingAssocTAs;

        protected boolean recoverMgrs = true;

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

        @Override
        public void redo() {
            super.redo();
            recoverMgrs = true;
            siblingTAs = (siblingAsTaskGroup != prevSibling) ? project.taskApplicationsForRemovedTask(prevSibling) : null;
            // Remove task from parent and replace previousSibling with
            // new task group if not already one.
            parent.removeUndertaking(task);
            if (siblingAsTaskGroup != prevSibling) {
                parent.removeUndertaking(prevSibling);
                parent.addUndertaking(indexInParent - 1, siblingAsTaskGroup);
            }
            // Insert task as the last child of siblingAsTaskGroup
            makeTaskNameUnique(siblingAsTaskGroup, task);
            siblingAsTaskGroup.addUndertaking(task);
        }

        @Override
        public void undo() {
            super.undo();
            recoverMgrs = false;
            // Remove task from sibling group; rename back
            siblingAsTaskGroup.removeUndertaking(task);
            task.setName(oldTaskName);
            // Restore sibling as a task if necessary
            if (siblingAsTaskGroup != prevSibling) {
                parent.removeUndertaking(siblingAsTaskGroup);
                parent.addUndertaking(indexInParent - 1, prevSibling);
                project.restoreRemovedTaskApplications(siblingTAs);
            }
            // Add task back to parent
            parent.addUndertaking(indexInParent, task);
        }

        @Override
        public void die() {
            super.die();
            if (recoverMgrs && (siblingAsTaskGroup != prevSibling)) {
                recoverManagers(task, siblingTAs);
            }
        }
    };
    editSeq.addEdit(edit);
    return null;
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) Map(java.util.Map) HashMap(java.util.HashMap) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 10 with TaskGroup

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

the class ProjectController method computeSnifAct.

// assignActions
protected boolean computeSnifAct(Design design, AUndertaking task, IUndoableEditSequence editSequence, SNIFACTGroupParameters defaults) {
    // TODO: L10N required for error titles and messages.
    if (design == null) {
        interaction.reportProblem("SNIF-ACT", "No design is selected.");
        return false;
    }
    if (design.getFrames().size() == 0) {
        interaction.reportProblem("SNIF-ACT", "Selected design is empty.");
        return false;
    }
    if (task.isTaskGroup()) {
        // We can only recompute with this algorithm if the
        // group was generated by a previous SNIF-ACT
        // computation (and thus has the execution
        // context attribute)
        Object contextAttr = task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
        if (NullSafe.equals(contextAttr, WidgetAttributes.NO_CONTEXT)) {
            interaction.reportProblem("SNIF-ACT", "Can't recompute with this algorithm from this cell.");
            return false;
        }
    }
    ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
    if (dict == null) {
        interaction.reportProblem("Export Dictionary", "No dictionary exists for the selected design");
        return false;
    }
    List<Frame> sortedFrames = NamedObjectUtil.getSortedList(design.getFrames());
    SNIFACTParameters parms;
    int addGroupMode;
    boolean hasScript = false;
    final SNIFACTExecContext prevContext;
    if (task.isTaskGroup()) {
        // Since we got this far, we know the group already has
        // parameters associated with it, so use those values as
        // defaults in the dialog box
        prevContext = (SNIFACTExecContext) task.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
        parms = prevContext.getParameters();
        addGroupMode = SNIFACTDialog.ENABLED;
    } else {
        // Otherwise, create a new set of default values for this
        // execution
        String defaultName = sortedFrames.get(0).getName();
        List<String> targets = new ArrayList<String>();
        targets.add(defaultName);
        parms = new SNIFACTParameters(task.getName(), NUM_SNIF_ACT_TRIALS, SNIF_ACT_K_VALUE, defaultName, targets, ITermSimilarity.ALL);
        addGroupMode = SNIFACTDialog.NONE;
        prevContext = null;
        TaskApplication ta = project.getTaskApplication(task, design);
        hasScript = (ta != null) && ta.hasScript();
    }
    SNIFACTGroupParameters groupParms = null;
    if (defaults == null) {
        groupParms = interaction.requestSNIFACTParameters(hasScript, sortedFrames, parms, dict.getAlgorithmsInUse(), addGroupMode);
    } else {
        groupParms = new SNIFACTGroupParameters(defaults.taskName, defaults.numRuns, defaults.kValue, defaults.startFrame, defaults.targetFrames, defaults.algorithm, ((addGroupMode != SNIFACTDialog.NONE) && defaults.addToGroup));
    }
    if (groupParms == null) {
        return false;
    }
    SNIFACTPredictionAlgo.ONLY.setParameters(groupParms);
    TaskParent parent = task.getTaskGroup();
    if (parent == null) {
        parent = project;
    }
    final TaskGroup group;
    if (groupParms.addToGroup) {
        // user wants to add new trial tasks to the same group
        group = (TaskGroup) task;
    } else {
        Collection<AUndertaking> siblings = parent.getUndertakings();
        group = new TaskGroup(SNIFACTCmd.getGroupName(groupParms, siblings), GroupNature.MEAN);
    }
    final SNIFACTExecContext context = SNIFACTCmd.computeInBackground(project, design, interaction, group, groupParms);
    if (context == null) {
        return true;
    }
    group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context);
    CompoundUndoableEdit snifActEditSeq = new CompoundUndoableEdit(SNIFACT_COMPUTATION, ProjectLID.RecomputeScript);
    if (!task.isTaskGroup()) {
        snifActEditSeq.addEdit(HCIPACmd.replaceTask(project, parent, task, group, SNIFACT_COMPUTATION));
    } else {
        if (groupParms.addToGroup) {
            snifActEditSeq.addEdit(SNIFACTCmd.addTasksToGroup(project, group, context, SNIFACT_COMPUTATION));
        } else {
            snifActEditSeq.addEdit(SNIFACTCmd.addGroup(project, parent, group, SNIFACT_COMPUTATION));
        }
    }
    snifActEditSeq.addEdit(new AUndoableEdit(ProjectLID.RecomputeScript) {

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

        @Override
        public void redo() {
            super.redo();
            group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, context);
        }

        @Override
        public void undo() {
            super.undo();
            group.setAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR, prevContext);
        }
    });
    snifActEditSeq.end();
    if (editSequence != null) {
        editSequence.addEdit(snifActEditSeq);
    }
    return true;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ArrayList(java.util.ArrayList) SNIFACTGroupParameters(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo.SNIFACTGroupParameters) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) SNIFACTParameters(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo.SNIFACTParameters) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) SNIFACTExecContext(edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Aggregations

TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)43 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)35 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)16 Design (edu.cmu.cs.hcii.cogtool.model.Design)10 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)9 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)8 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)8 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 Script (edu.cmu.cs.hcii.cogtool.model.Script)6 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)6 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)5 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)4 GroupNature (edu.cmu.cs.hcii.cogtool.model.GroupNature)4 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)4 HashMap (java.util.HashMap)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 SNIFACTExecContext (edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext)3 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)3