Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

  1. Receives The listener receives events from all opened diagrams.
  2. Delegates The adapter delegates these events to your own listener.

 

Note

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:

Code Block
languagejava
    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.ExtendedPropertyNamesclass.

Example: Listening to symbol creation / removal

Code Block
languagejava
    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);