Пример #1
0
  private String getColoredLabelWithCounts(Object element, String coloredName) {
    AbstractTextSearchResult result = fPage.getInput();
    if (result == null) return coloredName;

    int matchCount = result.getMatchCount(element);
    if (matchCount <= 1) return coloredName;

    String countInfo =
        Messages.format(SearchMessages.FileLabelProvider_count_format, new Integer(matchCount));
    coloredName += " ";
    coloredName += countInfo;
    return coloredName;
  }
  private StyledString getColoredLabelWithCounts(Object element, StyledString coloredName) {
    AbstractTextSearchResult result = fPage.getInput();
    if (result == null) {
      return coloredName;
    }

    int matchCount = result.getMatchCount(element);
    if (matchCount <= 1) {
      return coloredName;
    }

    String countInfo = MessageFormat.format("({0} matches)", matchCount);
    coloredName.append(' ').append(countInfo, StyledString.COUNTER_STYLER);
    return coloredName;
  }
Пример #3
0
  private String getLineElementLabel(LineElement lineElement) {
    int lineNumber = lineElement.getLine();
    String lineNumberString =
        Messages.format(SearchMessages.FileLabelProvider_line_number, new Integer(lineNumber));

    String str = new String(lineNumberString);

    Match[] matches = lineElement.getMatches(fPage.getInput());
    Arrays.sort(matches, fMatchComparator);

    String content = lineElement.getContents();

    int pos = evaluateLineStart(matches, content, lineElement.getOffset());

    int length = content.length();

    int charsToCut =
        getCharsToCut(
            length, matches); // number of characters to leave away if the line is too long
    for (int i = 0; i < matches.length; i++) {
      FileMatch match = (FileMatch) matches[i];
      int start = Math.max(match.getOriginalOffset() - lineElement.getOffset(), 0);
      // append gap between last match and the new one
      if (pos < start) {
        if (charsToCut > 0) {
          charsToCut = appendShortenedGap(content, pos, start, charsToCut, i == 0, str);
        } else {
          str += content.substring(pos, start);
        }
      }
      // append match
      int end =
          Math.min(
              match.getOriginalOffset() + match.getOriginalLength() - lineElement.getOffset(),
              lineElement.getLength());
      str += content.substring(start, end);
      pos = end;
    }
    // append rest of the line
    if (charsToCut > 0) {
      appendShortenedGap(content, pos, length, charsToCut, false, str);
    } else {
      str += content.substring(pos);
    }
    return str;
  }
  private StyledString getLineElementLabel(ICustomLineElement lineElement) {
    int lineNumber = lineElement.getLine();
    String lineNumberString = MessageFormat.format("{0}:", lineNumber);

    StyledString str = new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER);

    Match[] matches = lineElement.getMatches(fPage.getInput());
    Arrays.sort(matches, fMatchComparator);

    String content = lineElement.getContents();

    int pos = evaluateLineStart(matches, content, lineElement.getOffset());

    int length = content.length();

    int charsToCut =
        getCharsToCut(
            length, matches); // number of characters to leave away if the line is too long
    for (int i = 0; i < matches.length; i++) {
      ICustomMatch match = (ICustomMatch) matches[i];
      int start = Math.max(match.getOriginalOffset() - lineElement.getOffset(), 0);
      // append gap between last match and the new one
      if (pos < start) {
        if (charsToCut > 0) {
          charsToCut = appendShortenedGap(content, pos, start, charsToCut, i == 0, str);
        } else {
          str.append(content.substring(pos, start));
        }
      }
      // append match
      int end =
          Math.min(
              match.getOriginalOffset() + match.getOriginalLength() - lineElement.getOffset(),
              lineElement.getLength());
      str.append(content.substring(start, end), DecoratingFileSearchLabelProvider.HIGHLIGHT_STYLE);
      pos = end;
    }
    // append rest of the line
    if (charsToCut > 0) {
      appendShortenedGap(content, pos, length, charsToCut, false, str);
    } else {
      str.append(content.substring(pos));
    }
    return str;
  }