private StyleRange createRange(Match match, boolean selection) {
   Display display = composite.getDisplay();
   Color fgColor, bgColor;
   if (selection) {
     // Lighten to avoid search selection on system selection
     fgColor = ColorManager.lighten(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT), 50);
     bgColor = ColorManager.getInstance().getSelectedBackgroundColor();
   } else {
     // To avoid white text on light-green background
     fgColor = display.getSystemColor(SWT.COLOR_BLACK);
     bgColor = ColorManager.getInstance().getBackgroundColor();
   }
   return new StyleRange(match.getOffset(), match.getLength(), fgColor, bgColor);
 }
  public static void applyStyles(
      final TextPresentation presentation, final Match[] matches, final Match selected) {

    final StyleRange[] ranges =
        createStyleRanges(
            presentation.getExtent(), matches, ColorManager.getInstance().getBackgroundColor());

    presentation.mergeStyleRanges(ranges);

    if (selected != null) {
      final StyleRange[] selectedRanges =
          createStyleRanges(
              presentation.getExtent(),
              new Match[] {selected},
              ColorManager.getInstance().getSelectedBackgroundColor());
      presentation.mergeStyleRanges(selectedRanges);
    }
  }