Eclipse JFace infrastructure provides a powerful infrastructure called ViewerFilter, to allow the user to filter content presented in a viewer.
Especially TreeViewers as extensively used by common navigator framework (CNF) based viewers such as the Project Explorer or Package Explorer make use of them.Eclipse Viewer Filter Configuration

Providing as Extension or Programmatically

To provide such a filter one can either programmatically add it to a filter enabled viewer such as to FilteredTreeViewers

PatternFilter filter = new PatternFilter();
FilteredTree tree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);

To use an Eclipse extension point declare it this way:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
      description="Show only VariationPoints which are about variying imports"
      name="VariationPoints: Imports Only">

Filtering Empty Parent Folders

If you have implemented a filter for specific elements explicitly and to filter parent elements if they do not include any sub element.

public abstract class MyFilter extends ViewerFilter {

public boolean select(Viewer viewer, Object parentElement, Object element) {

if (isChildElement(element)) {
return handleChild(element);

} else {
// manipulate tree viewer based on select
// decision for the sub elements
StructuredViewer sviewer = (StructuredViewer) viewer;
ITreeContentProvider provider = (ITreeContentProvider) sviewer.getContentProvider();
for (Object child : provider.getChildren(element)) {
if (select(viewer, element, child)) {
return true;
return false;
Eclipse JFace ViewerFilter

Post navigation