A class must implement the
ManagerSelectionListener interface
to be notified that selections in a manager have been modified. This
interface contains only the
selectionChanged
method,
which is called each time an object is selected or deselected.
void selectionChanged(ManagerSelectionChangedEvent event)
To be notified of selections and deselections, a class
must register itself using the following method of the class IlvManager
:
void addManagerSelectionListener(ManagerSelectionListener l)
Note that the selectionChanged
method
is called just after the object is selected or deselected, so you
can easily determine whether it is a selection or a deselection. You
do this in the following way:
class MyListener implements ManagerSelectionListener
{
public void selectionChanged(ManagerSelectionChangedEvent event)
{
// retrieve the graphic object
IlvGraphic obj = event.getGraphic();
IlvManager manager = event.getManager();
if (manager.isSelected(obj)) {
// object was selected
} else {
// object was deselected
}
}
}
When numerous objects are being selected, for example,
as a result of a call to the
selectAll
method
of the manager, many selection events will be sent to the selection
listeners. This can be inefficient for some listeners that need to
perform an action when the selection is stable. For example, a property
inspector showing the properties of selected objects does not need
to be updated for each individual selection when a number of objects
are selected at the same time. To solve this kind of problem, the
ManagerSelectionChangedEvent class has the following methods:
In the case of a “property inspector,”
the listener would be as follows:
class MyListener implements ManagerSelectionListener
{
public void selectionChanged(ManagerSelectionChangedEvent event)
{
if (!event.isAdjusting() || event.isAdjustmentEnd())
{
// update the properties only if this is a single
// selection or the end of a series.
}
}
}
You may want to use the same “adjustment”
notification when selecting numerous objects in a manager. The IlvManager
class
allows you to do this using the setSelectionAdjusting
method:
boolean isAdjusting = manager.isSelectionAdjusting();
manager.setSelectionAdjusting(true);
try {
// select or deselect a lot of objects.
} finally {
manager.setSelectionAdjusting(isAdjusting);
}