How to highlight element on diagram using Open API
Visual Paradigm’s Open API not just provides a way to extend the functionality of Visual Paradigm, but also offer you a door to integrate Visual Paradigm with 3rd party software. The integration is not necessary to single direction, from model to 3rd party software, but also from your 3rd party software to models in your Visual Paradigm project. i.e. models being updated by external system. In this situation an indication on diagram could be very helpful to indicate what model elements being updated. Starting from v13.1 Visual Paradigm’s Open API support highlight diagram elements on your diagram. This can help you to indicate what element was being updated by your 3rd party software. In this article we will show you how to highlight the elements in your diagrams.
To highlight elements on your current opening diagram:
We first retrieve the active diagram from the project.
DiagramManager lDiagramManager = ApplicationManager.instance().getDiagramManager(); IDiagramUIModel lDiagram = lDiagramManager.getActiveDiagram();
After that we generate a random number between 1 to 5 to control number of elements to highlight
// generate a random number between 1 to 5 int lCount = (int) (Math.random() * 5); if (lCount == 0) { lCount = 1; }
Next we retrieve all diagram elements from the diagram and put them into a list.
// retrieve the elements in diagram into an array IDiagramElement[] lDiagramElements = lDiagram.toDiagramElementArray(); int lDiagramElementLength = lDiagramElements.length; if (lDiagramElementLength > 0) { // convert the elements into a List List<IDiagramElement> lDiagramElementList = new ArrayList<IDiagramElement>(Arrays.asList(lDiagramElements));
After that we random reorder the elements in the list, and reduce the list to the size of the random number we generated.
for (int i = 0; i < lDiagramElementLength; i++) { // random reorder the element into another list int lIndex = (int) (Math.random() * lDiagramElements.length); if (i != lIndex) { IDiagramElement lDiagramElementA = lDiagramElementList.get(lIndex); lDiagramElementList.set(lIndex, lDiagramElementList.get(i)); lDiagramElementList.set(i, lDiagramElementA); } } // reduce the number of elements to retrieve account to the random number previously generated if (lDiagramElementList.size() > lCount) { lDiagramElementList = lDiagramElementList.subList(0, lCount); }
Finally we highlight the elements on diagram.
// highlight the element on diagram lDiagramManager.highlightAsAnimation(lDiagramElementList.toArray(new IDiagramElement[lDiagramElementList.size()]));
To clear the highlight you can simply call
// clean up the highlighted elements lDiagramManager.clearHighlightAsAnimation(lDiagram);
Sample Plugin
The sample plugin attached in this article demonstrates how you can highlight the elements in your diagram. After you deploy your plugin into Visual Paradigm, you can then click on the Highlight button in plugin toolbar to trigger the highlight. The highlight will be changed every time you press on the button. To clear the highlight you can simply press the Clear button to restore the diagram into normal.
Download Sample Plugin
You can click this link to download the sample plugin.
Related Know-how |
Related Links |
Leave a Reply
Want to join the discussion?Feel free to contribute!