Can someone please guide me how to filter the contents from Jface TreeViewer?

51 Views Asked by At

I am new in creating TreeViewer. I am creating a treeviewer using a HashMap Map<String, List<String>> typeDefsTreeMap = new HashMap<>()

Now I want to filter the contents of TreeViewer. Can someone help me in filtering the contents of TreeViewer?

I tried to use ViewerFilter like below

treeViewer.addFilter(new ViewerFilter() {

    @Override
    public boolean select(Viewer viewer, Object parentElement, Object element) {
       if (element.toString().toLowerCase()
                                       .contains(searchFilterText.getText().toLowerCase())) {
          return element instanceof String;
        }
    return element instanceof String;
    }
});

But at the end I need to put a selection on that element which is filtered, as I do not want to hide anything with filter, I just want to select the first element which has filtered text.

How can I do that in treeviewer?

0

There are 0 best solutions below