org.gnu.gtk

Class TreeStore

public class TreeStore extends TreeModel implements TreeSortable, TreeDragDest, TreeDragSource

The TreeStore is a Model used for storing data which will be displayed in any number of {@link TreeView} widgets. For an overview of how the tree and list objects fit together, see the {@link TreeView} description.

Data is stored within this object in {@link DataColumn}s. This data is displayed in the widgets via {@link CellRenderer}'s; the mapping between this data and the cell renderers of each treeview column is done in the {@link TreeViewColumn} class.

Constructor Summary
TreeStore(DataColumn[] dataColumns)
Constructs a new TreeStore, defining the types for each datablock.
Method Summary
voidaddRow(DataRow aRow)
Adds a row to the tree.
voidaddRow(DataRow aRow, TreeIter aParent)
Adds a row to the tree.
voidaddRowAt(DataRow aRow, int aPosition)
Adds a row to the tree, at the specified position.
voidaddRowAt(DataRow aRow, TreeIter aParent, int aPosition)
Adds a row to the tree, at the specified position.
TreeIterappendRow(TreeIter parent)
Appends a new row to tree_store.
voidclear()
Removes all items from the treestore.
ListgetAllDataColumns()
Returns a List with the types for every column as a DataColumn object.
DataColumngetDataColumn(int aCol)
Returns the type of the column aCol as a DataColumn.
intgetIteratorDepth(TreeIter iter)
Returns the depth of the iterator.
DataRowgetRowAt(TreeIter aIter)
Gets all the values in the row indicated by aIter.
DataColumngetSortColumn()
Get a DataColumn object representing the currently sorted column.
SortTypegetSortOrder()
Get the current sorting order of the store.
static TypegetType()
Retrieve the runtime type used by the GLib library.
inthandleCompareFunc(Handle model, Handle aIter, Handle bIter, int col)
Call-back method invoked by the JNI code when sorting is required.
TreeIterinsertRow(TreeIter parent, int position)
Creates a new row at position.
TreeIterinsertRowAfter(TreeIter sibling, TreeIter parent)
Inserts a new row after sibling.
TreeIterinsertRowBefore(TreeIter sibling, TreeIter parent)
Inserts a new row before sibling.
booleanisAncestor(TreeIter iter, TreeIter descendant)
Returns TRUE if iter is an ancestor of descendant.
booleanisIterValid(TreeIter iter)
voidmoveRowAfter(TreeIter iter, TreeIter position)
Moves iter in this store to the position after position.
voidmoveRowBefore(TreeIter iter, TreeIter position)
Moves iter in tree_store to the position before position.
voidmoveRowToEnd(TreeIter iter)
Moves iter to the end of the model
voidmoveRowToStart(TreeIter iter)
Moves iter in this store to the start of the store.
TreeIterprependRow(TreeIter parent)
Prepends a new row to the store.
voidremoveRow(TreeIter iter)
Removes a row from the tree store.
voidreorder(TreeIter iter, int[] newOrder)
voidsetColumnTypes(DataColumn[] dataColumns)
voidsetDragDestListener(TreeDragDestListener listener)
This method has not yet been implemented.
voidsetDragSourceListener(TreeDragSourceListener listener)
This method has not yet been implemented.
voidsetRowAt(DataRow aRow, TreeIter aIter)
Sets all columns pointed by aIter to the values stored in aRow.
voidsetSortColumn(DataColumn column, SortType order)
Set the column in the list to sort on.
voidsetSortMethod(TreeIterComparison method, DataColumn column)
Set the class used to sort the list according to the values stored in the given DataColumn.
voidsetValue(TreeIter iter, DataColumnString dataBlock, String value)
Sets a value in the dataStore.
voidsetValue(TreeIter iter, DataColumnStockItem dataBlock, GtkStockItem value)
Sets a value in the dataStore.
voidsetValue(TreeIter iter, DataColumnIconSize dataBlock, IconSize value)
Sets a value in the dataStore.
voidsetValue(TreeIter iter, DataColumnInt dataBlock, int value)
Sets a value in the dataStore.
voidsetValue(TreeIter iter, DataColumnLong dataBlock, long value)
Sets a value in the dataStore.
voidsetValue(TreeIter iter, DataColumnBoolean dataBlock, boolean value)
Sets a value in the dataStore.
voidsetValue(TreeIter iter, DataColumnDouble dataBlock, double value)
Sets a value in the dataStore.
voidsetValue(TreeIter iter, DataColumnObject dataBlock, Object value)
Sets a value in the dataStore.
voidsetValue(TreeIter iter, DataColumnPixbuf dataBlock, Pixbuf value)
Sets a value in the dataStore.
voidswapRows(TreeIter a, TreeIter b)
Swaps a and b in the same level of tree_store.

Constructor Detail

TreeStore

public TreeStore(DataColumn[] dataColumns)
Constructs a new TreeStore, defining the types for each datablock. Subsequent setting of data to any of the datablocks must follow the types you set out here.

Parameters: dataColumns Types for the data to be stored in the TreeStore.

