|
java-gnome version 4.0.7 | ||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||
java.lang.Objectorg.freedesktop.bindings.Proxy
org.gnome.glib.Object
org.gnome.gtk.TreeModel
org.gnome.gtk.TreeModelSort
public class TreeModelSort
Takes an existing model and creates a new model of it sorted as specified. The data is not copied, but the TreeModel that results from creating a TreeModelSort can be used independently. It listens to and reacts to the signals emitted by the underlying base TreeModel. The end result is that of allowing you to have two different TreeViews with their own sort of the same underlying data set. This is potentially useful if you have a common TreeModel backing a number of different presentations, although you should be cognisant that a point will be reached where it is more efficient to simply have separate models.
A TreeIter pointing into this TreeModelSort is not valid in the
underlying "child" TreeModel. If you need to change data in the base model,
use convertIterToChildIter().
You need to be careful to use the correct TreeModel for TreeIter pointers you receive in callbacks. The scenario that arises more often is this:
ListStore model;
TreeModelSort sorted;
TreeView view;
TreeSelection selection;
// usual TreeModel setup
model = new ListStore(...);
// then create the sorted one, and use it
sorted = new TreeModelSort(model);
view = new TreeView(sorted);
...
// then, later
selection.connect(new TreeSelection.CHANGED() {
public void onChanged(TreeSelection source) {
final TreeIter row;
final String str;
row = selection.getSelected();
if (row == null) {
return;
}
str = model.getValue(row, column);
}
}
the problem that arises is that the retrieved TreeIter is not valid
in model. It's a TreeIter in sorted. Your
program will crash if you get this wrong. The fix is simple; change it to
use the correct TreeModel:
...
str = sorted.getValue(row, column);
...
and things will work fine.
You don't normally have need of this class. Both ListStore and TreeStore
implement TreeSortable already, and there are various sorting tools built
into the view side of the TreeView/TreeModel MVC framework, notably
TreeViewColumn's
setSortColumn(). If,
however, you are using a TreeModelFilter, you will need to wrap it
in one of these to make sorting work normally again.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.gnome.gtk.TreeModel |
|---|
TreeModel.ROW_CHANGED |
| Constructor Summary | |
|---|---|
TreeModelSort(TreeModel base)
Create a new TreeModelSort, wrapping an existing model. |
|
| Method Summary | |
|---|---|
TreeIter |
convertIterToChildIter(TreeIter row)
Convert a TreeIter pointing into this TreeModelSort into a TreeIter valid in the underlying base TreeModel that is being proxied. |
void |
setSortColumn(DataColumn column,
SortType ordering)
Specify the column from your (underlying) data model which will be used for sorting this TreeModelSort. |
| Methods inherited from class org.gnome.gtk.TreeModel |
|---|
connect, getIter, getIterFirst, getPath, getValue, getValue, getValue, getValue, getValue, getValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue |
| Methods inherited from class org.freedesktop.bindings.Proxy |
|---|
toString |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TreeModelSort(TreeModel base)
| Method Detail |
|---|
public TreeIter convertIterToChildIter(TreeIter row)
TODO We need to test the limitations of this, as several people have actually been getting away with not worrying about converting at all, so clearly something isn't quite as expected.
public void setSortColumn(DataColumn column,
SortType ordering)
TreeSortableASCENDING or
DESCENDING order via the
ordering parameter.
setSortColumn in interface TreeSortable
|
![]() java-gnome |
||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||