Skip to main content



      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] Sun, 06 May 2012 23:20 Go to next message
Eclipse UserFriend
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 08:01 Go to previous messageGo to next message
Eclipse UserFriend
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 08:02] by Moderator

Re: Help for the filter for the treeviewer with several columns? [message #870289 is a reply to message #870235] Mon, 07 May 2012 11:11 Go to previous messageGo to next message
Eclipse UserFriend
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 12:05 Go to previous messageGo to next message
Eclipse UserFriend
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] Mon, 07 May 2012 23:03 Go to previous message
Eclipse UserFriend
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: Mon Apr 21 08:40:18 EDT 2025

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

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

Back to the top