Method Detail

addRow

public void addRow(DataRow aRow)
Adds a row to the tree. This method can be used to easily add data to the tree. Each item in the DataRow must match the {@link DataColumn} type specified in the constructor of TreeStore. For example, if it was passed {new DataColumnBoolean(), new DataColumnString()} to the constructor, then the DataRow must contain a Boolean and a String object, respectively.

Parameters: aRow a row to be added to the list

addRow

public void addRow(DataRow aRow, TreeIter aParent)
Adds a row to the tree. This method can be used to easily add data to the tree. Each item in the DataRow must match the {@link DataColumn} type specified in the constructor of TreeStore. For example, if it was passed {new DataColumnBoolean(), new DataColumnString()} to the constructor, then the DataRow must contain a Boolean and a String object, respectively.

Parameters: aRow a row to be added to the list aParent a TreeIter pointing to a parent row.

addRowAt

public void addRowAt(DataRow aRow, int aPosition)
Adds a row to the tree, at the specified position. This method can be used to easily add data to the tree. Each item in the DataRow must match the {@link DataColumn} type specified in the constructor of TreeStore. For example, if it was passed {new DataColumnBoolean(), new DataColumnString()} to the constructor, then the DataRow must contain a Boolean and a String object, respectively.

Parameters: aRow a row to be added to the list

addRowAt

public void addRowAt(DataRow aRow, TreeIter aParent, int aPosition)
Adds a row to the tree, at the specified position. This method can be used to easily add data to the tree. Each item in the DataRow must match the {@link DataColumn} type specified in the constructor of TreeStore. For example, if it was passed {new DataColumnBoolean(), new DataColumnString()} to the constructor, then the DataRow must contain a Boolean and a String object, respectively.

Parameters: aRow a row to be added to the list aParent a TreeIter pointing to a parent row.

appendRow

public TreeIter appendRow(TreeIter parent)
Appends a new row to tree_store. If parent is non-NULL, then it will append the new row after the last child of parent, otherwise it will append a row to the top level.

Parameters: parent A valid TreeIter, or NULL

Returns: Iterator for the new row.

clear

public void clear()
Removes all items from the treestore.

getAllDataColumns

public List getAllDataColumns()
Returns a List with the types for every column as a DataColumn object.

Returns: the list of DataColumn's

getDataColumn

public DataColumn getDataColumn(int aCol)
Returns the type of the column aCol as a DataColumn. This is similar to calling getType(int); the difference is that this method returns the type as a DataColumn, which is a more high-level structure.

Parameters: aCol the column index

Returns: the corresponding DataColumn

getIteratorDepth

public int getIteratorDepth(TreeIter iter)
Returns the depth of the iterator. This will be 0 for anything on the root level, 1 for anything down a level, etc.

Parameters: iter The iterator to test the depth of

Returns: Depth of the iterator.

getRowAt

public DataRow getRowAt(TreeIter aIter)
Gets all the values in the row indicated by aIter. There are several ways you can get a TreeIter to pass; for example: using methods like getIter and getFirstIter(), or from a TreeSelection.

Parameters: aIter the iter pointing to the row

Returns: a DataRow filled with the values of the row.

See Also: getIter getIter getFirstIter TreeSelection

getSortColumn

