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
ConstructorsModifierConstructorDescriptionprotectedALcdWeakSelectionListener(T aObjectToModify) Creates a newALcdWeakSelectionListenerinstance which can updateaObjectToModifywhen it receives events. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidselectionChanged(TLcdSelectionChangedEvent aSelectionEvent) This method will be called by anILcdSelectionwhen thisILcdSelectionListenerhas been registered to it, and when the selection state of someObjecthas changed in theILcdSelection.protected abstract voidselectionChangedImpl(T aToModify, TLcdSelectionChangedEvent aSelectionEvent)
-
Constructor Details
-
ALcdWeakSelectionListener
Creates a new
ALcdWeakSelectionListenerinstance which can updateaObjectToModifywhen it receives events.- Parameters:
aObjectToModify- The object you want to modify when aTLcdSelectionChangedEventis received. This is a short-lived object, while the listener will be attached to a long-livingILcdSelectionobject.
-
-
Method Details
-
selectionChanged
This method will be called by anILcdSelectionwhen thisILcdSelectionListenerhas been registered to it, and when the selection state of someObjecthas 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:
selectionChangedin interfaceILcdSelectionListener<T>- Parameters:
aSelectionEvent- a TLcdSelectionChangedEvent detailing the changes in the selection.- See Also:
-
selectionChangedImpl
protected abstract void selectionChangedImpl(T aToModify, TLcdSelectionChangedEvent aSelectionEvent)
-