Search in sources :

Example 1 with MenuItemDefinition

use of edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition in project cogtool by cogtool.

the class SEDemoUI method populateContextMenu.

protected void populateContextMenu(TransitionSource source, List<MenuItemDefinition> menuItems) {
    Collection<Transition> values = source.getTransitions().values();
    Iterator<Transition> iter = values.iterator();
    SEDemoTransitionLID itemLID;
    while (iter.hasNext()) {
        Transition trans = iter.next();
        SEDemoUI.DemoTransition ftrans = new SEDemoUI.FollowTransition(selection, trans);
        // Add the ftrans to the list in the context menus
        itemLID = new SEDemoTransitionLID("PerformDemoTransition", ftrans);
        String transitionStr = KeyDisplayUtil.convertActionToMenuText(ftrans.getLocalizedString());
        MenuItemDefinition mItem = new SimpleMenuItemDefinition(transitionStr, itemLID, MenuUtil.ENABLED);
        menuItems.add(mItem);
    }
    // Check to see if any transitions are actually available.
    if (values.size() == 0) {
        MenuItemDefinition mItem = new SimpleMenuItemDefinition(L10N.get("SE.DemoNoPredefinedTransitions", "No defined transitions for ") + source.getName(), null);
        // Add a default disabled message
        menuItems.add(mItem);
    }
    boolean selfTransitionOK = true;
    // Add a default look-at transition for all regions except Devices
    if (source.getTransitionSourceType() == TransitionSourceType.Widget) {
        IWidget widget = (IWidget) source;
        Object isSep = widget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
        if ((NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) || (widget.getWidgetType() == WidgetType.Noninteractive) || ((widget instanceof MenuHeader) || (widget instanceof PullDownHeader) || (widget instanceof ContextMenu))) {
            selfTransitionOK = false;
        }
        // Add standard menus to the list of items
        menuItems.add(MenuUtil.SEPARATOR);
        SEDemoUI.DemoTransition lookAtTrans = new SEDemoUI.LookAtTransition(selection, widget);
        // Add default transition options.
        String itemLabel = L10N.get("SE.DemoLookAt", "Look at") + " " + widget.getName();
        itemLID = new SEDemoTransitionLID("PerformDemoLookAtTransition", lookAtTrans);
        menuItems.add(new SimpleMenuItemDefinition(itemLabel, itemLID, MenuUtil.ENABLED));
    }
    if (selfTransitionOK) {
        menuItems.add(MenuUtil.SEPARATOR);
        itemLID = new SEDemoTransitionLID("PerformSelfTransition", new SEDemoUI.SelfTransition(selection, source, null));
        MenuItemDefinition mItem = new SimpleMenuItemDefinition(L10N.get("SE.SelfTransition", "Perform Self-transition"), itemLID, MenuUtil.ENABLED);
        menuItems.add(mItem);
    }
}
Also used : MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) SimpleMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition) ContextMenu(edu.cmu.cs.hcii.cogtool.model.ContextMenu) PullDownHeader(edu.cmu.cs.hcii.cogtool.model.PullDownHeader) SimpleMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition) MenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition) SEDemoTransitionLID(edu.cmu.cs.hcii.cogtool.ui.SEDemoLID.SEDemoTransitionLID) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) EventObject(java.util.EventObject) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 2 with MenuItemDefinition

use of edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition 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 3 with MenuItemDefinition

use of edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition in project cogtool by cogtool.

the class MenuFactory method createProjectModifyMenuDefn.

