public static @NotNull @Nls String shortenTextToFit(@NotNull @Nls String text,
                                                      @NotNull FontMetrics fontMetrics,
                                                      int availableWidth,
                                                      int maxLength,
                                                      @NotNull @Nls String symbol) {
    if (fontMetrics.stringWidth(text) <= availableWidth) return text;

    for (int i = text.length(); i > maxLength; i--) {
      String result = StringUtil.shortenTextWithEllipsis(text, i, 0, symbol);
      if (fontMetrics.stringWidth(result) <= availableWidth) {
        return result;
      }
    }
    return StringUtil.shortenTextWithEllipsis(text, maxLength, 0, symbol);
  }
public static @NotNull @Nls String shortenTextToFit(@NotNull @Nls String text,
                                                      @NotNull FontMetrics fontMetrics,
                                                      int availableWidth,
                                                      int maxLength,
                                                      @NotNull @Nls String symbol)