Custom PatternFilter in TreeViewer [message #1695302] |
Wed, 13 May 2015 12:15 |
|
Hi,
I am developing an application in which I need to filter my treeviewer and that's why I have used the PatternFilter which pretty much provides everything I needed.
Now, I need to filter the treeviewer in a different way.
Let's say I have a treeviewer with the following items in it.
Parent1
--Child1
----ChildChild1
---------ChildChildChild1
Parent2
--Child2
----ChildChild2
---------ChildChildChild2
So now if I use filter text "Parent2", it is only displaying Parent2 but I want to view all its child nodes along with it.
That means while filtering using text "Parent2", I need to see the following in the treeviewer.
Parent2
--Child 2
----ChildChild2
---------ChildChildChild2
Awaiting for further assistance.
Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
[Updated on: Wed, 13 May 2015 12:28] Report message to a moderator
|
|
|
Re: Custom PatternFilter in TreeViewer [message #1695334 is a reply to message #1695302] |
Wed, 13 May 2015 14:13 |
Eclipse User |
|
|
|
You'll need to override PatternFilter#isElementVisible(Viewer viewer, Object element) to add a third case:
public boolean isElementVisible(Viewer viewer, Object element){
return isParentMatch(viewer, element) || isLeafMatch(viewer, element);
}
This method is invoked for each potential tree node element to check if the provided element should be shown. The default implementation checks two cases using somewhat confusingly-named methods. For each node, it checks if:
- One of its descendants matches (isParentMatch() -- may recurse down the tree). This case is necessary so that otherwise-non-matching parents are included (e.g., Parent1 and Child 1 if searching for "ChildChild1").
- Its own label text matches (isLeafMatch() -- may recurse down the tree). This case is necessary to match an actual node.
You need to add a third condition to check the node's ancestry: does one of my parents label text match? Look at the default implementations of isParentMatch() and isLeafMatch().
Brian.
|
|
|
|
Powered by
FUDForum. Page generated in 0.05557 seconds