void (final List<? extends AnAction> options, Editor editor) { final ScopeHighlighter highlighter = new ScopeHighlighter(editor); List<MyItem> model = ContainerUtil.map(options, a -> new MyItem(((MyUnwrapAction)a).getName(), options.indexOf(a))); Function<MyItem, MyUnwrapAction> optionByName = item -> (MyUnwrapAction)options.get(item.index); JBPopupFactory.getInstance() .createPopupChooserBuilder(model) .setTitle(CodeInsightBundle.message("unwrap.popup.title")) .setMovable(false) .setNamerForFiltering(item -> item.name) .setSelectionMode(ListSelectionModel.SINGLE_SELECTION) .setResizable(false) .setRequestFocus(true) .setItemChosenCallback((selectedValue) -> optionByName.apply(selectedValue).perform()) .setItemSelectedCallback(item -> { if (item != null) { MyUnwrapAction a = optionByName.apply(item); List<PsiElement> toExtract = new NotNullList<>(); PsiElement wholeRange = a.collectAffectedElements(toExtract); highlighter.highlight(wholeRange, toExtract); } }) .addListener(new JBPopupListener() { @Override public void onClosed(@NotNull LightweightWindowEvent event) { highlighter.dropHighlight(); } }) .createPopup().showInBestPositionFor(editor); }