Search in sources :

Example 1 with ActionManager

use of org.openide.actions.ActionManager in project ACS by ACS-Community.

the class ToolsAction method generate.

/** Implementation method that regenerates the items in the menu or
    * in the array.
    *
    * @param forMenu true if Presenter.Menu should be used false if Presenter.Popup
    * @param list (can be null)
    */
private static List generate(Action toolsAction, boolean forMenu) {
    ActionManager am = (ActionManager) Lookup.getDefault().lookup(ActionManager.class);
    SystemAction[] actions = am.getContextActions();
    List list = new ArrayList(actions.length);
    boolean separator = false;
    // flag to prevent adding separator before actual menu items
    boolean firstItemAdded = false;
    // Get action context.
    Lookup lookup;
    if (toolsAction instanceof Lookup.Provider) {
        lookup = ((Lookup.Provider) toolsAction).getLookup();
    } else {
        lookup = null;
    }
    for (int i = 0; i < actions.length; i++) {
        Action a;
        // Retrieve context sensitive action instance if possible.
        if (lookup != null && actions[i] instanceof ContextAwareAction) {
            a = ((ContextAwareAction) actions[i]).createContextAwareInstance(lookup);
        } else {
            a = actions[i];
        }
        if (a == null) {
            if (firstItemAdded)
                separator = true;
        } else if (forMenu) {
            if (a instanceof Presenter.Menu && a.isEnabled()) {
                if (separator) {
                    list.add(null);
                    separator = false;
                }
                JMenuItem mi = ((Presenter.Menu) a).getMenuPresenter();
                list.add(mi);
                firstItemAdded = true;
            }
        } else if (a instanceof Presenter.Popup && a.isEnabled()) {
            if (separator) {
                list.add(null);
                separator = false;
            }
            JMenuItem mi = ((Presenter.Popup) a).getPopupPresenter();
            list.add(mi);
            firstItemAdded = true;
        }
    }
    return list;
}
Also used : ContextAwareAction(org.openide.util.ContextAwareAction) ContextAwareAction(org.openide.util.ContextAwareAction) ActionManager(org.openide.actions.ActionManager) Lookup(org.openide.util.Lookup) JInlineMenu(org.openide.awt.JInlineMenu)

Aggregations

ActionManager (org.openide.actions.ActionManager)1 JInlineMenu (org.openide.awt.JInlineMenu)1 ContextAwareAction (org.openide.util.ContextAwareAction)1 Lookup (org.openide.util.Lookup)1