Class ALcdWeakSelectionListener<T>
- Type Parameters:
T
- The type of the short-lived object
- All Implemented Interfaces:
ILcdSelectionListener
,Serializable
,EventListener
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:
- The object to listen to must implement
ILcdSelection
. - The listener must be registered using
ILcdSelection#addSelectionListener
.
- Since:
- 2015.1
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
ALcdWeakSelectionListener
(T aObjectToModify) Creates a newALcdWeakSelectionListener
instance which can updateaObjectToModify
when it receives events. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
selectionChanged
(TLcdSelectionChangedEvent aSelectionEvent) This method will be called by anILcdSelection
when thisILcdSelectionListener
has been registered to it, and when the selection state of someObject
has changed in theILcdSelection
.protected abstract void
selectionChangedImpl
(T aToModify, TLcdSelectionChangedEvent aSelectionEvent)
-
Constructor Details
-
ALcdWeakSelectionListener
Creates a new
ALcdWeakSelectionListener
instance which can updateaObjectToModify
when it receives events.- Parameters:
aObjectToModify
- The object you want to modify when aTLcdSelectionChangedEvent
is received. This is a short-lived object, while the listener will be attached to a long-livingILcdSelection
object.
-
-
Method Details
-
selectionChanged
This method will be called by anILcdSelection
when thisILcdSelectionListener
has been registered to it, and when the selection state of someObject
has changed in theILcdSelection
.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.- Specified by:
selectionChanged
in interfaceILcdSelectionListener<T>
- Parameters:
aSelectionEvent
- a TLcdSelectionChangedEvent detailing the changes in the selection.- See Also:
-
selectionChangedImpl
protected abstract void selectionChangedImpl(T aToModify, TLcdSelectionChangedEvent aSelectionEvent)
-