Create and Access Logical View via API

Open API not only allows you access the model data within the project, but also create and access the Logical View in your project. This article will show you how to create Logical View using Open API.

Create Logical View

To create logical view, we first need to get the logical view from the project

IProject lProject = ApplicationManager.instance().getProjectManager().getProject();
ILogicalView lLogicalView = lProject.getLogicalView();

Once you get the logical view from project, we can then create a container under the logical view

ILogicalViewContainer lFolder = lLogicalView.createContainer();
lFolder.setName("Plugin Logical View");
lFolder.setNickname("Plugin Logical View");

And finally we can add a diagram under the logical view

IDiagramUIModel lDiagram = ApplicationManager.instance().getDiagramManager().createDiagram(DiagramManager.DIAGRAM_TYPE_USE_CASE_DIAGRAM);

List out the Logical View

To list out the logical view in your project, we first need to get the root of logical view

ILogicalView lLogicalView = lProject.getLogicalView();

After that we can retrieve its child as an array

ILogicalViewElement[] lChildren = lLogicalView.toChildArray();

We can then loop through the array to inspect each element. If the element is an instance of ILogicalViewParent, we can then put it into a recursive loop to further inspect its details.

Sample Plugins

This sample plugin demonstrate how to create nested class with containment relationships. You will find 2 extra buttons in application toolbar once you deployed the plugin to VP applications. One of it will create a logical view “Plugin Logical View” with a Use Case Diagram inside. The other button will list out the logical view in your project in message pane.

Plugin buttons for create and list out logical view

Plugin buttons for create and list out logical view

Download Sample Plugin

You can download the sample plugins at here.

Related Articles

Related Links

1197 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply