private static boolean showPopupIfNeedTo( @NotNull JBPopup popup, @NotNull RelativePoint popupPosition) { if (!popup.isDisposed() && !popup.isVisible()) { popup.show(popupPosition); return true; } else { return false; } }
@Override public void setPopupVisible(boolean visible) { if (!isSwingPopup()) { if (visible && (myJBPopup == null || myJBPopup.isDisposed())) { final JBList list = createJBList(getModel()); myJBPopup = JBPopupFactory.getInstance() .createListPopupBuilder(list) .setItemChoosenCallback( new Runnable() { @Override public void run() { final Object value = list.getSelectedValue(); if (value != null) { configureEditor(getEditor(), value); IdeFocusManager.getGlobalInstance().requestFocus(ComboBox.this, true); assert myJBPopup != null; ComboBox.this.getUI().setPopupVisible(ComboBox.this, false); myJBPopup.cancel(); } } }) .setFocusOwners(new Component[] {this}) .setMinSize(new Dimension(getWidth(), -1)) .createPopup(); list.setBorder(IdeBorderFactory.createEmptyBorder()); myJBPopup.showUnderneathOf(this); list.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent e) { ComboBox.this.getUI().setPopupVisible(ComboBox.this, false); myJBPopup.cancel(); } }); } return; } if (getModel().getSize() == 0 && visible) return; if (visible && JBPopupFactory.getInstance().getChildFocusedPopup(this) != null) return; final boolean wasShown = isPopupVisible(); super.setPopupVisible(visible); if (!wasShown && visible && isEditable() && !UIManager.getBoolean("ComboBox.isEnterSelectablePopup")) { final ComboBoxEditor editor = getEditor(); final Object item = editor.getItem(); final Object selectedItem = getSelectedItem(); if (isSwingPopup() && (item == null || item != selectedItem)) { configureEditor(editor, selectedItem); } } }