use of com.intellij.ide.util.NavigationItemListCellRenderer in project intellij-community by JetBrains.
the class HighlightImportedElementsHandler method selectTargets.
@Override
protected void selectTargets(final List<PsiMember> targets, final Consumer<List<PsiMember>> selectionConsumer) {
if (targets.isEmpty()) {
selectionConsumer.consume(Collections.<PsiMember>emptyList());
return;
}
if (targets.size() == 1) {
selectionConsumer.consume(Collections.singletonList(targets.get(0)));
return;
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
selectionConsumer.consume(targets);
return;
}
Collections.sort(targets, new PsiMemberComparator());
final List<Object> model = new ArrayList<>();
model.add(CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"));
model.addAll(targets);
final JList list = new JBList(model);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
final ListCellRenderer renderer = new NavigationItemListCellRenderer();
list.setCellRenderer(renderer);
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
builder.setFilteringEnabled(o -> {
if (o instanceof PsiMember) {
final PsiMember member = (PsiMember) o;
return member.getName();
}
return o.toString();
});
if (myImportStatic) {
builder.setTitle(CodeInsightBundle.message("highlight.imported.members.chooser.title"));
} else {
builder.setTitle(CodeInsightBundle.message("highlight.imported.classes.chooser.title"));
}
builder.setItemChoosenCallback(() -> {
final int index = list.getSelectedIndex();
if (index == 0) {
selectionConsumer.consume(targets);
} else {
selectionConsumer.consume(Collections.singletonList(targets.get(index - 1)));
}
});
final JBPopup popup = builder.createPopup();
popup.showInBestPositionFor(myEditor);
}
Aggregations