I have a TreeViewer as shown here:
.
I have a text field to enter the percentage values. Suppose the percentage entered is 30 %, I should hide all the rows that are below 30% and display only the rows above 30%. Is there any row filter that I can use for my TreeViewer? It would be great if some examples are provided.
I am using e4 RCP. I want to do View based filtering and prefer not to change the Model.
You use a class which extends ViewFilter
to filter the rows in a tree viewer.
The main method to override in the ViewFilter
is the select
method:
@Override
public boolean select(Viewer viewer, Object parentElement, Object element)
here you are given the object being considered (element
) along with its parent and the viewer. You return true
to keep displaying the element and false
to hide it.
You can have several filters active if required, set them in the tree viewer using:
treeViewer.setFilters(array of view filters);
You may need to call
treeViewer.filter();
when something changes in the tree which requires the filters to be re-run.