Example usage for com.intellij.openapi.ui.popup PopupChooserBuilder setRequestFocus

List of usage examples for com.intellij.openapi.ui.popup PopupChooserBuilder setRequestFocus

Introduction

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

Prototype

@Override
    public PopupChooserBuilder<T> setRequestFocus(final boolean requestFocus) 

Source Link

Usage

From source file:com.intellij.tasks.actions.SearchSupport.java

License:Apache License

private void showPopup(boolean explicit) {

    myCancelled = false;//from w ww.j  av  a  2  s. c  o m

    List<T> list = getItems(myTextField.getText());
    myListModel.clear();
    myListModel.addAll(list);

    if (list.isEmpty()) {
        if (explicit) {
            showNoSuggestions();
        } else {
            hideCurrentPopup();
        }
        return;
    }

    ensureSelectionExists();

    myList.setPrototypeCellValue(null);
    if (isPopupShowing()) {
        adjustPopupSize();
        return;
    }

    hideCurrentPopup();

    final PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(myList);
    builder.addListener(new JBPopupListener() {
        public void beforeShown(LightweightWindowEvent event) {
            myTextField.registerKeyboardAction(myCancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
                    JComponent.WHEN_IN_FOCUSED_WINDOW);
        }

        public void onClosed(LightweightWindowEvent event) {
            myTextField.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
        }
    });
    myCurrentPopup = builder.setRequestFocus(false).setAutoSelectIfEmpty(false).setResizable(false)
            .setCancelCallback(new Computable<Boolean>() {
                public Boolean compute() {
                    final int caret = myTextField.getCaretModel().getOffset();
                    getEditor().getSelectionModel().setSelection(caret, caret);
                    myTextField.setFocusTraversalKeysEnabled(true);
                    ApplicationManager.getApplication().invokeLater(new Runnable() {
                        public void run() {
                            myTextField.requestFocus();
                        }
                    });
                    return Boolean.TRUE;
                }
            }).setItemChoosenCallback(new Runnable() {
                public void run() {
                    processChosenFromCompletion();
                }
            }).setCancelKeyEnabled(false).setAlpha(0.1f).setFocusOwners(new Component[] { myTextField })
            .createPopup();

    adjustPopupSize();
    showPopup();
}