Java Code Examples for org.openide.windows.TopComponent#getActions()

The following examples show how to use org.openide.windows.TopComponent#getActions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TabbedHandler.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Possibly invokes popup menu. */
public static void handlePopupMenuShowing(MouseEvent e, int idx) {
    Component c = (Component) e.getSource();
    while (c != null && !(c instanceof Tabbed.Accessor))
        c = c.getParent();
    if (c == null) {
        return;
    }
    final Tabbed tab = ((Tabbed.Accessor)c).getTabbed();

    final Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), c);

    final int clickTab = idx;
    Lookup context = null;
    Action[] actions = null;
    if (clickTab >= 0) {

        TopComponent tc = tab.getTopComponentAt(clickTab);
        if(tc != null) {
            // ask also tabbed to possibly alter actions
            actions = tab.getPopupActions(tc.getActions(), clickTab);
            if (actions == null) { 
                actions = tc.getActions();
            }
            if (actions == null || actions.length == 0 )
                return;
            context = tc.getLookup();
        }
    }
    if( null == context ) {
        actions = tab.getPopupActions(new Action[0], -1);
        if (actions == null || actions.length == 0 )
            return;
        context = Lookup.getDefault();
    }

    showPopupMenu(Utilities.actionsToPopup(actions, context), p, c);
}
 
Example 2
Source File: NbEditorKit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addTopComponentActions(JTextComponent component, JPopupMenu popupMenu) {
    Lookup contextLookup = getContextLookup(component);
    // Get the cloneable-editor instance
    TopComponent tc = NbEditorUtilities.getOuterTopComponent(component);
    if (tc != null) {
        // Add all the actions
        Action[] actions = tc.getActions();
        Component[] comps = org.openide.util.Utilities.actionsToPopup(actions, contextLookup).getComponents();
        for (int i = 0; i < comps.length; i++) {
            popupMenu.add(comps[i]);
        }
    }
}