Class DiagramListenerAdapter

java.lang.Object
com.nomagic.magicdraw.uml.symbols.DiagramListenerAdapter

@OpenApi public class DiagramListenerAdapter extends Object

Forwards diagram events to the given PropertyChangeListener delegate. Diagram content event listeners in DiagramPresentationElement are notified about all changes in the opened diagram. This class adds itself to those listeners and forwards all events to the delegate. It listens for diagram content change events from opened diagrams only. It takes care of (de)attaching itself as listener to the diagram when diagram is closed or opened. Diagram open/close events are forwarded to the delegate as well.

A DiagramListenerAdapter object has the ability to delegate all events to your own listener. This adapter is everything you need, when listening to the opened diagram change events. Adapter works in a project scope.

To listen to the diagram change events, you must create a DiagramListenerAdapter and install it for the project. To create the DiagramListenerAdapter, call:

 new DiagramListenerAdapter(propertyChangeListener)
 

To create the adapter, you need to pass the property change listener as a delegate, which will receive all events. To start using the adapter, install it. Uninstall it when it is no longer necessary.

IMPORTANT! The uninstalled adapter cannot be reused anymore. To start receiving events, you must create a new instance of the DiagramListenerAdapter.

Example of listening to symbol creation/deletion

 DiagramListenerAdapter adapter = new DiagramListenerAdapter(new PropertyChangeListener()
 {
        public void propertyChange(PropertyChangeEvent evt)
     {
                String propertyName = evt.getPropertyName();
                if (ExtendedPropertyNames.VIEW_ADDED.equals(propertyName) ||
                        ExtendedPropertyNames.VIEW_REMOVED.equals(propertyName))
         {
                        // added/removed symbol
                        PresentationElement presentationElement = (PresentationElement) evt.getNewValue();
         }
     }
 });

 adapter.install(project);

 // When it is no longer needed, uninstall it.
 adapter.uninstall(project);