Class DiagramListenerAdapter
- java.lang.Object
-
- com.nomagic.magicdraw.uml.symbols.DiagramListenerAdapter
-
@OpenApi public class DiagramListenerAdapter extends java.lang.Object
Forwards diagram events to the given
PropertyChangeListener
delegate. Diagram content event listeners inDiagramPresentationElement
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);
-
-
Field Summary
Fields Modifier and Type Field Description private java.beans.PropertyChangeListener
delegate
private java.beans.PropertyChangeListener
projectListener
private java.util.Collection<DiagramPresentationElement>
trackedDiagrams
-
Constructor Summary
Constructors Constructor Description DiagramListenerAdapter(Project project, java.beans.PropertyChangeListener delegate)
Deprecated.DiagramListenerAdapter(java.beans.PropertyChangeListener delegate)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
dispose(Project project)
Deprecated.void
install(Project project)
Install DiagramListenerAdapter to a project.private boolean
trackDiagram(DiagramPresentationElement diagram)
void
uninstall(Project project)
Removes itself from the project.private boolean
untrackDiagram(DiagramPresentationElement diagram)
-
-
-
Field Detail
-
projectListener
private final java.beans.PropertyChangeListener projectListener
-
delegate
private final java.beans.PropertyChangeListener delegate
-
trackedDiagrams
private final java.util.Collection<DiagramPresentationElement> trackedDiagrams
-
-
Constructor Detail
-
DiagramListenerAdapter
@OpenApi @Deprecated public DiagramListenerAdapter(Project project, java.beans.PropertyChangeListener delegate)
Deprecated.Install DiagramListenerAdapter to a project. Useuninstall(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)
-
uninstall
@OpenApi public void uninstall(Project project)
Removes itself from the project.- Parameters:
project
- uninstall from project.- See Also:
install(com.nomagic.magicdraw.core.Project)
-
trackDiagram
private boolean trackDiagram(DiagramPresentationElement diagram)
-
untrackDiagram
private boolean untrackDiagram(DiagramPresentationElement diagram)
-
-