use of org.springsource.ide.eclipse.commons.livexp.ui.Stylers in project eclipse-integration-commons by spring-projects.
the class SwtConnect method connectTextBasedFilter.
/**
* Connect a filterbox model to a treeviewer. This assumes that the filter is text-based. The filter is applied to the labels of the elements in the tree.
* <p>
* For the viewer filter to work correctly the ITreeContentProvider must provide a proper implementation of the 'getParent' method. If getParent only
* returns null the viewer filter will not be able to check whether an element should be shown when a parent element is selected by the search filter.
* <p>
* Note: you can use {@link TreeElementWrappingContentProvider} in order to ensure that ITreeContentProvider keeps track of parent nodes properly.
*/
public static void connectTextBasedFilter(TreeViewer viewer, LiveExpression<Filter<String>> searchBoxModel, LabelProvider labels, ITreeContentProvider treeContent) {
TreeAwareViewerFilter viewerFilter = new TreeAwareViewerFilter(viewer, Filters.acceptAll(), labels, treeContent);
Disposable disposable = searchBoxModel.onChange(UIValueListener.from((e, filter) -> {
viewerFilter.setFilter(searchBoxModel.getValue());
viewer.refresh(true);
}));
// TODO: what if there are existing filters?
viewer.setFilters(viewerFilter);
viewer.getControl().addDisposeListener(de -> {
disposable.dispose();
});
Stylers stylers = new Stylers(viewer.getTree().getFont());
viewer.getControl().addDisposeListener(de -> {
disposable.dispose();
stylers.dispose();
});
ILabelProvider baseLabels = (ILabelProvider) viewer.getLabelProvider();
// Can't add bolding support without this! Ensure label provider is set before calling this method
Assert.isNotNull(baseLabels);
viewer.setLabelProvider(boldMatchedElements(stylers, baseLabels, Filters.delegatingTo(searchBoxModel)));
}
Aggregations