Example usage for com.intellij.openapi.ui.popup ListPopup addListSelectionListener

List of usage examples for com.intellij.openapi.ui.popup ListPopup addListSelectionListener

Introduction

In this page you can find the example usage for com.intellij.openapi.ui.popup ListPopup addListSelectionListener.

Prototype

void addListSelectionListener(ListSelectionListener listSelectionListener);

Source Link

Usage

From source file:com.intellij.debugger.actions.JvmSmartStepIntoHandler.java

License:Apache License

/**
 * Override this if you haven't PsiMethod, like in Kotlin.
 *
 * @param position//from  w  w  w.j  a  v a  2  s  .co m
 * @param session
 * @param fileEditor
 * @return false to continue for another handler or for default action (step into)
 */
public boolean doSmartStep(SourcePosition position, final DebuggerSession session, TextEditor fileEditor) {
    final List<SmartStepTarget> targets = findSmartStepTargets(position);
    if (!targets.isEmpty()) {
        final SmartStepTarget firstTarget = targets.get(0);
        if (targets.size() == 1) {
            session.stepInto(true, createMethodFilter(firstTarget));
        } else {
            final Editor editor = fileEditor.getEditor();
            final PsiMethodListPopupStep popupStep = new PsiMethodListPopupStep(editor, targets,
                    new PsiMethodListPopupStep.OnChooseRunnable() {
                        public void execute(SmartStepTarget chosenTarget) {
                            session.stepInto(true, createMethodFilter(chosenTarget));
                        }
                    });
            final ListPopup popup = new ListPopupImpl(popupStep) {
                @Override
                protected JComponent createContent() {
                    registerExtraHandleShortcuts(XDebuggerActions.STEP_INTO);
                    registerExtraHandleShortcuts(XDebuggerActions.SMART_STEP_INTO);
                    return super.createContent();
                }

                private void registerExtraHandleShortcuts(String actionName) {
                    AnAction action = ActionManager.getInstance().getAction(actionName);
                    KeyStroke stroke = KeymapUtil.getKeyStroke(action.getShortcutSet());
                    if (stroke != null) {
                        registerAction("handleSelection " + stroke, stroke, new AbstractAction() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                handleSelect(true);
                            }
                        });
                    }
                }
            };
            popup.addListSelectionListener(new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent e) {
                    popupStep.getScopeHighlighter().dropHighlight();
                    if (!e.getValueIsAdjusting()) {
                        final SmartStepTarget selectedTarget = (SmartStepTarget) ((JBList) e.getSource())
                                .getSelectedValue();
                        if (selectedTarget != null) {
                            highlightTarget(popupStep, selectedTarget);
                        }
                    }
                }
            });
            highlightTarget(popupStep, firstTarget);
            final RelativePoint point = DebuggerUIUtil.calcPopupLocation(editor, position.getLine());
            popup.show(point);
        }
        return true;
    }
    return false;
}

From source file:com.vladsch.MissingInActions.util.ui.ComboBoxAction.java

License:Apache License

@Override
public void actionPerformed(AnActionEvent e) {
    JComponent button = (JComponent) e.getPresentation().getClientProperty(CUSTOM_COMPONENT_PROPERTY);
    if (button == null) {
        Component contextComponent = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
        JRootPane rootPane = UIUtil.getParentOfType(JRootPane.class, contextComponent);
        if (rootPane != null) {
            button = (ComboBoxButton) UIUtil.uiTraverser(rootPane).bfsTraversal()
                    .filter(component -> component instanceof ComboBoxButton
                            && ((ComboBoxButton) component).getMyAction() == this)
                    .first();// ww  w.j  a  v  a 2 s .com
        }
        if (button == null)
            return;
    }
    //if (!button.isShowing()) return;
    if (button instanceof ComboBoxButton && button.isShowing()) {
        final Editor editor = e.getData(PlatformDataKeys.EDITOR);
        ((ComboBoxButton) button).myPresentation.putClientProperty(COMBO_BOX_EDITOR_PROPERTY, editor);
        ((ComboBoxButton) button).showPopup();
    } else {
        DataContext context = e.getDataContext();
        Project project = e.getProject();
        if (project == null)
            return;
        final Editor editor = e.getData(PlatformDataKeys.EDITOR);
        DefaultActionGroup group = createPopupActionGroup(button, editor);
        ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(myPopupTitle, group, context,
                myShowNumbers, shouldShowDisabledActions(), false, null, getMaxRows(), getPreselectCondition());
        popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight()));

        JComponent finalButton = button;

        popup.addListSelectionListener(ev -> {
            actionSelected(finalButton, editor, ev);
        });

        popup.addListener(new JBPopupListener() {
            @Override
            public void beforeShown(final LightweightWindowEvent event) {
                popupStart(finalButton, editor);
            }

            @Override
            public void onClosed(final LightweightWindowEvent event) {
                popupDone(finalButton, editor);
            }
        });

        popup.showCenteredInCurrentWindow(project);
    }
}