Home > Filter, OutlineView > Recipe 9: How to filter an OutlineView?

Recipe 9: How to filter an OutlineView?

Problem

How can I filter an OutlineView programmatically?

Solution

By right-clicking inside an outline view, a popup menu is displayed where you can select the action Show only rows where you can define your criteria depending under which column you clicked.

To do filtering programmatically, ETable defines two methods:

outlineView.getOutline().setQuickFilter(column, filter);
outlineView.getOutline().unsetQuickFilter();

where column is 1 for first column, 2 for second etc. and filter is of type Object and can be one of two types:

  • a value that is matched directly to the values of the column, e.g.
outlineView.getOutline().setQuickFilter(3, Boolean.TRUE);
  • a QuickFilter e.g.
private final QuickFilter filter = new QuickFilter() {
   @Override
   public boolean accept(Object aValue) {
      if (aValue instanceof TaskNode) {
         TaskNode taskNode = (TaskNode) aValue;
         Task task = taskNode.getLookup().lookup(Task.class);
         return task.isCompleted();
      }
     return true;
   }
};
outlineView.getOutline().setQuickFilter(0, filter);

In the previous example we pass the filter to column 0. This is the node column which gives us access to all fields of the node, i.e. the bean that is wrapped, which allows to filter the outline view even for fields that are not displayed in the outline view. E.g. you have a class :

public class Task implements Serializable {
  private int id;
  private String description;
  private int priority;
  private Date dueDate;
  private boolean alert = false;
  private int daysBefore;
  private String obs;
  private boolean completed = false;

but the outline view displays only: priority, description, alert and due date and you want to filter the tasks that are completed, then the above filter will do the job.

Advertisements
Categories: Filter, OutlineView
  1. No comments yet.
  1. February 1, 2015 at 6:09 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: