Capture Application Events using Open API
Open API is a powerful tool for developers to extend the functionality of Visual Paradigm software. It does not just allow you to have full access to the model data within your project, but also allow you to alter the behavior of the software. In this article, you will learn how to capture various events which has been fired during the execution of the software, and you can make use of these events to insert custom actions to achieve your goal.
Events on the project
Implementing the IProjectListener interface will allow you to capture the following events which happen on your project. It can be registered to the project by calling IProject.addProjectListener(listener) method.
Events | Operation |
Project being created | The projectNewed(project) method fires when a new project is being created. |
Project being opened | The projectOpened(project) method fires when open a project. |
Project being renamed | The projectRenamed(project) method fires when a project is being renamed. |
Project is going to save | The projectPreSave(project) method fires before saving of the project. |
Project is saved | The projectSaved(project) method fires after project is being saved. |
Events related to adding or removing diagrams in project
The IProjectDiagramListener interface allows you to capture the events by adding or removing diagrams to the project. The IProjectDiagramListener can be registered to project by calling IProject. addProjectDiagramListener(listener) method.
Events | Operation |
Add diagram | The diagramAdded(IProject, IDiagramUIModel) method fires when adding new diagram to project where the second argument IDiagramUIModel is the diagram being created. |
Remove diagram | The diagramRemoved(IProject, IDiagramUIModel) method fires when removing a diagram from project where the second argument IDiagramUIModel is the diagram being removed. |
Events related to adding or removing model elements in project
The IProjectModelListener interface allows you to capture the events on adding or removing model elements to the project. The IProjectModelListener can be registered to project by calling IProject. addProjectModelListener(listener) method.
Events | Operation |
Add model element | The modelAdded(IProject, IModelElement) method fires when adding new model element to project where the second argument IModelElement is the model element being created. |
Remove model element | The modelRemoved(IProject, IModelElement) method fires when removing a model element from project where the second argument IModelElement is the model element being removed. |
Events related to the diagram
The IDiagramListener interface offers operations to capture various events on your diagram. The IDiagramListener can be registered to diagram by calling IDiagramUIModel.addDiagramListener(listener) method.
Events | Operations |
Add shape to diagram | The diagramElementAdded(IDiagramUIModel, IDiagramElement) fires when adding shape to a diagram where the first argument is the target diagram and the second argument is the shape being created. |
Remove shape from diagram | The diagramElementRemoved(IDiagramUIModel, IDiagramElement) fires when removing shape from a diagram where the first argument is the target diagram and the second argument is the shape being removed. |
Diagram load from project | The method diagramUIModelLoaded(IDiagramUIModel) method fires when the diagram is load from project. i.e. the diagram is being opened. |
Rename diagram | The diagramUIModelRenamed(IDiagramUIModel) method fires when the diagram is being renamed. The argument in this operation is the subject diagram. |
Changing diagram property | The diagramUIModelPropertyChanged(IDiagramUIModel, String, Object, Object) method fires when the property of the diagram is being modified. The first argument is the subject diagram. The second argument is the name of the property which is being modified. The third and fourth argument are the original and new values of the property respectively. |
Events related to model element
There is no specific event listener interface for model element. You can simply implement your own PropertyChangeListener and attach it to model element to listen to its change. Once the model element is being modified, then events will fire to the PropertyChangeListener. You can use the IModelElement.addPropertyChangeListener(listener) method to register the listener.
Sample plugin
The sample plugin attached to this document demonstrate how to capture the events on your project. After deploy the plugin to Visual Paradigm installation directory and restart of application, the plugin will be triggered upon creating new project.
Related Know-how |
Related Link |
Leave a Reply
Want to join the discussion?Feel free to contribute!