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);
}
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;
}
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);
}
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;
}
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();
}
Aggregations