Search in sources :

Example 16 with IPredictionAlgo

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

the class ProjectController method createSetAlgorithmAction.

protected IListenerAction createSetAlgorithmAction(final IPredictionAlgo alg, final CogToolLID lid, final String actionString) {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object actionParms) {
            ProjectSelectionState selState = (ProjectSelectionState) actionParms;
            Design design = selState.getSelectedDesign();
            AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            // iterate through tasks and get set of TaskApplications
            final TaskApplication[] taskApps = new TaskApplication[tasks.length];
            final IPredictionAlgo[] oldAlgos = new IPredictionAlgo[tasks.length];
            for (int i = 0; i < tasks.length; i++) {
                // Make sure that the task application exists, and create it
                // if it does not.  No need to ensure a script.
                TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
                taskApps[i] = ta;
                oldAlgos[i] = ta.getActiveAlgorithm();
                // now set the new algorithm
                ta.setActiveAlgorithm(alg);
            }
            undoMgr.addEdit(new AUndoableEdit(lid) {

                @Override
                public String getPresentationName() {
                    return actionString;
                }

                @Override
                public void redo() {
                    super.redo();
                    for (TaskApplication taskApp : taskApps) {
                        taskApp.setActiveAlgorithm(alg);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setActiveAlgorithm(oldAlgos[i]);
                    }
                }
            });
            return true;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 17 with IPredictionAlgo

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

the class ProjectController method openProjectOnCompute.

/**
     * editSeq will be null if no regeneration occurred; otherwise,
     * the edit sequence will contain the undoable edit for the regeneration.
     */
public static boolean openProjectOnCompute(Project project, final Script script, final APredictionResult newResult, CompoundUndoableEdit editSeq) {
    boolean notModified;
    try {
        notModified = UndoManager.isAtSavePoint(project);
    } catch (IllegalStateException ex) {
        System.err.println("Ignoring that isAtSavePoint failed.");
        notModified = false;
    }
    ProjectController c = ProjectController.openController(project, false, notModified);
    final CognitiveModelGenerator modelGen = script.getModelGenerator();
    final IPredictionAlgo computeAlg = newResult.getPredictionAlgorithm();
    final TaskApplication taskApp = script.getDemonstration().getTaskApplication();
    final APredictionResult oldResult = taskApp.getResult(modelGen, computeAlg);
    taskApp.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(newResult));
    UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
    IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {

        protected APredictionResult redoResult = newResult;

        protected APredictionResult undoResult = oldResult;

        @Override
        public String getPresentationName() {
            return COMPUTE_SCRIPT;
        }

        @Override
        public void redo() {
            super.redo();
            redoResult = PredictionResultProxy.getLatestResult(redoResult);
            taskApp.setResult(modelGen, computeAlg, redoResult);
        }

        @Override
        public void undo() {
            super.undo();
            undoResult = PredictionResultProxy.getLatestResult(undoResult);
            taskApp.setResult(modelGen, computeAlg, undoResult);
        }
    };
    if (editSeq != null) {
        editSeq.addEdit(edit);
        editSeq.end();
        edit = editSeq;
    }
    // Add to script's undo mgr first to set owner properly
    scriptUndoMgr.addEdit(edit);
    c.undoMgr.addEdit(edit);
    c.takeFocus();
    return true;
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 18 with IPredictionAlgo

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

the class ProjectView method getContextMenuForIntersection.

public Menu getContextMenuForIntersection(Project project, AUndertaking undertaking, Design design) {
    // Get the task application being clicked on
    TaskApplication ta = project.getTaskApplication(undertaking, design);
    boolean hasExternalFile = false;
    boolean isVisualizable = false;
    Set<IPredictionAlgo> algsWithResults = new HashSet<IPredictionAlgo>();
    IPredictionAlgo algo = null;
    if (ta != null) {
        // TODO: mlh make access to model gen algo generic
        Script script = ta.getScript(KLMCognitiveGenerator.ONLY);
        if (script != null) {
            if (script.getAssociatedPath() != null) {
                hasExternalFile = true;
            }
            // as well as the list of algorithms with results in the ta
            Iterator<IPredictionAlgo> algsIt = ta.getPredictionAlgs(script.getModelGenerator());
            while (algsIt.hasNext()) {
                IPredictionAlgo i = algsIt.next();
                if (i != null) {
                    algsWithResults.add(i);
                }
            }
        }
        // And whether or not ta has a visualizable result
        isVisualizable = ta.hasResultSteps(ta.determineActiveAlgorithm(project));
        algo = ta.getActiveAlgorithm();
    }
    //      that the following test will have to suffice.
    if (algo == null) {
        algo = ACTR6PredictionAlgo.ONLY;
    }
    contextMenus.setContextSelection(View.CONTEXT);
    if (undertaking.isTaskGroup()) {
        if (CogToolPref.HCIPA.getBoolean()) {
            return contextMenus.getMenu(HCIPA_GROUP_CELL_MENU);
        }
        if (CogToolPref.RESEARCH.getBoolean()) {
            return contextMenus.getMenu(RESEARCH_GROUP_CELL_MENU);
        }
        return contextMenus.getMenu(GROUP_CELL_MENU);
    }
    // create cascading menus for algorithm (now called "Usability Metric" BEJoh 25mar2011)
    MenuItemDefinition algCascade = null;
    if (CogToolPref.RESEARCH.getBoolean()) {
        List<MenuItemDefinition> algList = new ArrayList<MenuItemDefinition>();
        algList.add(ALG_ACTR6_ITEM);
        algList.add(ALG_SNIFACT_ITEM);
        if (algsWithResults.contains(HumanDataAlgo.ONLY)) {
            algList.add(ALG_HUMAN_DATA_ITEM);
        }
        algCascade = new CascadingMenuItemDefinition(L10N.get("MI.PV.AlgorithmType", //                                                        "Algorithm Type"),
        "Usability Metric"), algList.toArray(new MenuItemDefinition[algList.size()]));
        // test for active algorithm
        // TODO Do we really want to use this idiom? It seems nauseating on
        //      at least three counts:
        //      1) setting a field of a constant is confusing--no one
        //         looking at these constants elsewhere is going to be
        //         expecting them to mutate out from under them
        //      2) while it does seem unlikely re-entrancy will in practice
        //         be an issue here, using application-wide globals as a way
        //         of passing essentially local information is suspect
        //      3) it's a dangerously fragile idiom--for any of these
        //         fields you ever fiddle, you really, truly HAVE to set them to
        //         either true or false every time--can't count on any defaults,
        //         or you'll be using stale data from the previous time around
        ALG_ACTR6_ITEM.selectedInitially = (algo == ACTR6PredictionAlgo.ONLY);
        ALG_HUMAN_DATA_ITEM.selectedInitially = (algo == HumanDataAlgo.ONLY);
        ALG_SNIFACT_ITEM.selectedInitially = (algo == SNIFACTPredictionAlgo.ONLY);
        // TODO speaking of "it's a dangerously fragile idiom," the following
        //      code wasn't originally correct, as nothing ever got
        //      deselected, demonstrating my point #3, above!
        //      [while this is now fixed, I believe, I'm leaving a TODO here
        //       as a sort of continuation of the one above to which it refers]
        // test for background run
        Boolean computeInBkg = null;
        if (ta != null) {
            computeInBkg = ta.getComputeInBackground();
        }
        //      we do the following test will have to suffice.
        if (computeInBkg == null) {
            computeInBkg = TaskApplication.RUN_IN_FOREGROUND;
        }
        ALG_IN_BACKGROUND.selectedInitially = (computeInBkg == TaskApplication.RUN_IN_BACKGROUND);
        ALG_IN_FOREGROUND.selectedInitially = (computeInBkg == TaskApplication.RUN_IN_FOREGROUND);
    }
    // build custom menu
    List<MenuItemDefinition> taskCellContextMenuDef = new ArrayList<MenuItemDefinition>();
    SHOW_MODEL_VISUALIZATION.enabledInitially = isVisualizable;
    taskCellContextMenuDef.add(SHOW_MODEL_VISUALIZATION);
    taskCellContextMenuDef.add(MenuUtil.SEPARATOR);
    taskCellContextMenuDef.add(EDIT_SCRIPT);
    IPredictionAlgo a = (algo != null ? algo : project.getDefaultAlgo());
    if (a instanceof ACTRPredictionAlgo || a instanceof SNIFACTPredictionAlgo) {
        if (CogToolPref.RESEARCH.getBoolean()) {
            // TODO it is disgusting the way this stuff is all cloned; when
            //      we have time we need to think through a consistent design
            //      to be shared across all backends
            EDIT_ACTR_MODEL_ITEM.enabledInitially = hasExternalFile;
            GENERATE_ACTR_MODEL_ITEM.enabledInitially = (ta != null);
            taskCellContextMenuDef.add(EDIT_ACTR_MODEL_ITEM);
            taskCellContextMenuDef.add(GENERATE_ACTR_MODEL_ITEM);
        }
        taskCellContextMenuDef.add(MenuUtil.SEPARATOR);
    }
    taskCellContextMenuDef.add(RECOMPUTE_SCRIPT);
    if (algCascade != null) {
        taskCellContextMenuDef.add(MenuUtil.SEPARATOR);
        taskCellContextMenuDef.add(algCascade);
        taskCellContextMenuDef.add(EXECUTE_CASCADE);
    }
    taskCellContextMenuDef.add(MenuUtil.SEPARATOR);
    taskCellContextMenuDef.add(EDIT_DESIGN);
    taskCellContextMenuDef.add(RENAME_DESIGN);
    taskCellContextMenuDef.add(DUPLICATE_DESIGN);
    taskCellContextMenuDef.add(MenuUtil.SEPARATOR);
    if (CogToolPref.RESEARCH.getBoolean()) {
        taskCellContextMenuDef.add(IMPORT_HUMAN_CSV);
        taskCellContextMenuDef.add(MenuUtil.SEPARATOR);
        taskCellContextMenuDef.add(MenuFactory.EXPORT_DESIGN_TO_HTML);
    }
    taskCellContextMenuDef.add(MenuFactory.EXPORT_SCRIPT_TO_CSV);
    taskCellContextMenuDef.add(MenuFactory.EXPORT_RESULTS_TO_CSV);
    if (CogToolPref.RESEARCH.getBoolean()) {
        taskCellContextMenuDef.add(EXPORT_TO_XML);
        taskCellContextMenuDef.add(EXPORT_ACTR_MODEL);
        taskCellContextMenuDef.add(EXPORT_TRACELINES);
        taskCellContextMenuDef.add(EXPORT_FOR_SANLAB);
        if (CogToolPref.HCIPA.getBoolean()) {
            taskCellContextMenuDef.add(MenuFactory.EXPORT_TO_HCIPA);
        }
        taskCellContextMenuDef.add(MenuUtil.SEPARATOR);
        taskCellContextMenuDef.add(DISPLAY_TRACELINES);
    }
    if (CogToolPref.RESEARCH.getBoolean()) {
        taskCellContextMenuDef.add(MenuUtil.SEPARATOR);
        taskCellContextMenuDef.add(GENERATE_DICT_ENTRIES);
        taskCellContextMenuDef.add(EDIT_DICT);
    }
    return contextMenus.createDynamicMenu(taskCellContextMenuDef);
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ArrayList(java.util.ArrayList) CascadingMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.CascadingMenuItemDefinition) SimpleMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition) MenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition) CascadingMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.CascadingMenuItemDefinition) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) SNIFACTPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo) ACTRPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo) HashSet(java.util.HashSet)

