Modeling tools developed by No Magic Inc. provides an API to listen to all diagram changes in a single adapter that works in the following order:

  1. Receives events from all opened diagrams.
  2. Delegates these events to your own listener.

 

The adapter works in a project scope.

            

To listen to diagram change events, you need to create the com.nomagic.magicdraw.uml.symbols.DiagramListenerAdapter object, that is, to pass the property change listener as a delegator, which receives all events.

To create the DiagramListenerAdapter object, call:

    new DiagramListenerAdapter(propertyChangeListener)

The DiagramListenerAdapter object is registered for a project on its creation.

To start using the adapter, install it. Uninstall it when it is no longer necessary, that is, you do not need to receive any events about diagram changes anymore.

 

Property names related to presentation elements modification are defined in com.nomagic.magicdraw.uml.ExtendedPropertyNames class.

Example: Listening to symbol creation / removal

    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))
            {
                // an added / removed symbol
                PresentationElement presentationElement = (PresentationElement) evt.getNewValue();
            }
        }
    }
    
    adapter.install(project);
 
    // When the adapter is no longer needed, uninstall it. 
    adapter.uninstall(project);