@OpenApiAll
public class SmartPropertyChangeListener
extends java.lang.Object
implements com.nomagic.uml2.ext.jmi.NonMaskedPropertyChangeListener
SmartPropertyChangeListener
is "smarter" than standard PropertyChangeListener
,
because it allows to listen not only to properties of a single model element,
but also to related model element properties in the model.
Given a model element, it is possible to listen to changes in the model which occur outside the element.
These changes are related through a chain of element properties.
General idea: to create a smart listener for an element, you have to pass in a collection of smart listener configurations which describe how to reach the changes in the model which are of interest to you.
A single configuration contains the element's class and references to other elements which are of interest to us (a reference in this case is a property name).
Remark: if you want to listen for a specific property of a single model element without listening to
properties outside the model element, use BaseElement.addPropertyChangeListener(java.beans.PropertyChangeListener)
.
Element element = ...; // some element SmartListenerConfig config = new SmartListenerConfig(); config.listenTo(PropertyNames.NAME); // listen to element's name config.listenToNested(PropertyNames.OWNER).listenTo(PropertyNames.NAME); // listen to element owner's name // create the listener SmartPropertyChangeListener.createSmartPropertyListener(element, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // change event comes here } }, config);
Element element = ...; // some element SmartListenerConfig config = new SmartListenerConfig(); config.listenTo(PropertyNames.NAME); config.listenTo(PropertyNames.IS_ABSTRACT); config.listenTo(PropertyNames.OWNER, config); SmartPropertyChangeListener.createSmartPropertyListener(element, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // change event comes here } }, config);
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SMART_LISTENER_PROPAGATION_ID
Constant ID of the property which is used in property names for smart listener events.
|
Modifier | Constructor and Description |
---|---|
protected |
SmartPropertyChangeListener(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target,
java.beans.PropertyChangeListener listener,
SmartListenerConfig configuration)
Constructs the smart property change listener.
|
Modifier and Type | Method and Description |
---|---|
(package private) com.nomagic.uml2.ext.jmi.smartlistener.SmartListenerConfigurator |
createSmartListenerConfigurator(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target,
SmartListenerConfig config) |
static SmartPropertyChangeListener |
createSmartPropertyListener(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target,
java.beans.PropertyChangeListener listener,
java.util.Collection<SmartListenerConfig> configurations)
Factory method for creating a smart property change listener.
|
static SmartPropertyChangeListener |
createSmartPropertyListener(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target,
java.beans.PropertyChangeListener listener,
SmartListenerConfig config)
Factory method for creating a smart property change listener.
|
static SmartPropertyChangeListener |
createSmartPropertyListener(Element target,
java.beans.PropertyChangeListener listener,
java.util.Collection<SmartListenerConfig> configurations)
Factory method for creating a smart property change listener.
|
static SmartPropertyChangeListener |
createSmartPropertyListener(Element target,
java.beans.PropertyChangeListener listener,
SmartListenerConfig config)
Factory method for creating a smart property change listener.
|
void |
dispose()
Disposes and cleans up.
|
void |
eventDeliveryRestored() |
void |
eventDeliveryStopped() |
SmartListenerConfig |
getConfig() |
java.beans.PropertyChangeListener |
getListener() |
com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject |
getTarget() |
static SmartListenerConfig |
mergeConfigurations(java.util.Collection<SmartListenerConfig> configurations)
Merges given configurations into a single configuration.
|
static void |
mergeConfigurations(java.util.Map<java.lang.Class<? extends Element>,java.util.Collection<SmartListenerConfig>> destination,
java.util.Map<java.lang.Class<? extends Element>,java.util.Collection<SmartListenerConfig>> source)
Adds all source configurations to the destination map and merges all configurations of each element type.
|
static SmartListenerConfig |
mergeConfigurations(SmartListenerConfig c1,
SmartListenerConfig c2)
Merges two configurations into a single configuration.
|
void |
propertyChange(java.beans.PropertyChangeEvent e) |
java.lang.String |
toString() |
public static final java.lang.String SMART_LISTENER_PROPAGATION_ID
protected SmartPropertyChangeListener(@Nonnull com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, @Nonnull java.beans.PropertyChangeListener listener, @Nonnull SmartListenerConfig configuration)
target
- target to which smart listener is attached.listener
- listener to which elements are being delegated.configuration
- configuration to apply to the given element.public static SmartListenerConfig mergeConfigurations(@Nonnull java.util.Collection<SmartListenerConfig> configurations)
configurations
- configurations to merge.public static SmartListenerConfig mergeConfigurations(@Nonnull SmartListenerConfig c1, @Nonnull SmartListenerConfig c2)
c1
- first configuration to merge.c2
- second configuration to merge.public static void mergeConfigurations(java.util.Map<java.lang.Class<? extends Element>,java.util.Collection<SmartListenerConfig>> destination, @CheckForNull java.util.Map<java.lang.Class<? extends Element>,java.util.Collection<SmartListenerConfig>> source)
destination
- destination of all configurations. This map should be modifiable.source
- configurations to add.com.nomagic.uml2.ext.jmi.smartlistener.SmartListenerConfigurator createSmartListenerConfigurator(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, SmartListenerConfig config)
public void propertyChange(java.beans.PropertyChangeEvent e)
propertyChange
in interface java.beans.PropertyChangeListener
public void dispose()
public static SmartPropertyChangeListener createSmartPropertyListener(@Nonnull Element target, @Nonnull java.beans.PropertyChangeListener listener, @Nonnull java.util.Collection<SmartListenerConfig> configurations)
target
- element to which to attach the listener.listener
- wrapped listener to which events should be delegated.configurations
- configurations with which to configure the smart listener.public static SmartPropertyChangeListener createSmartPropertyListener(@Nonnull com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, @Nonnull java.beans.PropertyChangeListener listener, @Nonnull java.util.Collection<SmartListenerConfig> configurations)
target
- target to which to attach the listener.listener
- wrapped listener to which events should be delegated.configurations
- configurations with which to configure the smart listener.public static SmartPropertyChangeListener createSmartPropertyListener(@Nonnull Element target, @Nonnull java.beans.PropertyChangeListener listener, @Nonnull SmartListenerConfig config)
target
- target to which to attach the listener.listener
- wrapped listener to which events should be delegated.config
- configuration with which to configure the smart listener.public static SmartPropertyChangeListener createSmartPropertyListener(@Nonnull com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, @Nonnull java.beans.PropertyChangeListener listener, @Nonnull SmartListenerConfig config)
target
- target to which to attach the listener.listener
- wrapped listener to which events should be delegated.config
- configuration with which to configure the smart listener.@Nonnull public SmartListenerConfig getConfig()
@Nonnull public com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject getTarget()
@Nonnull public java.beans.PropertyChangeListener getListener()
public java.lang.String toString()
toString
in class java.lang.Object
public void eventDeliveryStopped()
eventDeliveryStopped
in interface com.nomagic.uml2.ext.jmi.NonMaskedPropertyChangeListener
public void eventDeliveryRestored()
eventDeliveryRestored
in interface com.nomagic.uml2.ext.jmi.NonMaskedPropertyChangeListener