public <C extends BaseReplaceChoice> void showChooser(final Map<C, List<T>> occurrencesMap,
                                                        @Nls String title,
                                                        Consumer<? super C> callback) {
    if (occurrencesMap.size() == 1) {
      callback.accept(occurrencesMap.keySet().iterator().next());
      return;
    }
    List<C> model = new ArrayList<>(occurrencesMap.keySet());

    JBPopupFactory.getInstance()
      .createPopupChooserBuilder(model)
      .setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(final JList list,
                                                      final Object value,
                                                      final int index,
                                                      final boolean isSelected,
                                                      final boolean cellHasFocus) {
          final Component rendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
          @SuppressWarnings("unchecked") final C choices = (C)value;

          if (choices != null) {
            setText(choices.formatDescription(occurrencesMap.get(choices).size()));
          }
          return rendererComponent;
        }
      })
      .setItemSelectedCallback(value -> {
        if (value == null) return;
        dropHighlighters();
        final MarkupModel markupModel = myEditor.getMarkupModel();
        final List<T> occurrenceList = occurrencesMap.get(value);
        for (T occurrence : occurrenceList) {
          final TextRange textRange = getOccurrenceRange(occurrence);
          final RangeHighlighter rangeHighlighter = markupModel.addRangeHighlighter(
            EditorColors.SEARCH_RESULT_ATTRIBUTES, textRange.getStartOffset(), textRange.getEndOffset(), HighlighterLayer.SELECTION - 1,
            HighlighterTargetArea.EXACT_RANGE);
          myRangeHighlighters.add(rangeHighlighter);
        }
      })
      .setTitle(title)
      .setMovable(true)
      .setResizable(false)
      .setRequestFocus(true)
      .setItemChosenCallback(t -> callback.accept(t))
      .addListener(new JBPopupListener() {
        @Override
        public void onClosed(@NotNull LightweightWindowEvent event) {
          dropHighlighters();
        }
      })
      .createPopup().showInBestPositionFor(myEditor);
  }
public <C extends BaseReplaceChoice> void showChooser(final Map<C, List<T>> occurrencesMap,
                                                        @Nls String title,
                                                        Consumer<? super C> callback)