Reputation: 5989
I created TreeViewer
and PatternFilter
PatternFilter patternFilter = new PatternFilter();
FilteredTree filter = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true);
treeViewer = filter.getViewer();
treeViewer.setContentProvider(new TreeContentProvider());
treeViewer.setLabelProvider(new TreeLabelProvider());
treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
treeViewer.setInput(Activator.getDefault().getTreeModel());
Tree tree = treeViewer.getTree();
How can I add bold text to the text results of the filter?
Like the filter in the preferences dialog in Eclipse
Upvotes: 1
Views: 320
Reputation: 8960
The Eclipse Preferences uses that same FilteredTree
. Knowing this, it's easy from here.
A quick trip to FilteredTree
, and CTRL + F the text bold
.
First result is this method:
/**
* Return a bold font if the given element matches the given pattern.
* Clients can opt to call this method from a Viewer's label provider to get
* a bold font for which to highlight the given element in the tree.
*
* @param element
* element for which a match should be determined
* @param tree
* FilteredTree in which the element resides
* @param filter
* PatternFilter which determines a match
*
* @return bold font
*/
public static Font getBoldFont(Object element, FilteredTree tree, PatternFilter filter)
If we search for where it's used, we find org.eclipse.ui.internal.dialogs.PreferenceBoldLabelProvider
.
Use the same trick in your label provider.
Edit 1: As greg-449 said, I hope you're experienced enough to know not to use internal classes, rather immitate them and create your own by extending LabelProvider
(in this case).
Upvotes: 1