Example 19 with IPredictionAlgo

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

the class ProjectUI method setViewEnabledState.

/**
     * Enables or disables LIDs as appropriate
     * @param sel the selection state on which to base enabling/disabling
     * @param availability NORMAL or CONTEXT
     * @see ListenerIdentifierMap
     */
protected void setViewEnabledState(ProjectSelectionState sel, Boolean availability) {
    boolean hasDesign = sel.getSelectedDesign() != null;
    setEnabled(CogToolLID.AddDesignDevices, availability, hasDesign);
    String scriptLabel = "";
    scriptLabel = hasMultipleScripts(sel) ? " " + SCRIPTS_LABEL : " " + SCRIPT_LABEL;
    String label = "";
    int selectedTaskCount = sel.getSelectedTaskCount();
    boolean isSnifActTask = snifActTasksSelected(sel, TaskSelectionState.PRUNE_SELECTION);
    boolean isSnifActGroup = snifActTasksSelected(sel, TaskSelectionState.TASK_GROUPS_ONLY);
    if (selectedTaskCount > 0) {
        AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
        boolean allGroups = true;
        for (int i = 0; i < tasks.length; i++) {
            if (!tasks[i].isTaskGroup()) {
                allGroups = false;
            }
        }
        if (allGroups) {
            label = (selectedTaskCount > 1) ? (" " + TASK_GROUPS_LABEL) : (" " + TASK_GROUP_LABEL);
        } else {
            label = (selectedTaskCount > 1) ? (" " + TASKS_LABEL) : (" " + TASK_LABEL);
        }
    }
    if (hasDesign) {
        label = " " + DESIGN_LABEL;
        setEnabled(CogToolLID.ExportToXML, ListenerIdentifierMap.ALL, MenuUtil.ENABLED, L10N.get("PR.ExportDesignXMLLabel", "Export Design to XML"));
    } else {
        setEnabled(CogToolLID.ExportToXML, ListenerIdentifierMap.ALL, MenuUtil.ENABLED, EXPORT_PROJECT_LABEL);
    }
    String cutCopyLabel = (editor.getEditor() != null) ? "" : label;
    String regenerateString = regenerateTitle;
    boolean requiresRegeneration = selectionRequiresRegeneration(sel);
    if (requiresRegeneration) {
        regenerateString += scriptLabel;
    }
    setEnabled(CogToolLID.RegenerateScript, availability, requiresRegeneration, regenerateString);
    AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
    boolean singleTask = selectedTaskCount == 1;
    boolean cellSelected = hasDesign && singleTask;
    boolean anySelection = hasDesign || (selectedTaskCount > 0);
    setEnabled(CogToolLID.ExportDesignToHTML, availability, hasDesign);
    setEnabled(ProjectLID.ExportDictToCSV, availability, hasDesign);
    setEnabled(ProjectLID.ImportDict, availability, hasDesign);
    setEnabled(CogToolLID.CaptureBehavior, availability, true);
    if (cellSelected) {
        setEnabled(CogToolLID.Paste, availability, false);
        setEnabled(CogToolLID.Duplicate, availability, false, MenuFactory.DUPLICATE_STRING);
        setEnabled(CogToolLID.Rename, availability, false, MenuFactory.RENAME_STRING);
        setEnabled(CogToolLID.Cut, availability, false, MenuFactory.CUT_STRING);
        setEnabled(CogToolLID.Copy, availability, false, MenuFactory.COPY_STRING);
        setEnabled(CogToolLID.Delete, availability, false, MenuFactory.DELETE_STRING);
        String editLabel = MenuFactory.EDIT_STRING + " " + SCRIPT_LABEL;
        boolean editEnabled = true;
        if (tasks[0].isTaskGroup()) {
            if (GroupNature.SUM.equals(((TaskGroup) tasks[0]).getNature())) {
                editLabel = VIEW_SCRIPTS;
            } else {
                editLabel = MenuFactory.EDIT_STRING;
                editEnabled = false;
            }
        }
        setEnabled(CogToolLID.Edit, availability, editEnabled, editLabel);
        if (isSnifActTask) {
            // If it's a task generated by a run of SNIF-ACT (and therefore
            // put in a group that has that attribute), the algorithm in its
            // cell should never be changed.
            setEnabled(ProjectLID.SetAlgorithmACTR6, availability, false);
            setEnabled(ProjectLID.SetAlgorithmSNIFACT, availability, false);
            setEnabled(ProjectLID.SetAlgorithmDefault, availability, false);
            setEnabled(ProjectLID.SetAlgorithmHuman, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationDefault, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationFalse, availability, false);
            setEnabled(ProjectLID.SetBackgroundComputationTrue, availability, false);
        }
    } else if (isSnifActTask) {
        setEnabled(CogToolLID.Paste, availability, false);
        setEnabled(CogToolLID.Duplicate, availability, false, MenuFactory.DUPLICATE_STRING);
        setEnabled(CogToolLID.Cut, availability, false, MenuFactory.CUT_STRING);
        setEnabled(CogToolLID.Copy, availability, false, MenuFactory.COPY_STRING);
        setEnabled(CogToolLID.Rename, availability, hasDesign || singleTask, MenuFactory.RENAME_STRING + label);
        setEnabled(CogToolLID.NewTask, availability, false);
        setEnabled(CogToolLID.NewTaskGroup, availability, false);
    } else {
        setEnabled(CogToolLID.NewTask, availability, true);
        setEnabled(CogToolLID.NewTaskGroup, availability, true);
        setEnabled(CogToolLID.Paste, availability, true);
        String dupString = MenuFactory.DUPLICATE_STRING;
        if (anySelection) {
            dupString += label;
        }
        setEnabled(CogToolLID.Duplicate, availability, anySelection, dupString);
        // Edit enabled if only a single design selected
        String editString = MenuFactory.EDIT_STRING;
        if (hasDesign) {
            editString += label;
        }
        setEnabled(CogToolLID.Edit, availability, hasDesign, editString);
        // Rename enabled if a single selection
        boolean enabled = hasDesign || singleTask;
        String renameString = MenuFactory.RENAME_STRING;
        if (enabled) {
            renameString += label;
        }
        setEnabled(CogToolLID.Rename, availability, enabled, renameString);
        // Cut, Copy, Delete, DeselectAll should be enabled
        //   if there is any selection (task or design)
        setEnabled(CogToolLID.Cut, availability, anySelection, MenuFactory.CUT_STRING + cutCopyLabel);
        setEnabled(CogToolLID.Copy, availability, anySelection, MenuFactory.COPY_STRING + cutCopyLabel);
        setEnabled(CogToolLID.Delete, availability, anySelection, MenuFactory.DELETE_STRING + label);
        setEnabled(CogToolLID.DeselectAll, availability, anySelection);
    }
    boolean showRecompute = anySelection && taskHasComputableScripts(sel);
    if (!showRecompute && hasDesign && sel.getSelectedTaskCount() == 1) {
        Design design = sel.getSelectedDesign();
        TaskApplication taskApp = project.getTaskApplication(sel.getSelectedTask(), design);
        if (taskApp != null && taskApp.getActiveAlgorithm() instanceof SNIFACTPredictionAlgo) {
            showRecompute = true;
        }
    }
    String recomputeString = recomputeTitle;
    if (showRecompute) {
        recomputeString += scriptLabel;
    }
    // If the user wants to call recompute let them.
    setEnabled(CogToolLID.RecomputeScript, availability, showRecompute, recomputeString);
    // The export trace is only available when a script is
    // computed && there are traces to export.
    boolean hasComputedResult = selectionHasComputedResult(sel);
    boolean showExport = anySelection && //hasComputedResult &&
    selectionHasTraces(sel);
    setEnabled(ProjectLID.ExportTraces, availability, showExport);
    setEnabled(ProjectLID.DisplayTraces, availability, showExport);
    setEnabled(ProjectLID.ExportForSanlab, availability, showExport);
    // Show Visualization should only be available when a script is
    // computed/valid && there are ResultSteps to visualize.
    boolean showVis = anySelection && hasComputedResult && selectionHasResultSteps(sel);
    setEnabled(ProjectLID.ShowModelVisualization, availability, showVis);
    // The export device and script lisp files
    // is only available when a script is valid
    // valid IE: not null, not invalid
    boolean showExportFiles = anySelection && selectionHasScripts(sel) && hasComputedResult;
    setEnabled(ProjectLID.ExportActrModelFile, availability, showExportFiles);
    // Default to off; fix if truly enabled
    setEnabled(ProjectLID.MoveTaskEarlier, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.MoveTaskLater, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, false);
    setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, false);
    // Allow "vertical" movement if effectively only one task is selected
    if ((tasks != null) && !hasDesign) {
        if (singleTask) {
            boolean spawned = tasks[0].isSpawned();
            TaskGroup parent = tasks[0].getTaskGroup();
            List<AUndertaking> siblings;
            if (parent != null) {
                setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, !spawned);
                siblings = parent.getUndertakings();
            } else {
                siblings = project.getUndertakings();
            }
            int siblingCount = siblings.size();
            int atIndex = siblings.indexOf(tasks[0]);
            if (siblingCount > 1) {
                boolean notFirstChild = (atIndex > 0);
                setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, notFirstChild && !spawned);
                setEnabled(ProjectLID.MoveTaskEarlier, ListenerIdentifierMap.ALL, notFirstChild && !spawned);
                setEnabled(ProjectLID.MoveTaskLater, ListenerIdentifierMap.ALL, (atIndex < siblingCount - 1) && !spawned);
            }
        } else if (tasks.length > 1) {
            // Too many tasks selected to check conditions;
            // let the controller handle the error cases.
            setEnabled(ProjectLID.PromoteTask, ListenerIdentifierMap.ALL, !isSnifActTask);
            setEnabled(ProjectLID.DemoteTask, ListenerIdentifierMap.ALL, !isSnifActTask);
        }
    }
    // Stuff that is enabled only when a script exists.
    boolean canExport = false;
    if (hasDesign) {
        Design design = sel.getSelectedDesign();
        for (AUndertaking task : tasks) {
            if (taskHasScripts(task, design)) {
                canExport = true;
            }
        }
    }
    setEnabled(CogToolLID.ExportScriptToCSV, availability, canExport);
    // Enable "Show XXX" options if any task groups are selected
    boolean enabled = false;
    int numTaskGroups = 0;
    TaskGroup group = null;
    for (AUndertaking task : tasks) {
        if (task.isTaskGroup()) {
            enabled = true;
            numTaskGroups++;
            group = (TaskGroup) task;
        }
    }
    setEnabled(ProjectLID.Ungroup, availability, enabled && !isSnifActGroup);
    setEnabled(CogToolLID.ShowSum, availability, enabled && !isSnifActGroup);
    setEnabled(CogToolLID.ShowMean, availability, enabled);
    setEnabled(CogToolLID.ShowMin, availability, enabled);
    setEnabled(CogToolLID.ShowMax, availability, enabled);
    setSelected(CogToolLID.ShowSum, availability, false);
    setSelected(CogToolLID.ShowMean, availability, false);
    setSelected(CogToolLID.ShowMin, availability, false);
    setSelected(CogToolLID.ShowMax, availability, false);
    if (enabled) {
        if (numTaskGroups == 1) {
            GroupNature nature = group.getNature();
            CogToolLID id = null;
            if (nature == GroupNature.SUM) {
                id = CogToolLID.ShowSum;
            } else if (nature == GroupNature.MEAN) {
                id = CogToolLID.ShowMean;
            } else if (nature == GroupNature.MIN) {
                id = CogToolLID.ShowMin;
            } else if (nature == GroupNature.MAX) {
                id = CogToolLID.ShowMax;
            }
            setSelected(id, availability, true);
        }
    }
    IPredictionAlgo defaultAlgo = project.getDefaultAlgo();
    // enabled state for default algorithm settings
    setSelected(ProjectLID.SetProjDefaultAlgoACTR, availability, defaultAlgo == ACTR6PredictionAlgo.ONLY);
    setSelected(ProjectLID.SetProjDefaultAlgoSNIFACT, availability, defaultAlgo == SNIFACTPredictionAlgo.ONLY);
    setSelected(ProjectLID.SetProjExecBackground, availability, project.getDefaultRunInBackground());
    setSelected(ProjectLID.SetProjExecForeground, availability, !project.getDefaultRunInBackground());
    // (TODO: same level/contiguous/subtrees for Group Tasks???)
    // if the user has named the task (created the group), he can export
    boolean canExportHCIPA = false;
    if ((tasks != null) && (tasks.length > 0)) {
        // Must have selected a top-level group
        for (AUndertaking task : tasks) {
            if (task.isTaskGroup() && (task.getTaskGroup() == null)) {
                canExportHCIPA = true;
            }
        }
    } else if (hasDesign) {
        // At least one top-level task must be a group
        Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
        while (allTasks.hasNext()) {
            AUndertaking u = allTasks.next();
            if (u.isTaskGroup()) {
                canExportHCIPA = true;
            }
        }
    }
    setEnabled(ProjectLID.ExportToHCIPA, availability, canExportHCIPA);
    if (hasDesign) {
        ISimilarityDictionary dict = (ISimilarityDictionary) sel.getSelectedDesign().getAttribute(WidgetAttributes.DICTIONARY_ATTR);
        String newLabel = NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY) ? L10N.get("WT.GenerateDictionary", "Generate Dictionary...") : L10N.get("WT.UpdateDictionary", "Update Dictionary...");
        setEnabled(ProjectLID.GenerateDictionary, availability, !isSnifActTask, newLabel);
    } else if (tasks.length > 0) {
        List<Design> designs = project.getDesigns();
        String newLabel = designs.size() > 1 ? L10N.get("WT.UpdateDictionaries", "Update Dictionaries...") : L10N.get("WT.UpdateDictionary", "Update Dictionary...");
        setEnabled(ProjectLID.GenerateDictionary, availability, !isSnifActTask, newLabel);
    }
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) Point(org.eclipse.swt.graphics.Point) Design(edu.cmu.cs.hcii.cogtool.model.Design) CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Iterator(java.util.Iterator) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) SNIFACTPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo) List(java.util.List) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

Aggregations

IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)19 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)15 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)10 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)7 Design (edu.cmu.cs.hcii.cogtool.model.Design)7 Script (edu.cmu.cs.hcii.cogtool.model.Script)7 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)7 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)7 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)6 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)5 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)5 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)5 ACTRPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)4 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)4 RcvrUnimplementedFnException (edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException)4 File (java.io.File)4 IOException (java.io.IOException)4 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)3 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3