|
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 |
Thorsten Schlathölter 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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03170 seconds