Search in sources :

Example 56 with TaskApplication

use of edu.cmu.cs.hcii.cogtool.model.TaskApplication 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 57 with TaskApplication

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

the class SWTListGroupScript method getFirstTaskDemo.

protected static Demonstration getFirstTaskDemo(Project project, Project.ITaskDesign td) {
    TaskGroup group = (TaskGroup) td.getTask();
    AUndertaking firstTask = group.getUndertakings().get(0);
    TaskApplication ta = project.getTaskApplication(firstTask, td.getDesign());
    return ta.getDemonstration();
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 58 with TaskApplication

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

the class DemoScriptCmd method regenerateDesignScripts.

public static boolean regenerateDesignScripts(Project project, Design design, Interaction interaction) {
    DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
    Iterator<TaskApplication> designTAs = project.taskApplicationsForDesign(design).values().iterator();
    while (designTAs.hasNext()) {
        TaskApplication ta = designTAs.next();
        Demonstration demo = ta.getDemonstration();
        if (demo.isObsolete() && demo.isEditable()) /*&& ! demo.isInvalid()*/
        {
            demoStateMgr.restoreConformance(demo);
            // Collection of ScriptUndoRedo instances
            regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
        // Variables are ignored; undo/redo will simply re-invoke
        // this method again!
        }
    }
    return true;
}
Also used : TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration)

Example 59 with TaskApplication

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

the class DemoScriptCmd method exportScriptToCSV.

public static boolean exportScriptToCSV(Script script, Project project, Interaction interaction, IUndoableEditSequence editSeq) {
    Demonstration demo = script.getDemonstration();
    TaskApplication ta = demo.getTaskApplication();
    Design design = ta.getDesign();
    AUndertaking task = ta.getTask();
    String name = project.getName();
    name += "_" + design.getName();
    name += "_" + task.getName();
    File dest = null;
    if (interaction != null) {
        dest = interaction.selectCSVFileDest(name);
    } else {
        dest = new File(CogTool.exportCSVKludgeDir, name + ".txt");
    }
    if (dest == null) {
        return false;
    }
    FileWriter fw = null;
    BufferedWriter buffer = null;
    try {
        fw = new FileWriter(dest);
        buffer = new BufferedWriter(fw);
        CSVSupport.writeCell("Format version:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(FORMAT_VERSION, buffer);
        CSVSupport.addLineEnding(buffer);
        Date now = new Date();
        String date = DateFormat.getDateTimeInstance().format(now);
        CSVSupport.writeCell("Date and Time:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(date, buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Project Name:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(project.getName(), buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Design Name:", buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.writeCell(design.getName(), buffer);
        CSVSupport.addLineEnding(buffer);
        CSVSupport.writeCell("Task Hierarchy:", buffer);
        String taskName = task.getFullName();
        String[] cells = taskName.split(":");
        for (String cell : cells) {
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(cell, buffer);
        }
        CSVSupport.addLineEnding(buffer);
        CSVSupport.addSeparator(buffer);
        CSVSupport.addLineEnding(buffer);
        buffer.write("\"Frame\",\"Action\",\"Widget-Name\"," + "\"Displayed-Label\",\"Widget-Type\"");
        CSVSupport.addLineEnding(buffer);
        IWidget lastMovedToWidget = null;
        Iterator<DefaultModelGeneratorState> stepStates = script.getStepStates().iterator();
        while (stepStates.hasNext()) {
            DefaultModelGeneratorState stepState = stepStates.next();
            AScriptStep step = stepState.getScriptStep();
            TransitionSource stepFocus = step.getStepFocus();
            String frameName = step.getCurrentFrame().getName();
            String actionName = KeyDisplayUtil.convertActionToMenuText(step.getLocalizedString());
            if ((!(step instanceof LookAtScriptStep)) && (!(step instanceof ThinkScriptStep)) && (!(step instanceof TextActionSegment))) {
                actionName = step.getLocalizedActionString(actionName, lastMovedToWidget);
            }
            lastMovedToWidget = stepState.getLastMovedToWidget();
            String widgetName = "";
            String widgetType = "";
            String widgetTitle = "";
            if (stepFocus != null) {
                widgetName = stepFocus.getName();
                if (stepFocus instanceof IWidget) {
                    IWidget w = (IWidget) stepFocus;
                    widgetType = w.getWidgetType().toString();
                    String s = w.getTitle();
                    if (s != null) {
                        widgetTitle = s;
                    }
                }
            }
            CSVSupport.writeCell(frameName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(actionName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetName, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetTitle, buffer);
            CSVSupport.addSeparator(buffer);
            CSVSupport.writeCell(widgetType, buffer);
            CSVSupport.addLineEnding(buffer);
        }
        Frame resultFrame = demo.getResultFrame();
        if (resultFrame != null) {
            CSVSupport.writeCell(resultFrame.getName(), buffer);
        }
        if (interaction != null) {
            interaction.setStatusMessage(L10N.get("DSO.ExportCompletedPre", "Export completed to ") + dest + L10N.get("DSO.ExportCompletePost", "."));
        }
    } catch (IOException e) {
        if (interaction != null) {
            interaction.reportProblem("File I/O Error", e.getMessage());
        } else {
            e.printStackTrace();
        }
        return false;
    } finally {
        try {
            if (buffer != null) {
                buffer.close();
            }
            if (fw != null) {
                fw.close();
            }
        } catch (IOException e) {
            if (interaction != null) {
                interaction.reportProblem("File I/O Error on Close", e.getMessage());
            } else {
                e.printStackTrace();
            }
            return false;
        }
    }
    return true;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) FileWriter(java.io.FileWriter) IOException(java.io.IOException) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) Design(edu.cmu.cs.hcii.cogtool.model.Design) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) TextActionSegment(edu.cmu.cs.hcii.cogtool.model.TextActionSegment) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) LookAtScriptStep(edu.cmu.cs.hcii.cogtool.model.LookAtScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) File(java.io.File) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 60 with TaskApplication

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

the class DemoStateManager method ensureTaskApplication.

public static TaskApplication ensureTaskApplication(Project project, AUndertaking task, Design design, CognitiveModelGenerator gen, DemoStateManager demoMgr) {
    TaskApplication ta = project.getTaskApplication(task, design);
    if (ta == null) {
        ta = new TaskApplication(task, design);
        project.setTaskApplication(ta);
        demoMgr.trackEdits(ta.getDemonstration());
    }
    // If no script exists for this cell, create one
    // However, if the given model generator (gen) is null, then don't
    // create a script.
    ensureScript(ta, gen);
    return ta;
}
Also used : TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Aggregations

TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)63 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)38 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)22 Design (edu.cmu.cs.hcii.cogtool.model.Design)20 Script (edu.cmu.cs.hcii.cogtool.model.Script)20 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)17 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)16 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)15 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)14 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)12 IOException (java.io.IOException)12 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)11 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)11 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)10 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)10 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)10 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)8 File (java.io.File)8 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)7 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)5