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

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

Introduction

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

Prototype

void addListener(@NotNull JBPopupListener listener);

Source Link

Usage

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();/*from  www  .j  a  v a 2 s. c om*/
        }
        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);
    }
}