Class DiagramListenerAdapter


  • @OpenApi
    public class DiagramListenerAdapter
    extends java.lang.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);
     
    • Constructor Detail

      • DiagramListenerAdapter

        @OpenApi
        @Deprecated
        public DiagramListenerAdapter​(Project project,
                                      java.beans.PropertyChangeListener delegate)
        Install DiagramListenerAdapter to a project. Use uninstall(Project) to stop receiving property change event in delegate.
        Parameters:
        project - project to install adapter to.
        delegate - delegate listener.
      • DiagramListenerAdapter

        @OpenApi
        public DiagramListenerAdapter​(java.beans.PropertyChangeListener delegate)
        Constructor.
        Parameters:
        delegate - delegate listener.
    • Method Detail

      • dispose

        @Deprecated
        @OpenApi
        public void dispose​(Project project)
        Deprecated.
        Removes itself from the project.
        Parameters:
        project - uninstall from project.
      • install

        @OpenApi
        public void install​(Project project)
        Install DiagramListenerAdapter to a project.
        Parameters:
        project - project to install adapter to.
        See Also:
        uninstall(Project)