AbstractPopup: intercept other show() methods. ChooserInterceptor: use UIUtil.findComponentOfType

This commit is contained in:
Tagir Valeev
2019-03-11 10:49:30 +07:00
parent a99dc56f10
commit d3e23bbb38
2 changed files with 5 additions and 4 deletions
@@ -406,6 +406,7 @@ public class AbstractPopup implements JBPopup {
@Override
public void showCenteredInCurrentWindow(@NotNull Project project) {
if (UiInterceptors.tryIntercept(this)) return;
Window window = null;
Component focusedComponent = getWndManager().getFocusedComponent(project);
@@ -760,6 +761,7 @@ public class AbstractPopup implements JBPopup {
}
public void show(Component owner, int aScreenX, int aScreenY, final boolean considerForcedXY) {
if (UiInterceptors.tryIntercept(this)) return;
if (ApplicationManagerEx.getApplicationEx() != null && ApplicationManager.getApplication().isHeadlessEnvironment()) return;
if (isDisposed()) {
throw new IllegalStateException("Popup was already disposed. Recreate a new instance to show again");
@@ -3,6 +3,7 @@ package com.intellij.ui;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.ui.components.JBList;
import com.intellij.util.ui.UIUtil;
import one.util.streamex.IntStreamEx;
import one.util.streamex.StreamEx;
import org.intellij.lang.annotations.RegExp;
@@ -10,7 +11,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.regex.Pattern;
@@ -39,10 +39,9 @@ public class ChooserInterceptor extends UiInterceptors.UiInterceptor<JBPopup> {
@Override
protected void doIntercept(JBPopup popup) {
JComponent component = popup.getContent();
JBList<?> content = StreamEx.ofTree((Component)component, Container.class, c -> StreamEx.of(c.getComponents()))
.select(JBList.class).findFirst().orElse(null);
JBList<?> content = UIUtil.findComponentOfType(component, JBList.class);
if (content == null) {
fail("Expected chooser; got: " + component);
fail("JBList not found under " + component);
}
ListModel<?> model = content.getModel();
List<String> actualOptions = IntStreamEx.range(model.getSize()).mapToObj(model::getElementAt).map(Object::toString).toList();