public class TreeModelFilter extends TreeModel implements TreeDragSource
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.
Modifier and Type | Class and Description |
---|---|
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.
|
TreeModel.RowChanged
Constructor and Description |
---|
TreeModelFilter(TreeModel base,
TreePath root)
Construct a new TreeModelFilter.
|
Modifier and Type | Method and Description |
---|---|
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. |
public TreeModelFilter(TreeModel base, TreePath root)
base
- The underlying model that you are filteringroot
- 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
.public TreeIter convertIterBaseToFilter(TreeIter row)
null
if the row is not (currently) present in the
TreeModelFilter.public TreeIter convertIterFilterToBase(TreeIter row)
public TreePath convertPathBaseToFilter(TreePath path)
If the row represented by path
isn't (currently) present
in the narrowed representation provided by this TreeModelFilter, then
null
is returned.
public TreePath convertPathFilterToBase(TreePath path)
public void refilter()
Visible
callback to be hit for each
row.public void setVisibleCallback(TreeModelFilter.Visible handler)
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.