DiscoveredTestsTree (@NotNull Project project, @NotNull DataContext dataContext, @NotNull String title, @Nullable String place) { DiscoveredTestsTree tree = new DiscoveredTestsTree(title); String initTitle = JavaCompilerBundle.message("test.discovery.tests.tab.title", title); Ref<JBPopup> ref = new Ref<>(); ConfigurationContext context = ConfigurationContext.getFromContext(dataContext, place); ActiveComponent runButton = createButton(JavaCompilerBundle.message("action.run.all.affected.tests.text"), AllIcons.Actions.Execute, () -> runAllDiscoveredTests(project, tree, ref, context, initTitle), tree); Runnable pinActionListener = () -> { UsageView view = FindUtil.showInUsageView(null, tree.getTestMethods(), param -> param, initTitle, p -> { p.setCodeUsages(false); // don't show r/w, imports filtering actions p.setMergeDupLinesAvailable(false); p.setUsageTypeFilteringAvailable(false); p.setExcludeAvailable(false); }, project); if (view != null) { view.addButtonToLowerPane(new AbstractAction(JavaCompilerBundle.message("action.run.all.affected.tests.text"), AllIcons.Actions.Execute) { @Override public void actionPerformed(ActionEvent e) { runAllDiscoveredTests(project, tree, ref, context, initTitle); } }); } JBPopup popup = ref.get(); if (popup != null) { popup.cancel(); } }; KeyStroke findUsageKeyStroke = findUsagesKeyStroke(); String pinTooltip = IdeBundle.message("show.in.find.window.button.name") + (findUsageKeyStroke == null ? "" : " " + KeymapUtil.getKeystrokeText(findUsageKeyStroke)); ActiveComponent pinButton = createButton(pinTooltip, AllIcons.General.Pin_tab, pinActionListener, tree); PopupChooserBuilder<?> builder = new PopupChooserBuilder(tree) .setTitle(initTitle) .setMovable(true) .setResizable(true) .setCommandButton(new CompositeActiveComponent(pinButton)) .setSettingButton(new CompositeActiveComponent(runButton).getComponent()) .setItemChosenCallback(() -> PsiNavigateUtil.navigate(tree.getSelectedElement())) .registerKeyboardAction(findUsageKeyStroke, __ -> pinActionListener.run()) .setMinSize(new JBDimension(500, 300)) .setDimensionServiceKey(ShowAffectedTestsAction.class.getSimpleName()); JBPopup popup = builder.createPopup(); ref.set(popup); TreeModel model = tree.getModel(); Disposer.register(popup, tree); model.addTreeModelListener(new TreeModelAdapter() { @Override protected void process(@NotNull TreeModelEvent event, @NotNull EventType type) { int testsCount = tree.getTestCount(); int classesCount = tree.getTestClassesCount(); popup.setCaption(JavaCompilerBundle.message("popup.title.affected.tests.counts", testsCount, testsCount == 1 ? 0 : 1, classesCount, classesCount == 1 ? 0 : 1, title)); } }); popup.showInBestPositionFor(dataContext); return tree; }