Search in sources :

Example 36 with AUndertaking

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

the class ProjectSelectionState method getSelectedTask.

/**
     * Returns the single selected task.  If zero tasks or more than one task
     * is selected, then IllegalStateException is thrown.
     */
public AUndertaking getSelectedTask() {
    String errorMsg;
    Iterator<AUndertaking> taskIt = getSelectedTaskIterator();
    if (taskIt.hasNext()) {
        AUndertaking selectedTask = taskIt.next();
        if (!taskIt.hasNext()) {
            return selectedTask;
        }
        errorMsg = "Selection is multiple";
    } else {
        errorMsg = "Nothing is selected";
    }
    throw new IllegalStateException(errorMsg);
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking)

Example 37 with AUndertaking

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

the class ProjectSelectionState method getSelectedTaskParent.

/**
     * Retrieves the parent task group that contains the selected undertaking.
     *
     * @return the parent task group if a all selected undertakings have the
     *         same parent; <code>null</code> is returned if there are no
     *         selected undertakings or if there are multiple selected
     *         undertakings with different parents or if all selected
     *         undertakings are top-level.
     */
public TaskGroup getSelectedTaskParent() {
    boolean first = true;
    TaskGroup allParent = null;
    // Examine the parent task group for each selected undertaking
    Iterator<AUndertaking> taskIt = getSelectedTaskIterator();
    while (taskIt.hasNext()) {
        AUndertaking item = taskIt.next();
        TaskGroup parentOfItem = item.getTaskGroup();
        // then null is the only possible response.
        if (parentOfItem == null) {
            return null;
        }
        // Remember first parent to compare against the remaining ones
        if (first) {
            first = false;
            allParent = parentOfItem;
        } else if (parentOfItem != allParent) {
            // return null
            return null;
        }
    }
    // If there is no selected undertaking, return null
    if (allParent == null) {
        return null;
    }
    // Otherwise, return the shared parent task group
    return allParent;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 38 with AUndertaking

use of edu.cmu.cs.hcii.cogtool.model.AUndertaking 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 39 with AUndertaking

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

the class ResultDisplayPolicy method computeGroup.

// getTaskApplicationCell
/**
     * Recursively computes value of script results on a particular design
     * for tasks within a group.
     *
     * @param group the group whose resVal to calculate
     * @param d the design whose script results should be used here
     * @return the recursive value of script results on design d
     *         for tasks in the given TaskGroup; -1.0 if the group is empty
     */
public static double computeGroup(Project project, TaskGroup group, Design d) {
    List<AUndertaking> children = group.getUndertakings();
    if (children.size() == 0) {
        // trivial case
        return TimePredictionResult.UNSET_TIME;
    }
    GroupNature nature = group.getNature();
    boolean validReturnValue = false;
    double returnValue = 0.0d;
    double meanDivisor = 0.0d;
    for (AUndertaking child : children) {
        double stepValue = TimePredictionResult.UNSET_TIME;
        if (child.isTaskGroup()) {
            // recursive (TaskGroup) case
            stepValue = computeGroup(project, (TaskGroup) child, d);
        } else {
            // terminal case
            TaskApplication ta = project.getTaskApplication(child, d);
            if (ta != null) {
                APredictionResult result = ta.getResult(ta.getFirstModelGenerator(), ta.determineActiveAlgorithm(project));
                stepValue = getComputationResult(result);
            }
        }
        if ((nature == GroupNature.SUM) || (nature == GroupNature.MEAN)) {
            if (stepValue != TimePredictionResult.UNSET_TIME) {
                returnValue += stepValue;
                meanDivisor += 1.0d;
                validReturnValue = true;
            }
        } else if (nature == GroupNature.MIN) {
            if ((stepValue != TimePredictionResult.UNSET_TIME) && ((stepValue < returnValue) || (!validReturnValue))) {
                returnValue = stepValue;
                validReturnValue = true;
            }
        } else if (nature == GroupNature.MAX) {
            if (stepValue > returnValue) {
                returnValue = stepValue;
                validReturnValue = true;
            }
        }
    }
    if (validReturnValue) {
        if ((nature == GroupNature.MEAN) && (meanDivisor != 0.0d)) {
            returnValue /= meanDivisor;
        }
        return returnValue;
    }
    return TimePredictionResult.UNSET_TIME;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

Example 40 with AUndertaking

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

the class ScriptViewerUIModel method dispose.

/**
     * Dispose: clear the currentFrame of the window, and remove all handlers
     */
@Override
public void dispose() {
    TaskGroup group = (TaskGroup) taskDesign.getTask();
    Iterator<AUndertaking> tasks = group.getUndertakings().iterator();
    while (tasks.hasNext()) {
        AUndertaking childTask = tasks.next();
        TaskApplication tApp = project.getTaskApplication(childTask, design);
        if (tApp != null) {
            Script script = tApp.getOnlyScript();
            script.removeAllHandlers(this);
            script.getDemonstration().removeAllHandlers(this);
        }
    }
    super.dispose();
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Aggregations

AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)89 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)38 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)35 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)28 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)24 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)18 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)17 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 Script (edu.cmu.cs.hcii.cogtool.model.Script)13 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)13 IOException (java.io.IOException)12 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)11 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)9 TreeItem (org.eclipse.swt.widgets.TreeItem)9 ArrayList (java.util.ArrayList)7