Class SmartPropertyChangeListener
- java.lang.Object
-
- com.nomagic.uml2.ext.jmi.smartlistener.SmartPropertyChangeListener
-
- All Implemented Interfaces:
com.nomagic.uml2.ext.jmi.NonMaskedPropertyChangeListener,java.beans.PropertyChangeListener,java.util.EventListener
@OpenApiAll public class SmartPropertyChangeListener extends java.lang.Object implements com.nomagic.uml2.ext.jmi.NonMaskedPropertyChangeListenerSmartPropertyChangeListeneris "smarter" than standardPropertyChangeListener, 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).Example 1: listen to element owner's name
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);Example 2: listen recursively to owner's name and "Is Abstract" property
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);
-
-
Field Summary
Fields Modifier and Type Field Description private SmartListenerConfigconfigSmart listener configuration used to configure this smart listener.private java.beans.PropertyChangeListenerlistenerWrapped property change listener to which events are delegated.static java.lang.StringSMART_LISTENER_PROPAGATION_IDConstant ID of the property which is used in property names for smart listener events.private com.nomagic.uml2.ext.jmi.smartlistener.SmartListenerConfiguratorsmartListenerConfiguratorConfigures smart listeners.private com.nomagic.uml2.ext.jmi.reflect.AbstractRefObjecttargetTarget to which smart listener is attached.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSmartPropertyChangeListener(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, java.beans.PropertyChangeListener listener, SmartListenerConfig configuration)Constructs the smart property change listener.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description (package private) com.nomagic.uml2.ext.jmi.smartlistener.SmartListenerConfiguratorcreateSmartListenerConfigurator(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, SmartListenerConfig config)static SmartPropertyChangeListenercreateSmartPropertyListener(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, java.beans.PropertyChangeListener listener, SmartListenerConfig config)Factory method for creating a smart property change listener.static SmartPropertyChangeListenercreateSmartPropertyListener(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 SmartPropertyChangeListenercreateSmartPropertyListener(Element target, java.beans.PropertyChangeListener listener, SmartListenerConfig config)Factory method for creating a smart property change listener.static SmartPropertyChangeListenercreateSmartPropertyListener(Element target, java.beans.PropertyChangeListener listener, java.util.Collection<SmartListenerConfig> configurations)Factory method for creating a smart property change listener.voiddispose()Disposes and cleans up.voideventDeliveryRestored()voideventDeliveryStopped()SmartListenerConfiggetConfig()java.beans.PropertyChangeListenergetListener()com.nomagic.uml2.ext.jmi.reflect.AbstractRefObjectgetTarget()static SmartListenerConfigmergeConfigurations(SmartListenerConfig c1, SmartListenerConfig c2)static SmartListenerConfigmergeConfigurations(java.util.Collection<SmartListenerConfig> configurations)Deprecated.private voidnotifyListener(java.beans.PropertyChangeEvent e)Delegates the event to the wrapped listener.voidpropertyChange(java.beans.PropertyChangeEvent e)java.lang.StringtoString()
-
-
-
Field Detail
-
SMART_LISTENER_PROPAGATION_ID
public static final java.lang.String SMART_LISTENER_PROPAGATION_ID
Constant ID of the property which is used in property names for smart listener events.- See Also:
- Constant Field Values
-
target
private final com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target
Target to which smart listener is attached.
-
listener
private final java.beans.PropertyChangeListener listener
Wrapped property change listener to which events are delegated.
-
smartListenerConfigurator
private final com.nomagic.uml2.ext.jmi.smartlistener.SmartListenerConfigurator smartListenerConfigurator
Configures smart listeners.
-
config
private final SmartListenerConfig config
Smart listener configuration used to configure this smart listener.
-
-
Constructor Detail
-
SmartPropertyChangeListener
protected SmartPropertyChangeListener(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, java.beans.PropertyChangeListener listener, SmartListenerConfig configuration)Constructs the smart property change listener.- Parameters:
target- target to which smart listener is attached.listener- listener to which elements are being delegated.configuration- configuration to apply to the given element.
-
-
Method Detail
-
mergeConfigurations
@Deprecated public static SmartListenerConfig mergeConfigurations(SmartListenerConfig c1, SmartListenerConfig c2)
Merges two configurations into a single configuration.- Parameters:
c1- first configuration to mergec2- second configuration to merge- Returns:
- merged configuration
-
mergeConfigurations
@Deprecated public static SmartListenerConfig mergeConfigurations(java.util.Collection<SmartListenerConfig> configurations)
Deprecated.Merges given configurations into a single configuration.- Parameters:
configurations- configurations to merge- Returns:
- merged configuration
-
createSmartListenerConfigurator
com.nomagic.uml2.ext.jmi.smartlistener.SmartListenerConfigurator createSmartListenerConfigurator(com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject target, SmartListenerConfig config)
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
notifyListener
private void notifyListener(java.beans.PropertyChangeEvent e)
Delegates the event to the wrapped listener.- Parameters:
e- event to delegate.
-
dispose
public void dispose()
Disposes and cleans up.
-
createSmartPropertyListener
public static SmartPropertyChangeListener createSmartPropertyListener(Element target, java.beans.PropertyChangeListener listener, java.util.Collection<SmartListenerConfig> configurations)
Factory method for creating a smart property change listener.- Parameters:
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.- Returns:
- created smart property change listener.
-
createSmartPropertyListener
public 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.- Parameters:
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.- Returns:
- created smart property change listener.
-
createSmartPropertyListener
public static SmartPropertyChangeListener createSmartPropertyListener(Element target, java.beans.PropertyChangeListener listener, SmartListenerConfig config)
Factory method for creating a smart property change listener.- Parameters:
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.- Returns:
- created smart property change listener.
-
createSmartPropertyListener
public 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.- Parameters:
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.- Returns:
- created smart property change listener.
-
getConfig
public SmartListenerConfig getConfig()
-
getTarget
public com.nomagic.uml2.ext.jmi.reflect.AbstractRefObject getTarget()
-
getListener
public java.beans.PropertyChangeListener getListener()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
eventDeliveryStopped
public void eventDeliveryStopped()
- Specified by:
eventDeliveryStoppedin interfacecom.nomagic.uml2.ext.jmi.NonMaskedPropertyChangeListener
-
eventDeliveryRestored
public void eventDeliveryRestored()
- Specified by:
eventDeliveryRestoredin interfacecom.nomagic.uml2.ext.jmi.NonMaskedPropertyChangeListener
-
-