|
java-gnome version 4.0.19 | ||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Objectorg.freedesktop.bindings.Pointer
org.freedesktop.bindings.Proxy
org.gnome.glib.Object
org.gnome.gtk.TreeSelection
public class TreeSelection
Manipulate the selection state of a TreeView. Every TreeView has an accompanying TreeSelection object which is used to manage whether or not rows can be selected, and to return to the programmer the current state of which rows are selected, if any.
TreeSelection can be used to programmatically select rows by either
TreeIter or TreePath; see the selectRow()
methods. For
example, to select the first row you could do:
final TreeSelection selection; selection = view.getSelection(); selection.selectRow(new TreePath("0"));
Using TreeSelection to determine the currently selected row is fairly straight forward:
selection.connect(new TreeSelection.Changed() { public void onChanged(TreeSelection source) { final TreeIter row; row = selection.getSelected(); if (row != null) { // do something! } } });Unfortunately, the
TreeSelection.Changed
signal is not
entirely deterministic; it is sometimes emitted more than once or for no
change at all. You'll need to allow for this in your code.
Mostly this is an API helper; the underlying documentation notes that
these could have all been methods on GtkTreeView
.
Nested Class Summary | |
---|---|
static interface |
TreeSelection.Changed
Emitted when the selection state of the TreeView changes. |
Method Summary | |
---|---|
void |
connect(TreeSelection.Changed handler)
Hook up a TreeSelection.Changed signal handler. |
SelectionMode |
getMode()
Get the mode that is governing selection behaviour on this TreeView. |
TreeIter |
getSelected()
Get the selected row from the TreeView. |
TreePath[] |
getSelectedRows()
Get the rows currently selected from the TreeView. |
boolean |
isSelected(TreePath path)
Return true if the currently selected row is pointed by
path . |
void |
selectRow(TreeIter row)
Select a row in the TreeView. |
void |
selectRow(TreePath path)
Select a row in the TreeView. |
void |
setMode(SelectionMode type)
Set what kinds of selections are allowed. |
void |
unselectAll()
Unselect all the rows in the TreeView. |
Methods inherited from class org.freedesktop.bindings.Pointer |
---|
toString |
Methods inherited from class Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public void connect(TreeSelection.Changed handler)
TreeSelection.Changed
signal handler.
public SelectionMode getMode()
public TreeIter getSelected()
SINGLE
or
BROWSE
.
null
if there is no currently selected row.public TreePath[] getSelectedRows()
MULTIPLE
. Otherwise getSelected()
offers a more
convenient way to obtain the selected row.
You can use the TreeModel's getIter()
method to convert the returned TreePaths to the more
convenient TreeIter:
TreePath[] rows; TreeSelection selection; TreeModel model; rows = selection.getSelectedRows(); for (int i = 0; i < rows.length; ++i) { TreeIter row = model.getIter(rows[i]); // do something with the row }
Also remember that both TreeIter and TreePath are temporally objects no
longer valid once you make any change to the model. Thus, if you plan
to modify the model, you may want to convert the returned TreePaths to
TreeRowReferences
.
public boolean isSelected(TreePath path)
true
if the currently selected row is pointed by
path
.
public void selectRow(TreeIter row)
selectRow(TreePath)
.
public void selectRow(TreePath path)
selectRow(TreeIter)
for the other. Use this one if you have
want to express expressing the row you want selected in abstract,
logical form.
public void setMode(SelectionMode type)
NONE
and
MULTIPLE
since
SINGLE
is the default. See SelectionMode
for the details of the behaviour implied by each option.
public void unselectAll()
|
![]() java-gnome |
||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |