Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Custom PatternFilter in TreeViewer
Custom PatternFilter in TreeViewer [message #1695302] Wed, 13 May 2015 12:15 Go to next message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

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 Go to previous messageGo to next message
Eclipse UserFriend
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:

  1. 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").

  2. 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.
Re: Custom PatternFilter in TreeViewer [message #1695374 is a reply to message #1695334] Wed, 13 May 2015 20:02 Go to previous message
Amit Kumar Mondal is currently offline Amit Kumar MondalFriend
Messages: 108
Registered: March 2015
Location: Munich, Germany
Senior Member

Thanks Brian for the assistance. I will try it and will let u know.

Amit Kumar Mondal
Email: admin@amitinside.com
Skype: arsenalnerk Blog: blog.amitinside.com
Previous Topic:How to select the tree item when a char is typed
Next Topic:Jface TreeView File list drag and drop
Goto Forum:
  


Current Time: Fri Apr 26 11:05:14 GMT 2024

Powered by FUDForum. Page generated in 0.05557 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top