use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectUIModel method populateRow.
protected void populateRow(AUndertaking undertaking, final TreeItem row) {
taskTreeItems.put(undertaking, row);
row.addListener(SWT.Dispose, onDisposeRow);
// TODO: This is creating a new handler instance for each row
// TODO: reuse a single instance by looking up TreeItem in taskTreeItems?
AlertHandler handler = new AlertHandler() {
public void handleAlert(EventObject alert) {
AUndertaking task = (AUndertaking) row.getData();
row.setText(0, SWTStringUtil.insertEllipsis(task.getName(), 300, StringUtil.EQUAL, tree.getFont()));
setRowBackground(task, row);
}
};
row.setData(undertaking);
undertaking.addHandler(this, NameChangeAlert.class, handler);
row.setText(getTaskRowStrings(undertaking));
Color bkg = setRowBackground(undertaking, row);
int numCols = tree.getColumnCount();
for (int i = 0; i < numCols; i++) {
row.setBackground(i, bkg);
}
if (undertaking.isTaskGroup()) {
TaskGroup group = (TaskGroup) undertaking;
setGroupAlertHandlers(group, row);
addTasks(group.getUndertakings().iterator(), row);
}
row.setExpanded(true);
if (rowHook != null) {
rowHook.onRowCreation(row);
}
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class ProjectUIModel method setGroupAlertHandlers.
// populateRow
protected void setGroupAlertHandlers(TaskGroup group, final TreeItem row) {
AlertHandler handler = new AlertHandler() {
public void handleAlert(EventObject alert) {
TaskGroup.TaskChange chg = (TaskGroup.TaskChange) alert;
if (chg != null) {
if (chg.isAdd) {
TreeItem newRow;
if (chg.atIndex == TaskGroup.TaskChange.AT_END) {
newRow = new TreeItem(row, SWT.NONE);
} else {
newRow = new TreeItem(row, SWT.NONE, chg.atIndex);
}
row.setExpanded(true);
populateRow((AUndertaking) chg.element, newRow);
redisplayResults(newRow);
} else {
TreeItem rowToDelete = findChildRow((AUndertaking) chg.element, row.getItems());
recoverTreeItem(rowToDelete);
}
}
}
};
group.addHandler(this, TaskGroup.TaskChange.class, handler);
handler = new AlertHandler() {
public void handleAlert(EventObject alert) {
// System.out.println("NatureChange!");
// walk up the group tree and recalculate
redisplayResults(row);
}
};
group.addHandler(this, TaskGroup.NatureChange.class, handler);
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class GenerateDictEntriesWorkThread method generateEntries.
protected void generateEntries(Iterator<AUndertaking> tasks, DictEntryGenerator generator, ITermSimilarity alg) {
while (tasks.hasNext() && !isCanceled() && !isStopped()) {
AUndertaking t = tasks.next();
if (t instanceof TaskGroup) {
SNIFACTExecContext context = (SNIFACTExecContext) t.getAttribute(WidgetAttributes.SNIFACT_CONTEXT_ATTR);
if (!NullSafe.equals(context, WidgetAttributes.NO_CONTEXT)) {
generator.generateEntries(context.getParameters().taskName, alg, this, this, requestData.computeAll, computeErrors, progressCallback);
} else {
Iterator<AUndertaking> subTasks = ((TaskGroup) t).getUndertakings().iterator();
generateEntries(subTasks, generator, alg);
}
} else if (!t.isSpawned()) {
generator.generateEntries(t.getName(), alg, this, this, requestData.computeAll, computeErrors, progressCallback);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class HCIPACmd method setFunctionName.
public static void setFunctionName(Project project, final AUndertaking renamedTask, final String newName, CognitiveModelGenerator modelGen, final String undoRenameLabel, IUndoableEditSequence editSeq) {
final TaskGroup parentTask = renamedTask.getTaskGroup();
final String oldName = renamedTask.getName();
final Object oldAttr = parentTask.getAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR);
final String newAttr = parseFunctionName(newName);
renamedTask.setName(newName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, newAttr);
CompoundUndoableEdit edits = new CompoundUndoableEdit(undoRenameLabel, ProjectLID.HCIPARenameTask);
edits.addEdit(new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
renamedTask.setName(newName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, newAttr);
}
@Override
public void undo() {
super.undo();
renamedTask.setName(oldName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, oldAttr);
}
});
// change the task's think step label
Iterator<Design> designs = project.getDesigns().iterator();
while (designs.hasNext()) {
final ThinkScriptStep thinkStep = chgFnName(project, renamedTask, designs.next(), modelGen, DECIDE_TO_USE + newAttr);
// Create undo/redo step and add to undo manager
if (thinkStep != null) {
IUndoableEdit edit = new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
thinkStep.setLabel(DECIDE_TO_USE + newAttr);
}
@Override
public void undo() {
super.undo();
thinkStep.setLabel(DECIDE_TO_USE + oldAttr);
}
};
edits.addEdit(edit);
}
}
edits.end();
editSeq.addEdit(edits);
}
use of edu.cmu.cs.hcii.cogtool.model.TaskGroup in project cogtool by cogtool.
the class PERTChartView method addDesignResults.
protected void addDesignResults(APredictionResult knownResult, Project project, Design design, Iterator<AUndertaking> tasks, List<NamedPredictionResult> availableResults) {
while (tasks.hasNext()) {
AUndertaking task = tasks.next();
if ((design != null) && (task != null)) {
if (task.isTaskGroup()) {
addDesignResults(knownResult, project, design, ((TaskGroup) task).getUndertakings().iterator(), availableResults);
} else {
TaskApplication otherTa = project.getTaskApplication(task, design);
if (otherTa != null) {
Iterator<CognitiveModelGenerator> modGenIt = otherTa.getModelGenerators();
while (modGenIt.hasNext()) {
CognitiveModelGenerator otherModGen = modGenIt.next();
if (otherModGen != null) {
Iterator<IPredictionAlgo> predAlgIt = otherTa.getPredictionAlgs(otherModGen);
while (predAlgIt.hasNext()) {
APredictionResult otherResult = otherTa.getResult(otherModGen, predAlgIt.next());
if ((otherResult != knownResult) && (otherResult != null)) {
String name = otherTa.getDesign().getName() + " : " + otherTa.getTask().getName();
NamedPredictionResult npr = new NamedPredictionResult(otherResult, name);
addAvailableResult(npr, availableResults);
}
}
}
}
}
}
}
}
}
Aggregations