Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Help for the filter for the treeviewer with several columns?
Help for the filter for the treeviewer with several columns? [message #870145] Mon, 07 May 2012 03:20 Go to next message
David Song is currently offline David SongFriend
Messages: 217
Registered: April 2011
Senior Member
Hi all,
I want to implement that if any one of the children(leaf element) matches the filter text, all the children of the same parent are visiable. How to do it?

* The default
* behavior returns true if the element has at least one child element that is
* a match with the filter text.

thanks a lot

David
Re: Help for the filter for the treeviewer with several columns? [message #870235 is a reply to message #870145] Mon, 07 May 2012 12:01 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
Hi David,
one solution could be (I say could because I haven't tested the code).

    protected boolean doFilter(Viewer viewer, Object element) {
    	IContentProvider cProvider = ((TreeViewer)viewer).getContentProvider();

    	// Check if element is visible
    	boolean ret = filterElement(element);
    	
    	if (!ret)
    	{
    		if (cProvider instanceof ITreeContentProvider)
	    	{
    			ITreeContentProvider treeContentProvider = (ITreeContentProvider) cProvider;
    			// If not visible, recursively check if a child element is visible, in which case the element must also be visible
    	    	if (treeContentProvider.hasChildren(element))
	    		{
	    			Object[] children = treeContentProvider.getChildren(element);
	    			for (Object child: children)
	    			{
	    				ret = doFilter(viewer, child);
	    				if (ret)
	    				{
	    					break;
	    				}
	    			}
	    		}
	    		
	        	// If still not visible and element is leaf, check if one of the siblings is visible 
    	    	if (!ret && !treeContentProvider.hasChildren(element))
	        	{
	        		Object parent = treeContentProvider.getParent(element);
	        		Object[] siblings = treeContentProvider.getChildren(parent);
	        		for (Object sibling: siblings)
	    			{
	        			if (sibling.equals(element))
	        			{
	        				continue;
	        			}
	        			
	        			// Check if sibling passes filter
	        			ret = filterElement(sibling);
	        			
	        			if (ret)
	        			{
	        				break;
	        			}
	    			}
	    			
	    			
	        	}

	    	}
	    	
	    	
    	}
    	
    	return ret;
    }
    
    private boolean filterElement(Object element) {
    	// do some filtering here
		return true;
	}


Regards
Thorsten

[Updated on: Mon, 07 May 2012 12:02]

Report message to a moderator

Re: Help for the filter for the treeviewer with several columns? [message #870289 is a reply to message #870235] Mon, 07 May 2012 15:11 Go to previous messageGo to next message
David Song is currently offline David SongFriend
Messages: 217
Registered: April 2011
Senior Member
Thanks Thorsten, the treeviewer uses ViewerFilter or its subclass PatternFilter to filter the elements, and we can implement the method
public boolean select(Viewer viewer, Object parentElement,
				Object element) {
}




but you gave the method doFilter(Viewer viewer, Object element), you wrote your own filter without extending the class ViewerFilter?
Re: Help for the filter for the treeviewer with several columns? [message #870318 is a reply to message #870289] Mon, 07 May 2012 16:05 Go to previous messageGo to next message
Thorsten Schlathölter is currently offline Thorsten SchlathölterFriend
Messages: 312
Registered: February 2012
Location: Düsseldorf
Senior Member
Oh sorry. I hacked the code into an existing ViewerFilter (which uses doFilter in the course of filtering) and did not take care. Of course you need to implement the select method. That also saves you the determination of the parent when you treat the siblings.

Regards
Thorsten
Re: Help for the filter for the treeviewer with several columns? [message #870399 is a reply to message #870145] Tue, 08 May 2012 03:03 Go to previous message
David Song is currently offline David SongFriend
Messages: 217
Registered: April 2011
Senior Member
Thanks Thorsten very much, I got it
Previous Topic:ToolItem text not visible on first login, adjust after refresh or second login to applicatoin.
Next Topic:DateTime Control Sizing Glitch using Chinese Locale
Goto Forum:
  


Current Time: Sat Nov 09 01:46:52 GMT 2024

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

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

Back to the top