ActionGroup (@Nullable Object target, @NotNull Consumer<? super T> onChosen) { DefaultActionGroup group = new DefaultActionGroup(); String clearText = getClearValueText(target); Function<T, AnAction> choseAction = t -> { String nullValue = StringUtil.notNullize(clearText); AnAction a = new DumbAwareAction(renderValue(t, nullValue), "", getActionListIcon(target, t)) { @Override public void actionPerformed(@NotNull AnActionEvent e) { onChosen.consume(t); } }; a.getTemplatePresentation().setText(renderValue(t, nullValue)); return a; }; if (clearText != null) { group.add(choseAction.fun(null)); } SimpleColoredText text = new SimpleColoredText(); List<T> values = new ArrayList<>(getValueVariants(target)); if (param(SORT_VALUES)) { Function<T, String> toString = o -> { text.clear(); renderValue(target, o, text); return text.toString(); }; values.sort((o1, o2) -> StringUtil.naturalCompare(toString.fun(o1), toString.fun(o2))); } for (T t : values) { group.add(choseAction.fun(t)); } return group; }