Search in sources :

Example 21 with TaskGroup

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);
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Color(org.eclipse.swt.graphics.Color) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) EventObject(java.util.EventObject)

Example 22 with TaskGroup

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);
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) EventObject(java.util.EventObject)

Example 23 with TaskGroup

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);
        }
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) SNIFACTExecContext(edu.cmu.cs.hcii.cogtool.model.SNIFACTExecContext) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 24 with TaskGroup

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);
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)

Example 25 with TaskGroup

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);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) 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