The plug-in
org.eclipse.app4mc.visualization.ui
provides a small framework to visualize model elements. It contains a view part
VisualizationPart
that can be opened via
Via the context menu it is also possible to open multiple instances of the
VisualizationPart
.
On selecting a model element, the VisualizationPart is updated to render a corresponding visualization. The visualization to render is searched in the ModelVisualizationRegistry OSGi service. If multiple visualizations are registered, the first one will be selected by default, unless the user has selected another visualization before.
The visualization view has 4 entries in the toolbar:
The whole red area can be used to render the visualization.
To contribute a new visualization to the framework, the followings steps have to be done:
@Component(property= {
"name=Runnable Visualization",
"description=Render the name of the Runnable"
})
public class SampleVisualization implements Visualization {
@PostConstruct
public void createVisualization(Runnable runnable, Composite parent) {
Label label = new Label(parent, SWT.NONE);
label.setText(runnable.getName());
}
}
To register the Visualization implementation the framework utilizes OSGi DS. This means:
It is mandatory to place this class inside a user defined package (i.e., other than default package)
To enable DS annotation for the entire workspace,enable the following option in your eclipse workspace at:
Window -> Preferences -> Plug-in Development -> DS Annotations -> "Enable descriptors from annotated sources"
Once above steps are followed, visualization plugin contents should look like below:
The Visualization will automatically be registered in the ModelVisualizationRegistry with the appropriate meta-data. The meta-data is extracted from the class definition and the method annotated with @PostConstruct. Additionally information can be provided via component properties on the @Component annotation.
The following component properties are supported:
The rendering is triggered via Eclipse injection mechanisms. Therefore a method annotated with @PostConstruct needs to be created. This method needs at least two parameters in the following order:
So the following method signatures would be valid for Visualizations for Runnable model elements:
@PostConstruct
public void createVisualization(Runnable runnable, Composite parent) {}
@PostConstruct
public void createVisualization(List<Runnable> runnable, Composite parent) {}
You can specify additional parameters that should be injected. Only the first parameter has a semantic to be able to extract the model type for which the Visualization is implemented.
Additionally a method annotated with @PreDestroy can be added that gets called before the Visualization is disposed. This gives the opportunity to clean up resources if necessary.
As the service instance creation is done by the OSGi Service Component Runtime, the following information needs to be considered with regards to injection: