Open main menu

CDOT Wiki β

Changes

Teams Winter 2011/team1/RCP/Create RPC Application

1,970 bytes added, 12:58, 4 March 2011
6. Add Highlights to Search
=== 6. Add Highlights to Search ===
6.1 Create a new helper class and put it in <code>util</code> package. <br/>Method in this class use logic that is case-insensitive, because filter is case-insensitive:<br/>
<pre>
package cs.ecl.rcp.simplercp.util;
}
</pre><br/>
56.2Change the way columns are created in the <code>createColumns()</code> method.<br/>Following is the code for the first column, other columns need to be changed in similar way:<br/> <pre> // First column is for the id TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0); col.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { String search = searchText.getText(); Student student = (Student) cell.getElement(); String cellText = student.getId(); cell.setText(cellText); if (search != null && search.length() > 0) { int intRangesCorrectSize[] = SearchUtil .getSearchTermOccurrences(search, cellText); List<StyleRange> styleRange = new ArrayList<StyleRange>(); for (int i = 0; i < intRangesCorrectSize.length / 2; i++) { int start = intRangesCorrectSize[i]; int length = intRangesCorrectSize[++i]; StyleRange myStyledRange = new StyleRange(start, length, null, colorYellow);  styleRange.add(myStyledRange); } cell.setStyleRanges(styleRange .toArray(new StyleRange[styleRange.size()])); } else { cell.setStyleRanges(null); }  super.update(cell); setStatusLine("Student search has been updated"); } }); col.setEditingSupport(new IdEditingSupport(viewer)); </pre><br/>6.3 Run the application. Now your search matches are highlighted:<br/>[[Image: Create5.png | 400px]]
1
edit