public DataColumn getSortColumn()
Get a DataColumn object representing the currently sorted column. This is not the same DataColumn used to create the store. It is only of type DataColumn (not DataColumnString, etc). It can be compared with another DataColumn object using the {@link DataColumn#equals} method.

Returns: A DataColumn object representing the currently sorted column or null if there is no column currently sorted.

getSortOrder

public SortType getSortOrder()
Get the current sorting order of the store.

Returns: A SortType object defining the current sorting order of the store or null if there is no current sort order.

getType

public static Type getType()
Retrieve the runtime type used by the GLib library.

handleCompareFunc

public int handleCompareFunc(Handle model, Handle aIter, Handle bIter, int col)
Call-back method invoked by the JNI code when sorting is required. This is for internal use only.

insertRow

public TreeIter insertRow(TreeIter parent, int position)
Creates a new row at position. If parent is non-NULL, then the row will be made a child of parent. Otherwise, the row will be created at the toplevel. If position is larger than the number of rows at that level, then the new row will be inserted to the end of the list.

Parameters: parent A valid TreeIter, or NULL position Position to insert the new row

Returns: Iterator for the new row

insertRowAfter

public TreeIter insertRowAfter(TreeIter sibling, TreeIter parent)
Inserts a new row after sibling. If sibling is NULL, then the row will be prepended to the beginning of the parent 's children. If parent and sibling are NULL, then the row will be prepended to the toplevel. If both sibling and parent are set, then parent must be the parent of sibling. When sibling is set, parent is optional.

Parameters: parent A valid TreeIter, or NULL sibling A valid GtkTreeIter, or NULL

Returns: Iterator for the new row.

insertRowBefore

public TreeIter insertRowBefore(TreeIter sibling, TreeIter parent)
Inserts a new row before sibling. If sibling is NULL, then the row will be appended to parent 's children. If parent and sibling are NULL, then the row will be appended to the toplevel. If both sibling and parent are set, then parent must be the parent of sibling. When sibling is set, parent is optional

Parameters: parent A valid TreeIter, or NULL sibling A valid TreeIter, or NULL

Returns: Iterator for the new row.

isAncestor

public boolean isAncestor(TreeIter iter, TreeIter descendant)
Returns TRUE if iter is an ancestor of descendant. That is, iter is the parent (or grandparent or great-grandparent) of descendant.

Parameters: iter Row to be tested. descendant Descendant row for testing

Returns: True of iter is an ancestor of descendant

isIterValid

public boolean isIterValid(TreeIter iter)

moveRowAfter

public void moveRowAfter(TreeIter iter, TreeIter position)
Moves iter in this store to the position after position. iter and position should be in the same level. Note that this function only works with unsorted stores.

Since: 2.2

moveRowBefore

public void moveRowBefore(TreeIter iter, TreeIter position)
Moves iter in tree_store to the position before position. iter and position should be in the same level. Note that this function only works with unsorted stores.

Since: 2.2

moveRowToEnd

public void moveRowToEnd(TreeIter iter)
Moves iter to the end of the model

Since: 2.2

moveRowToStart

public void moveRowToStart(TreeIter iter)
Moves iter in this store to the start of the store.

Since: 2.2

prependRow

public TreeIter prependRow(TreeIter parent)
Prepends a new row to the store. If parent is non-NULL, then it will prepend the new row before the first child of parent, otherwise it will prepend a row to the top level.

Parameters: parent A valid TreeIter, or NULL

Returns: Iterator for the new row.

removeRow

public void removeRow(TreeIter iter)
Removes a row from the tree store. After being removed, iter is set to the next valid row at that level, or invalidated if it previously pointed to the last one.

Parameters: iter TreeIter representing the row.

reorder

public void reorder(TreeIter iter, int[] newOrder)

setColumnTypes

public void setColumnTypes(DataColumn[] dataColumns)

setDragDestListener

public void setDragDestListener(TreeDragDestListener listener)
This method has not yet been implemented.

setDragSourceListener

public void setDragSourceListener(TreeDragSourceListener listener)
This method has not yet been implemented.

setRowAt

public void setRowAt(DataRow aRow, TreeIter aIter)
Sets all columns pointed by aIter to the values stored in aRow.

Parameters: aRow a row with items aIter a TreeIter pointing to a row in the tree.

See Also: getRowAt

setSortColumn

public void setSortColumn(DataColumn column, SortType order)
Set the column in the list to sort on.

setSortMethod

public void setSortMethod(TreeIterComparison method, DataColumn column)
Set the class used to sort the list according to the values stored in the given DataColumn.

setValue

public void setValue(TreeIter iter, DataColumnString dataBlock, String value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The datablock in which the data should be stored. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The value to be set.

setValue

public void setValue(TreeIter iter, DataColumnStockItem dataBlock, GtkStockItem value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The datablock in which the data should be stored. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The value to be set.

setValue

public void setValue(TreeIter iter, DataColumnIconSize dataBlock, IconSize value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The datablock in which the data should be stored. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The value to be set.

setValue

public void setValue(TreeIter iter, DataColumnInt dataBlock, int value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The datablock in which the data should be stored. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The value to be set.

Since: 2.8.5

setValue

public void setValue(TreeIter iter, DataColumnLong dataBlock, long value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The datablock in which the data should be stored. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The long value to set into this row.

setValue

public void setValue(TreeIter iter, DataColumnBoolean dataBlock, boolean value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The datablock in which the data should be stored. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The value to be set.

setValue

public void setValue(TreeIter iter, DataColumnDouble dataBlock, double value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The datablock in which the data should be stored. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The value to be set.

setValue

public void setValue(TreeIter iter, DataColumnObject dataBlock, Object value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The data block in which to store the data, starting at 0. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The value to be set. This must match the type for that dataBlock, as set in the constructor.

setValue

public void setValue(TreeIter iter, DataColumnPixbuf dataBlock, Pixbuf value)
Sets a value in the dataStore. The type of the value must match the type set for that dataBlock in the constructor.

This does not make the data visible in any of the widgets which use the class - to do that, you have to construct a {@link TreeViewColumn} and add it to the {@link TreeView}; construct and add a {@link CellRenderer} to that; and finally associate the properties of the CellRenderer with the dataBlocks, using the {@link TreeViewColumn#addAttributeMapping(CellRenderer, CellRendererAttribute, DataColumn)} method.

Parameters: dataBlock The data block in which to store the data, starting at 0. iter Valid iterator for the data row in which the value is to be set. These can be gotten using methods such as {@link #appendRow(TreeIter)}. value The value to be set.

swapRows

public void swapRows(TreeIter a, TreeIter b)
Swaps a and b in the same level of tree_store. Note that this function only works with unsorted stores.

Since: 2.2