Search in sources :

Example 31 with AUndertaking

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

the class ProjectUI method createPredicates.

// setUpDragAndDrop
protected void createPredicates() {
    requiresRegenerationPredicate = new ProjectSelectionPredicate(project) {

        @Override
        protected boolean isSatisfiedBy(Design design, AUndertaking t) {
            TaskApplication ta = project.getTaskApplication(t, design);
            if (ta != null) {
                Demonstration demo = ta.getDemonstration();
                return demo.isObsolete();
            }
            return false;
        }
    };
    hasComputableScriptsPredicate = new ProjectSelectionPredicate(project) {

        @Override
        protected boolean isSatisfiedBy(Design design, AUndertaking t) {
            TaskApplication taskApp = project.getTaskApplication(t, design);
            if (taskApp != null) {
                IPredictionAlgo activeAlg = taskApp.determineActiveAlgorithm(project);
                APredictionResult result = taskApp.getResult(taskApp.getFirstModelGenerator(), activeAlg);
                if ((result != null) && !result.canBeRecomputed()) {
                    return false;
                }
                return taskApp.hasComputableScript() && !taskApp.getDemonstration().isInvalid();
            }
            return project.getDefaultAlgo() == SNIFACTPredictionAlgo.ONLY;
        }
    };
    hasComputedResultPredicate = new ProjectSelectionPredicate(project) {

        @Override
        protected boolean isSatisfiedBy(Design design, AUndertaking t) {
            TaskApplication taskApp = project.getTaskApplication(t, design);
            return ((taskApp != null) && taskApp.hasComputedResult());
        }
    };
    hasResultStepsPredicate = new ProjectSelectionPredicate(project) {

        @Override
        protected boolean isSatisfiedBy(Design design, AUndertaking t) {
            TaskApplication taskApp = project.getTaskApplication(t, design);
            return (taskApp != null) && taskApp.hasResultSteps();
        }
    };
    hasScriptsPredicate = new ProjectSelectionPredicate(project) {

        @Override
        protected boolean isSatisfiedBy(Design design, AUndertaking t) {
            TaskApplication taskApp = project.getTaskApplication(t, design);
            return (taskApp != null) && taskApp.hasScript();
        }
    };
    hasTracesPredicate = new ProjectSelectionPredicate(project) {

        @Override
        protected boolean isSatisfiedBy(Design design, AUndertaking t) {
            TaskApplication taskApp = project.getTaskApplication(t, design);
            return (taskApp != null) && taskApp.hasResultTraces();
        }
    };
    hasMultipleScriptsPredicate = new ProjectSelectionPredicate(project) {

        protected int numScripts = 0;

        @Override
        protected void resetState() {
            numScripts = 0;
        }

        @Override
        protected boolean isSatisfiedBy(Design design, AUndertaking t) {
            TaskApplication taskApp = project.getTaskApplication(t, design);
            if (taskApp != null) {
                Iterator<CognitiveModelGenerator> modelGens = taskApp.getModelGenerators();
                while (modelGens.hasNext()) {
                    CognitiveModelGenerator modelGen = modelGens.next();
                    Script script = taskApp.getScript(modelGen);
                    if (script != null) {
                        if (++numScripts > 1) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Iterator(java.util.Iterator) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) ProjectSelectionPredicate(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState.ProjectSelectionPredicate) Point(org.eclipse.swt.graphics.Point)

Example 32 with AUndertaking

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

the class ProjectUI method commitRenameTask.

// initiateTaskRename
/**
     * Reports a task renaming to the controller.
     * @param item
     */
protected boolean commitRenameTask(boolean activeCommit) {
    boolean success = true;
    if (editor.getEditor() != null) {
        Text text = (Text) editor.getEditor();
        String newName = text.getText();
        TreeItem item = editor.getItem();
        // Get task & parent taskgroup from item, don't use this.selection!
        AUndertaking taskToRename = (AUndertaking) item.getData();
        TreeItem parentItem = item.getParentItem();
        TaskGroup parentGroup = (TaskGroup) ((parentItem != null) ? parentItem.getData() : null);
        cleanupTaskEditor();
        success = performAction((CogToolPref.HCIPA.getBoolean()) ? ProjectLID.HCIPARenameTask : ProjectLID.RenameTask, new ProjectUI.TaskRenameEvent(taskToRename, newName, parentGroup), false);
        if (activeCommit) {
            renameTaskItem = null;
        }
    }
    return success;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Text(org.eclipse.swt.widgets.Text) ManagedText(edu.cmu.cs.hcii.cogtool.util.ManagedText) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 33 with AUndertaking

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

the class ProjectMouseState method dealWithMouseDoubleClick.

@Override
protected void dealWithMouseDoubleClick(MouseEvent me) {
    super.dealWithMouseDoubleClick(me);
    TreeItem item = ui.tree.getItem(new Point(me.x, me.y));
    TreeColumn column = ui.findColumn(me.x);
    // check to see if the group visibility should toggle
    if ((item != null) && (column == null)) {
        // Toggle tree expand when a TaskGroup is double-clicked,
        // but not if double-clicking on the first column to edit the name
        AUndertaking u = (AUndertaking) item.getData();
        if (u.isTaskGroup()) {
            item.setExpanded(!item.getExpanded());
        }
    }
    // If on a valid cell, either edit script or open the script viewer
    if ((item != null) && (column != null) && (column.getData() != null)) {
        AUndertaking u = (AUndertaking) item.getData();
        // At the intersection of a task and design
        ProjectContextSelectionState seln = new ProjectContextSelectionState(ui.getProject());
        seln.setSelectedDesign((Design) column.getData());
        seln.addSelectedTask(u);
        if (u.isTaskGroup()) {
            TaskGroup group = (TaskGroup) u;
            if (GroupNature.SUM.equals(group.getNature())) {
                item.setExpanded(true);
                ui.cleanupTaskEditor();
                //TODO: won't work since repaint won't occur until after we're all done.
                ui.performAction(ProjectLID.ViewGroupScript, seln);
            }
        } else {
            ui.cleanupTaskEditor();
            //TODO: won't work since repaint won't occur until after we're all done.
            ui.performAction(ProjectLID.EditScript, seln);
        }
    } else if ((item != null) && (column != null) && (column.getData() == null)) {
        // In a valid row, first column
        if (ui.treeOperationOccurred == 0) {
            ui.initiateTaskRename(item, true);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Point(org.eclipse.swt.graphics.Point) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 34 with AUndertaking

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

the class ProjectSelectionState method getSelectedTaskParents.

/**
     * Retrieves the parents of all selected tasks/groups.
     *
     * @return an array of task groups, using null to signify root tasks/groups
     */
public TaskGroup[] getSelectedTaskParents() {
    int selectedItemCount = getSelectedTaskCount();
    TaskGroup[] parents = new TaskGroup[selectedItemCount];
    Iterator<AUndertaking> selectedTasks = getSelectedTaskIterator();
    int i = 0;
    while (selectedTasks.hasNext()) {
        AUndertaking task = selectedTasks.next();
        parents[i++] = task.getTaskGroup();
    }
    return parents;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 35 with AUndertaking

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

the class ProjectSelectionState method getSelectedTasks.

/**
     * Return the set of selected undertakings (tasks and/or task groups).
     * <p>
     * Although it should not be depended upon, the returned array
     * is generally not <code>null</code> (which would indicate no selected
     * undertakings).  Instead, if there are no selected undertakings,
     * an array of zero length is returned.
     * <p>
     * The mode parameter indicates whether or not to prune the set of selected
     * undertakings (i.e., pruning removes from consideration those selected
     * undertakings that are children of other selected ITaskGroups) and/or
     * whether or not to ensure the selected undertakings are presented in
     * order of their occurrence in the pre-order traversal of the Project's
     * root undertakings.  The constants PRUNE_SELECTION and ORDER_SELECTION
     * may be OR'ed together for both effects.  For neither effect, to achieve
     * the fastest "selection" (e.g., when it is known that only one task is
     * selected), FAST_SELECTION may be used.
     *
     * @param flags whether to prune and/or present
     * @return the set of selected undertakings
     * @author mlh
     */
public AUndertaking[] getSelectedTasks(int flags) {
    boolean prune = (flags & PRUNE_SELECTION) != 0;
    boolean taskGroupsOnly = (flags & TASK_GROUPS_ONLY) != 0;
    List<AUndertaking> keptTasks = new ArrayList<AUndertaking>();
    if ((flags & ORDER_SELECTION) != 0) {
        orderSelection(project.getUndertakings().iterator(), prune, taskGroupsOnly, keptTasks);
    } else {
        Iterator<AUndertaking> allSelectedTasks = getSelectedTaskIterator();
        while (allSelectedTasks.hasNext()) {
            AUndertaking selectedTask = allSelectedTasks.next();
            if ((!prune) || (!isAncestorSelected(selectedTask))) {
                if ((!taskGroupsOnly) || selectedTask.isTaskGroup()) {
                    keptTasks.add(selectedTask);
                }
            }
        }
    }
    AUndertaking[] selection = new AUndertaking[keptTasks.size()];
    keptTasks.toArray(selection);
    return selection;
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) ArrayList(java.util.ArrayList)

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