T
- The type of the short-lived objectpublic abstract class ALcdWeakSelectionListener<T> extends Object implements ILcdSelectionListener
A ILcdSelectionListener
implementation which only keeps a WeakReference
to the object it
wants to update when selection changes are received. This avoids memory leaks, even without removing the
listener.
The class javadoc of ALcdWeakModelListener
contains an example of a weak listener,
and some rules on the usage of weak listeners.
This particular listener has two extra rules compared to the general rules of weak listeners:
ILcdSelection
.ILcdSelection#addSelectionListener
.Modifier | Constructor and Description |
---|---|
protected |
ALcdWeakSelectionListener(T aObjectToModify)
Creates a new
ALcdWeakSelectionListener instance which can update aObjectToModify
when it receives events. |
Modifier and Type | Method and Description |
---|---|
void |
selectionChanged(TLcdSelectionChangedEvent aSelectionEvent)
This method will be called by an
ILcdSelection when this
ILcdSelectionListener has been registered to it, and when the
selection state of some Object has changed in the
ILcdSelection . |
protected abstract void |
selectionChangedImpl(T aToModify,
TLcdSelectionChangedEvent aSelectionEvent) |
protected ALcdWeakSelectionListener(T aObjectToModify)
Creates a new ALcdWeakSelectionListener
instance which can update aObjectToModify
when it receives events.
aObjectToModify
- The object you want to modify when a TLcdSelectionChangedEvent
is received.
This is a short-lived object, while the listener will be attached to a
long-living ILcdSelection
object.public final void selectionChanged(TLcdSelectionChangedEvent aSelectionEvent)
ILcdSelection
when this
ILcdSelectionListener
has been registered to it, and when the
selection state of some Object
has changed in the
ILcdSelection
.
This method will check whether the short-living object is still available.
If it is, this method will pass the short-living object and the event to the selectionChangedImpl(Object, TLcdSelectionChangedEvent)
method.
If the short-living object is already garbage collected, this method will de-register the listener from the source.
selectionChanged
in interface ILcdSelectionListener
aSelectionEvent
- a TLcdSelectionChangedEvent detailing the changes
in the selection.selectionChangedImpl(Object, TLcdSelectionChangedEvent)
protected abstract void selectionChangedImpl(T aToModify, TLcdSelectionChangedEvent aSelectionEvent)