A declarative model plugin lets MDriven Designer users build and open model-focused tools as ViewModels, without writing a compiled plugin assembly.
Use a declarative model plugin
Create a separate model project that contains the plugin ViewModels. Save the project as a modular file in the MDriven plugins folder. MDriven Designer loads the ViewModels and exposes them through the Plug-in Views menu.
For example, create a ViewModel named MyClassSeeker that lists classes in the loaded model and lets you search them. A modeler can then right-click in MDriven Designer, select Plug-in Views, select the plugin, and open MyClassSeeker.
Create the plugin project
- Create or open a model project for the plugin.
- Add a ViewModel that addresses the MDriven meta model. The meta model is the model that defines model elements such as classes, attributes, associations, and state machines.
- Define the ViewModel contents with named OCL expressions, columns, forms, and navigation.
- Save the project as a modular file in the plugins directory.
The plugin file contains meta-model information as well as the ViewModels. When MDriven Designer reads a declarative plugin, it ignores the meta-model information in the modular file and assumes that the plugin ViewModels conform to the meta model.
Load and open the plugin
After you save or update the modular file, load it in MDriven Designer.
- In MDriven Designer, use the command Reload plugins from disk. Alternatively, restart MDriven Designer.
- Right-click a relevant model element or area in the Designer.
- Select Plug-in Views.
- Select the plugin and then select the ViewModel to open.
The standard plugin location is managed by the MDriven plugin infrastructure. See Documentation:Plugins in Modlr for the default path and the PluginPath registry override.
Root a ViewModel for context-sensitive access
A rooted ViewModel requires a specific root object. MDriven Designer makes it available from Plug-in Views when the selected model element matches that root type.
For example, root a ViewModel named OneClass in the meta-model class type. When you select a class in MDriven Designer, Plug-in Views can offer OneClass directly for that class. The selected class becomes the ViewModel root.
A rooted plugin ViewModel can edit model data. For example, if OneClass shows the selected class's CodeComment, editing the value in the plugin form updates the same model object shown elsewhere in MDriven Designer.
Plugin ViewModels cannot use actions in the same way as application ViewModels. Use the navigation operator on selfVM to open another plugin ViewModel.
The navigation operator takes:
- The root object for the target ViewModel.
- The target ViewModel name.
For example, MyClassSeeker can display matching classes and provide a button that navigates from the selected class to OneClass. The selected class becomes the root object of OneClass, where its attributes are shown in a detail form.
Suitable uses
Use declarative model plugins for tools that inspect, navigate, document, or update the loaded model through ViewModels.
| Need | Declarative plugin example |
|---|---|
| Find model elements | Search for classes, associations, or other meta-model objects. |
| Improve documentation | List classes without a code comment and open each class for editing. |
| Inspect relationships | Show every association with a one-to-one cardinality. |
| Provide focused editing | Open a detail form for a selected class or other model element. |
You can define these tools with the same ViewModel techniques that you use elsewhere: OCL expressions determine what to show, and the ViewModel layout determines how to present it.
Declarative plugins and compiled plugins
A declarative plugin is a modular model file containing ViewModels. A compiled plugin is a .NET assembly that implements MDriven plugin interfaces.
| Type | Use when | Example |
|---|---|---|
| Declarative model plugin | You need a model-facing tool that can be expressed as ViewModels, OCL, forms, and navigation. | A class seeker and a class-detail form. |
| Compiled plugin | You need Designer extension points implemented in code, such as context-menu operations, code-generation callbacks, or custom OCL operations. | A context-menu command that changes the selected class name, or an OCL operation installed for design-time validation. |
For compiled plugin interfaces, assembly deployment, custom OCL operations, and code-generation callbacks, see Documentation:Modlr plugin.
Limits
- Plugin ViewModels address the MDriven meta model, not your application's runtime data model.
- Do not rely on application-style actions in a plugin ViewModel. Use
selfVMnavigation to open another plugin ViewModel. - Not every MDriven Designer capability is exposed through the meta model. For example, rendering the complete image of a diagram is not available through this approach.
Watch the declarative model plugin walkthrough.
