@NotNull private JList getRunConfigList() { final JList runConfigList = robot.finder().findByType(JBListWithHintProvider.class); pause(new Condition("Wait until the list is populated.") { @Override public boolean test() { //noinspection ConstantConditions return execute(new GuiQuery<Boolean>() { @Override protected Boolean executeInEDT() throws Throwable { return runConfigList.getComponentCount() >= 2; // At least 2, since there is always one option present (the option to edit). } }); } }, SHORT_TIMEOUT); Object selectedValue = execute(new GuiQuery<Object>() { @Override protected Object executeInEDT() throws Throwable { return runConfigList.getSelectedValue(); } }); assertThat(selectedValue).isInstanceOf(PopupFactoryImpl.ActionItem.class); return runConfigList; }
@NotNull public static <T extends PsiElement> JBPopup getPsiElementPopup(@NotNull T[] elements, @NotNull final PsiElementListCellRenderer<T> renderer, @Nullable final String title, @NotNull final PsiElementProcessor<T> processor, @Nullable final T selection) { final JList list = new JBListWithHintProvider(elements) { @Nullable @Override protected PsiElement getPsiElementForHint(Object selectedValue) { return (PsiElement)selectedValue; } }; list.setCellRenderer(renderer); if (selection != null) { list.setSelectedValue(selection, true); } final Runnable runnable = new Runnable() { @Override public void run() { int[] ids = list.getSelectedIndices(); if (ids == null || ids.length == 0) return; for (Object element : list.getSelectedValues()) { if (element != null) { processor.execute((T)element); } } } }; PopupChooserBuilder builder = new PopupChooserBuilder(list); if (title != null) { builder.setTitle(title); } renderer.installSpeedSearch(builder, true); return builder.setItemChoosenCallback(runnable).createPopup(); }
@Override public void beforeShown(final LightweightWindowEvent windowEvent) { final Lookup activeLookup = LookupManager.getInstance(myProject).getActiveLookup(); if (activeLookup != null) { activeLookup.addLookupListener(new LookupAdapter() { @Override public void currentItemChanged(LookupEvent event) { if (windowEvent.asPopup().isVisible()) { //was not canceled yet final LookupElement item = event.getItem(); if (item != null) { PsiElement targetElement = CompletionUtil.getTargetElement(item); if (targetElement == null) { targetElement = DocumentationManager.getInstance(myProject).getElementFromLookup(activeLookup.getEditor(), activeLookup.getPsiFile()); } updatePopup(targetElement); //open next } } else { activeLookup.removeLookupListener(this); } } }); } else { final Component focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject); boolean fromQuickSearch = focusedComponent != null && focusedComponent.getParent() instanceof ChooseByNameBase.JPanelProvider; if (fromQuickSearch) { ChooseByNameBase.JPanelProvider panelProvider = (ChooseByNameBase.JPanelProvider)focusedComponent.getParent(); panelProvider.registerHint(windowEvent.asPopup()); } else if (focusedComponent != null) { if (focusedComponent instanceof JBListWithHintProvider) { ((JBListWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup()); } else if (focusedComponent instanceof JBTableWithHintProvider) { ((JBTableWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup()); } else if (focusedComponent instanceof JBTreeWithHintProvider) { ((JBTreeWithHintProvider)focusedComponent).registerHint(windowEvent.asPopup()); } } } }