The PropertyChangeEvents support provides the ability to listen to the event by different scopes. The scope depends on how the listener is registered:
The java.beans.PropertyChangeListener should be registered to receive these events. There are several different ways to register a listener:
project.getRepositoryListenerRegistry().addPropertyChangeListener(listener, (RefObject)null); |
This listener will get all the property change events from any element.
project.getRepositoryListenerRegistry().addPropertyChangeListener(listener, UML2MetamodelConstants.BEFORE_DELETE); |
This listener will be notified, when any model element is set to be deleted.
element.addPropertyChangeListener(listener); |
This listener will be notified when any element property is changed.
project.getSmartEventSupport().registerConfig(aClass, configs, listener); |
This listener will be notified, when any property of any element in the project with this type is changed. If “configs” is NULL, the listener will get all property change events.
EventSupport could be disabled from the event firing:
|
These examples show, how to create the property change listeners to listen to the different kind of properties.
element.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // evt.getPropertyName() is changed } }); |
element.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (PropertyNames.NAME.equals(evt.getPropertyName())) { // name is Changed } } }); |