Skip to main content

Extending existing Plugins

In many scenarios, you'll want to extend existing metamodels by adding support for new element types within your plugins. This section details how to integrate these new elements into the editor's tree view and handle their specific behaviors.

ElementTreeExtension: Integrating Model Extensions into the Tree View

To attach elements of a ModelExtension to the editor's tree view, you use an ElementTreeExtension. This allows elements linked to the model by an extension reference to appear as nodes in the main tree structure.

You define ElementTreeExtensions within the <elementTreeExtensions> section of your editorModelExtension:

<editorModelExtension xmlns="https://schemas.normalizedsystems.org/xsd/editorElements/3/4/0">
<name>workflows</name>
<elementTreeExtensions>
<elementTreeExtension>
<name>workflows</name>
<actions>
<editorAction>workflows::createWorkflow</editorAction>
</actions>
<!-- Extension reference used a data source-->
<extensionReference>workflows::Workflow::component</extensionReference>
<nodeType>workflows::Workflow</nodeType>
</elementTreeExtension>
</elementTreeExtensions>
</editorModelExtension>

In this example the <extensionReference>workflows::Workflow::component</extensionReference> indicates that this extension will draw its elements from the component reference of the workflows::Workflow element.

Supporting Subclasses of Abstract Elements

When working with metamodels that utilize abstract elements and their concrete subclasses, you need to configure your plugin to correctly handle the creation, display, and manipulation of these subclasses. This involves defining specific components and actions for each subclass, even when they share a common superclass composition.

To add support for subclasses, follow these steps:

  • Define an ElementDetailComponent for the subclass: This ensures that when an instance of the subclass is selected, the editor knows how to display and allow editing of its unique properties.
  • Add an ElementTreeNode for the subclass: This allows instances of the subclass to be properly represented and navigated within the editor's tree view.
  • Define a CreateAction with the subclass's ElementDetailComponent, but specify the composition reference of the superclass: This is a key step. When creating a new instance of a subclass, it will typically be added to a collection (composition reference) defined by its abstract superclass. By linking the CreateAction to the superclass's reference while specifying the subclass's detail component, you can provide a new option when the user creates a new instance.

Let's illustrate with an example where EnumType is a subclass of an abstract ValueType which is part of a Component:

<editorModelExtension xmlns="https://schemas.normalizedsystems.org/xsd/editorElements/3/8/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>enumTypeElements</name>
<elementDetailComponents>
<elementDetailComponent>
<name>EnumType</name>
<autogenerate>true</autogenerate>
<elementClass>enumTypeElements::EnumType</elementClass>
</elementDetailComponent>
</elementDetailComponents>
<actions>
<editorAction type="editorElements::CreateAction" xsi:type="createAction">
<name>createEnumType</name>
<reference>elements::Component::valueTypes</reference>
<elementDetailComponent>enumTypeElements::EnumType</elementDetailComponent>
</editorAction>
<editorAction type="editorElements::DeleteAction" xsi:type="deleteAction">
<name>deleteEnumType</name>
<elementClass>enumTypeElements::EnumType</elementClass>
</editorAction>
</actions>
<elementTreeNodes>
<elementTreeNode>
<name>EnumType</name>
<actions>
<editorAction>enumTypeElements::deleteEnumType</editorAction>
</actions>
<elementClass>enumTypeElements::EnumType</elementClass>
</elementTreeNode>
</elementTreeNodes>
</editorModelExtension>

By following these steps, you ensure that your plugin correctly integrates new subclass types into the editor's functionality, allowing users to create, view, and modify them seamlessly within the context of the larger metamodel.