The selection model requirements for an
IlpTree are defined by the interface
IlpTreeSelectionModel. This model extends the
Swing
TreeSelectionModel
to provide convenience operations when working with business
objects (
IlpObject).
The selection model is responsible for setting, modifying, and
retrieving the objects selected in the
IlpTree.
How to access the selection model of a
tree component
IlpTree tree = ...
//...
// Retrieve the selection model
IlpTreeSelectionModel selectionModel = tree.getSelectionModel();
How to retrieve selected objects from the
selection model
The following code sample shows you how to retrieve the selected
IlpObject instances from the selection
model.
Collection selection = selectionModel.getSelectedObjects();
Iterator it = selection.iterator();
while (it.hasNext()) {
IlpObject node = (IlpObject)it.next();
// Do what you want with the selected node
// ...
}
Setting the selection look and feel
The
IlpTree allows you to choose between the
look-and-feel for the selection:
HIGHLIGHT_SELECTION_LOOK_AND_FEEL
: the standard mode, where a selected cell appears
highlighted.
CHECKBOX_SELECTION_LOOK_AND_FEEL
: in this mode, a check box is displayed next to each tree
node. A check mark indicates that the corresponding node is
selected. Clicking a check box or a cell switches the
selection state of the corresponding node. In this mode, the
highlighting only indicates which cell has the focus.
Note
In this mode, collapsing a node does
not deselect its descendants.
The following code shows you how to activate the
CHECKBOX_SELECTION_LOOK_AND_FEEL
.
How to activate a selection look and
feel
IlpTree tree = ...
// Activate the CHECKBOX_SELECTION_LOOK_AND_FEEL
tree.setSelectionLookAndFeel
(IlpTreeView.CHECKBOX_SELECTION_LOOK_AND_FEEL);