Blog Post

How to create model based JavaScript Add-ins using Enterprise Architect 15

One of the latest features of Sparx Enterprise Architect 15 is the model based add-ins which can be created using JavaScript.  These model based add-ins are defined by a combination of Receptions, Attributes and Operations which can be easy added in a model by just creating with a valid stereotyped classes.

Assuming you have a basic knowledge in Sparx Traditional add-ins, broadcast events and JavaScript.

Why model based add-ins

  • Accessed by all the users with in a model
  • Purely Model specific
  • No installation, registry entries , distribution or license worries
  • Self-Documenting as everything is modelled and created directly in EA

Prerequisites

  • Signal Reference Library ( Broadcast Events ) –  Defines the entry points to the add-In similar to the com class in the traditional add-ins
  • Referencing relevant signals in the receptions

What is Signal Reference Library

These are Signal elements which contain definitions of all the Enterprise architect broadcast events. Signals that are added to the add-in will receive an event when triggered. EAExample model contains all the broadcast event signals under the package Example Model.EA 15 Examples.Dynamic Model Based Add-Ins.Broadcast Types

Mandatory Signals or Events for Add-in

  • EA_Connect
  • EA_GetMenuItems
  • EA_MenuClick

All the available event references examples can be found here:

https://www.sparxsystems.com/enterprise_architect_user_guide/15.0/automation/broadcastevents.html

To Create an JavaScript Add-In

  1. Create a Signal Reference Library referring EAExample model. (Simple way would be just do an XMI export of the Broadcast Types package from EA model and import into your working model).
  2. Create a package in the root node for modelling the add-in

  1. Create a class object with stereotype JavascriptAddin ( this stereotyped element can be found in Model Add-Ins tool box as shown below

  1. The name of the above defined will be used in the JavaScript code. In our case it will be “Javascript Addin”
  2. Add the signal reference in the created class using the reception.
    • To Access Reception Right-click on the Class element and select the ‘Features | Receptions’ option. The Features window displays, at the ‘Receptions’ page.
    • Add the required events by clicking the button to the right of the New Receptiontext in the ‘Name’ column , the dialog will show the available Signals ( it will automatically fetch the parameters details from the object )

  • Once selected all the added signals will be displayed in the class object.

  1. After adding these events, it time to play with some JavaScript codes.
  2. Please open the behavior window (Develop > Source Code > Behavior) make sure the created class object “Javascript Addin” has been selected. It will show all the added events to which we need to add the code

  1. Codes for these events are similar to the traditional add-ins ( please refer the attached model for more details )
  1. Finally make sure the add-in is enabled. To enable the add-in Specialize -> Manage-Addin and please click Load on startup

  1. Once the add-in is loaded you can find it in the ribbon

Note:

For more details or customization please contact info@sparxsystems.in

Leave a Comment

*