|
java-gnome version 4.0.15 | ||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||
Objectorg.freedesktop.bindings.Pointer
org.freedesktop.bindings.Proxy
org.gnome.glib.Object
org.gnome.gtk.TreeModel
org.gnome.gtk.TreeStore
public class TreeStore
A TreeModel that stores its data in a hierarchical tree. TreeStore is a
concrete TreeModel subclass where rows can also have other rows that are
children. This model is suitable for hierarchical data where each row has a
parent and a list of children. If you just want to store a list of rows
(ie, plain tabular data), ListStore is a more appropriate
choice.
Instantiating a TreeStore is done identically as with a ListStore, by
specifying an array of DataColumns. For example, given:
final TreeStore model; final DataColumnString place; ...you would build a model as follows:
model = new TreeStore(new DataColumn[] {
place = new DataColumnString(),
...
});
The caveat described in ListStore applies here; don't declare your model as
abstract type TreeModel; keep them as concrete type TreeStore so you can
get to the TreeStore specific methods for adding rows and navigating the
hierarchy.
To add a new row at the top level of the hierarchy, you just use
appendRow() as you have seen with ListStore:
parent = model.appendRow(); model.setValue(parent, place, "Europe");If, however, you want to add a new row as a child of an existing row, you need to use the
appendChild() method
instead:
child = model.appendRow(parent); model.setValue(child, place, "London"); child = model.appendRow(parent); model.setValue(child, place, "Paris"); ...passing the TreeIter representing the parent you wish to create a child under.
You may also want to read the discussion at TreePath to understand
how to address a particular row in a given TreeStore. You will also
probably want to be aware of TreeView's
expandRow(),
expandAll(), and corresponding
collapse methods.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.gnome.gtk.TreeModel |
|---|
TreeModel.RowChanged |
| Constructor Summary | |
|---|---|
TreeStore(DataColumn[] types)
Construct a new TreeStore with the given column types. |
|
| Method Summary | |
|---|---|
TreeIter |
appendChild(TreeIter parent)
Append a new row after the last child of the given row. |
TreeIter |
appendRow()
Append a new row at the top level of this TreeStore. |
void |
clear()
Remove all elements from this TreeStore. |
TreeIter |
insertRow(TreeIter parent,
int position)
Insert a new row in the TreeStore. |
TreeIter |
insertRow(TreeIter parent,
TreeIter sibling)
Insert a new row in the TreeStore. |
TreeIter |
iterChildren(TreeIter row)
Get the children of the given row, if any. |
boolean |
iterHasChild(TreeIter row)
Returns whether the given row has at least one child row. |
TreeIter |
iterParent(TreeIter row)
Get the parent of the given row, assuming there is one. |
boolean |
removeRow(TreeIter row)
Delete a row from the TreeStore. |
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.Pointer |
|---|
toString |
| Methods inherited from class Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public TreeStore(DataColumn[] types)
DataColumn for details. You must include at least
one DataColumn in your types array (you can't have a
TreeStore with no columns).
| Method Detail |
|---|
public TreeIter appendChild(TreeIter parent)
setValue() methods, of course.
To add a top level row, use appendRow().
parent - The row to which a new child will be added.
public TreeIter appendRow()
appendChild(parent).
public void clear()
public TreeIter insertRow(TreeIter parent,
int position)
parent at the position specified. If
parent is null then the new row will be
inserted at the top level of the TreeStore.
public TreeIter insertRow(TreeIter parent,
TreeIter sibling)
parent and will be placed in front of the supplied
sibling.
public TreeIter iterChildren(TreeIter row)
row, if any.
You can use the returned TreeIter to iterate on children rows as follows:
child = model.iterChildren(row);
if (child == null) {
return;
}
do {
// do something with child row
} while (child.iterNext());
which works because iterating with a TreeIter will only iterate over
the rows that are siblings, ie, are at the same level of the hierarchy.
null if the row has no children.public boolean iterHasChild(TreeIter row)
row has at least one child row.
You can use iterChildren() to get the
actual children.
true if the specified row has one or more
children, false otherwise.public TreeIter iterParent(TreeIter row)
row, assuming there is one.
null if this row has no parent.public boolean removeRow(TreeIter row)
true will be returned and the
TreeIter will still be valid. Otherwise, false is returned
and row is invalidated.
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 | ||||