Example usage for org.eclipse.jface.viewers ViewerCell setStyleRanges

List of usage examples for org.eclipse.jface.viewers ViewerCell setStyleRanges

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerCell setStyleRanges.

Prototype

public void setStyleRanges(StyleRange[] styleRanges) 

Source Link

Document

Set the style ranges to be applied on the text label Note: Requires StyledCellLabelProvider with owner draw enabled.

Usage

From source file:ummisco.gama.ui.viewers.csv.CSVLabelProvider.java

/**
 * @see org.eclipse.jface.viewers.StyledCellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
 *///w  w  w.j a  v  a  2s  .c  o m
@Override
public void update(final ViewerCell cell) {
    final CSVRow element = (CSVRow) cell.getElement();
    final int index = cell.getColumnIndex();
    final String columnText = getColumnText(element, index);
    cell.setText(columnText);
    cell.setImage(null);
    if (searchText != null && searchText.length() > 0) {
        final int intRangesCorrectSize[] = SearchResultStyle.getSearchTermOccurrences(searchText, columnText);
        final List<StyleRange> styleRange = new ArrayList<StyleRange>();
        for (int i = 0; i < intRangesCorrectSize.length / 2; i++) {
            final StyleRange myStyleRange = new StyleRange(0, 0, null, searchColor);
            myStyleRange.start = intRangesCorrectSize[i];
            myStyleRange.length = intRangesCorrectSize[++i];
            styleRange.add(myStyleRange);
        }
        cell.setStyleRanges(styleRange.toArray(new StyleRange[styleRange.size()]));
    } else {
        cell.setStyleRanges(null);
    }

    super.update(cell);
}