java-gnome version 4.0.19

org.gnome.gtk
Class TreeModelFilter

Object
  extended by org.freedesktop.bindings.Pointer
      extended by org.freedesktop.bindings.Proxy
          extended by org.gnome.glib.Object
              extended by org.gnome.gtk.TreeModel
                  extended by org.gnome.gtk.TreeModelFilter
All Implemented Interfaces:
TreeDragSource

public class TreeModelFilter
extends TreeModel
implements TreeDragSource

A TreeModel which can present a subset of its backing model as determined by a filter function. TreeModelFilter acts to wrap an underlying TreeModel. You store your data in this underlying model; the TreeModelFilter just adds the functionality to selectively determine which rows should be visible.

Usage is straight forward. Given the following declarations:

 final ListStore model;
 final TreeModelFilter filter;
 final DataColumnInteger elevation;
 ...
 
you initialize and populate your ListStore as usual. To add the filtering functionality, you wrap your ListStore in a TreeModelFilter:
 filter = new TreeModelFilter(model, null);
 
then instruct the TreeModelFilter how to select the rows from the concrete TreeModel it is proxying to be included in the virtual model it presents via the setVisibleCallback(). For instance, if you have a list of all mountains and only want to present peaks higher than 8000 meters, you might do:
 filter.setVisibleCallback(new TreeModelFilter.Visible() {
     public boolean onVisible(TreeModelFilter source, TreeModel base, TreeIter row) {
         if (base.getValue(row, elevation) > 8000) {
             return true;
         } else {
             return false;
         }
     }
 }
 
Assuming you are using this data to back a display Widget such as a TreeView, and you only want to present this filtered list of rows, then you use the TreeModelFilter, not the ListStore, as the model backing the TreeView:
 view = new TreeView(filter);
 

Note:
For some reason, TreeModelFilter does not implement TreeSortable. If you plan to sort the filtered model (ie via TreeViewColumn's setSortColumn()) make sure you wrap your TreeModelFilter in a TreeModelSort and add that to the TreeView instead:

 store = new ListStore(...);
 filtered = new TreeModelFilter(store, null);
 sorted = new TreeModelSort(filtered);
 
 view = new TreeView(sorted);
 
 vertical = view.appendColumn();
 vertical.setSortColumn(...);
 
otherwise GTK will object vociferously.

Since:
4.0.6
Author:
Andrew Cowie

Nested Class Summary
static interface TreeModelFilter.Visible
          The callback invoked when a TreeModelFilter wants to ask if a given row in its child TreeModel should be considered visible in the TreeModelFilter.
 
Nested classes/interfaces inherited from class org.gnome.gtk.TreeModel
TreeModel.RowChanged
 
Constructor Summary
TreeModelFilter(TreeModel base, TreePath root)
          Construct a new TreeModelFilter.
 
Method Summary
 TreeIter convertIterBaseToFilter(TreeIter row)
          Convert a TreeIter valid in the underying TreeModel to one usable with this TreeModelFilter.
 TreeIter convertIterFilterToBase(TreeIter row)
          Convert a TreeIter valid in this TreeModelFilter into one usable with the underying TreeModel.
 TreePath convertPathBaseToFilter(TreePath path)
          Convert a TreePath representing a row in the underying TreeModel into the corresponding locator in this TreeModelFilter.
 TreePath convertPathFilterToBase(TreePath path)
          Convert a TreePath representing a row in this TreeModelFilter into one that points to the corresponding row in the underying TreeModel.
 void refilter()
          Cause the TreeModelFilter to re-calculate whether rows are visible.
 void setVisibleCallback(TreeModelFilter.Visible handler)
          Hookup the Visible callback that will be used to determine whether rows from the underlying TreeModel are to be included in the set presented by this TreeModelFilter.
 
Methods inherited from class org.gnome.gtk.TreeModel
connect, getIter, getIterFirst, getPath, getValue, getValue, getValue, getValue, getValue, getValue, getValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
 
Methods inherited from class org.freedesktop.bindings.Pointer
toString
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeModelFilter

public TreeModelFilter(TreeModel base,
                       TreePath root)
Construct a new TreeModelFilter.

Parameters:
base - The underlying model that you are filtering
root - You can give a TreePath to be used as a virtual root so that the TreeModelFilter only presents and operates on a subsection of the base TreeModel. This is rarely necessary, so specify null.
Method Detail

convertIterBaseToFilter

public TreeIter convertIterBaseToFilter(TreeIter row)
Convert a TreeIter valid in the underying TreeModel to one usable with this TreeModelFilter.

Returns:
null if the row is not (currently) present in the TreeModelFilter.
Since:
4.0.9

convertIterFilterToBase

public TreeIter convertIterFilterToBase(TreeIter row)
Convert a TreeIter valid in this TreeModelFilter into one usable with the underying TreeModel.

Since:
4.0.9

convertPathBaseToFilter

public TreePath convertPathBaseToFilter(TreePath path)
Convert a TreePath representing a row in the underying TreeModel into the corresponding locator in this TreeModelFilter.

If the row represented by path isn't (currently) present in the narrowed representation provided by this TreeModelFilter, then null is returned.

Since:
4.0.9

convertPathFilterToBase

public TreePath convertPathFilterToBase(TreePath path)
Convert a TreePath representing a row in this TreeModelFilter into one that points to the corresponding row in the underying TreeModel.

Since:
4.0.9

refilter

public void refilter()
Cause the TreeModelFilter to re-calculate whether rows are visible. This will cause your Visible callback to be hit for each row.

Since:
4.0.6

setVisibleCallback

public void setVisibleCallback(TreeModelFilter.Visible handler)
Hookup the Visible callback that will be used to determine whether rows from the underlying TreeModel are to be included in the set presented by this TreeModelFilter.

Since:
4.0.6


java-gnome