// createScriptMenuDefn
// View menu items
// Mnemonics:                   Accelerators:
//             Show Min
//             Show Max
//             Show Mean
//             Show Sum
//             Show Standalone Time
//             Show User Time
//             Show Driving Time
//             Show Avg Lane Deviation
//             Show Max Lane Deviation
//             Show Avg Reaction Time
//             Show Max Reaction Time
protected static MenuItemDefinition[] createProjectModifyMenuDefn(boolean research) {
    List<MenuItemDefinition> result = new ArrayList<MenuItemDefinition>();
    result.add(RECOMPUTE_SCRIPT);
    result.add(MenuUtil.SEPARATOR);
    result.add(ADD_DESIGN_DEVICES);
    result.add(MenuUtil.SEPARATOR);
    result.add(new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowSum", "Show &Sum"), CogToolLID.ShowSum, SWT.NONE, SWT.RADIO, false, true));
    result.add(new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowMean", "Show &Mean"), CogToolLID.ShowMean, SWT.NONE, SWT.RADIO));
    result.add(new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowMin", "Show Mi&nimum"), CogToolLID.ShowMin, SWT.NONE, SWT.RADIO));
    result.add(new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowMax", "Show Ma&ximum"), CogToolLID.ShowMax, SWT.NONE, SWT.RADIO));
    // TODO clean up the detritus from this no longer used functionality
    //        if (research) {
    //            result.add(MenuUtil.SEPARATOR);
    //            result.add(DEFAULT_ALGO_CASCADE);
    //            result.add(DEFAULT_EXECUTE_CASCADE);
    //        }
    //              new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowStandaloneTime",
    //                                                    "Show Standalone Time"),
    //                                           CogToolLID.ShowStandaloneTime,
    //                                           SWT.NONE,
    //                                           SWT.RADIO, false, true),
    //              new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowUserTime",
    //                                                    "Show User Time"),
    //                                           CogToolLID.ShowUserTime,
    //                                           SWT.NONE,
    //                                           SWT.RADIO),
    //              new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowDrivingTime",
    //                                                    "Show Driving Time"),
    //                                           CogToolLID.ShowDrivingTime,
    //                                           SWT.NONE,
    //                                           SWT.RADIO),
    ////              MenuUtil.SEPARATOR,
    //              new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowAvgLane",
    //                                                    "Show Avg Lane Deviation"),
    //                                           CogToolLID.ShowAvgLaneDev,
    //                                           SWT.NONE,
    //                                           SWT.RADIO),
    //              new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowMaxLane",
    //                                                    "Show Max Lane Deviation"),
    //                                           CogToolLID.ShowMaxLaneDev,
    //                                           SWT.NONE,
    //                                           SWT.RADIO),
    //              new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowAvgReaction",
    //                                                    "Show Avg Reaction Time"),
    //                                           CogToolLID.ShowAvgReaction,
    //                                           SWT.NONE,
    //                                           SWT.RADIO),
    //              new SimpleMenuItemDefinition(L10N.get("MI.PM.ShowMaxReaction",
    //                                                    "Show Max Reaction Time"),
    //                                           CogToolLID.ShowMaxReaction,
    //                                           SWT.NONE,
    //                                           SWT.RADIO),
    result.add(MenuUtil.SEPARATOR);
    result.add(UNGROUP);
    result.add(MenuUtil.SEPARATOR);
    result.add(PROMOTE_TASK);
    result.add(DEMOTE_TASK);
    result.add(MOVE_EARLIER);
    result.add(MOVE_LATER);
    return result.toArray(new MenuItemDefinition[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) SimpleMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition) 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)

Example 4 with MenuItemDefinition

use of edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition in project cogtool by cogtool.

the class DefaultUI method buildLeadItems.

/**
     * Support for creating the lead items for the Window menu.
     *
     * @param p the project either to restore or as the parent of the
     *          given design
     * @param d the design either to restore or <code>null</code> if
     *          restoring the project's window
     * @author mlh
     */
protected static MenuItemDefinition[] buildLeadItems(Project p, Design d) {
    ListenerIdentifier openProjectLID = null;
    ListenerIdentifier openDesignLID = null;
    boolean openProjectEnabled = MenuUtil.DISABLED;
    boolean openDesignEnabled = MenuUtil.DISABLED;
    String openProjectLabel = OPEN_PROJECT_LABEL;
    String openDesignLabel = OPEN_DESIGN_LABEL;
    // Check to create standard LID's for opening design & project
    if (p != null) {
        openProjectLID = new RestoreParentControllerLID(p, null);
        openProjectEnabled = MenuUtil.ENABLED;
        openProjectLabel = openProjectLabel + ": " + p.getName();
        if (d != null) {
            openDesignLID = new RestoreParentControllerLID(p, d);
            openDesignEnabled = MenuUtil.ENABLED;
            openDesignLabel = openDesignLabel + ": " + d.getName();
        }
    }
    return new MenuItemDefinition[] { new SimpleMenuItemDefinition(openProjectLabel, openProjectLID, openProjectEnabled), new SimpleMenuItemDefinition(openDesignLabel, openDesignLID, openDesignEnabled), MenuUtil.SEPARATOR };
}
Also used : SimpleMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition) SimpleMenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition) MenuItemDefinition(edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition) ListenerIdentifier(edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier)

Aggregations

MenuItemDefinition (edu.cmu.cs.hcii.cogtool.util.MenuUtil.MenuItemDefinition)4 SimpleMenuItemDefinition (edu.cmu.cs.hcii.cogtool.util.MenuUtil.SimpleMenuItemDefinition)4 CascadingMenuItemDefinition (edu.cmu.cs.hcii.cogtool.util.MenuUtil.CascadingMenuItemDefinition)2 ArrayList (java.util.ArrayList)2 ACTRPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)1 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)1 PullDownHeader (edu.cmu.cs.hcii.cogtool.model.PullDownHeader)1 SNIFACTPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.SNIFACTPredictionAlgo)1 Script (edu.cmu.cs.hcii.cogtool.model.Script)1 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)1 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)1 SEDemoTransitionLID (edu.cmu.cs.hcii.cogtool.ui.SEDemoLID.SEDemoTransitionLID)1 ListenerIdentifier (edu.cmu.cs.hcii.cogtool.util.ListenerIdentifier)1 EventObject (java.util.EventObject)1 HashSet (java.util.HashSet)1