Wednesday, 03 July 2019 04:00

Creating model based Javascript add-in with Enterprise Architect 15

Written by
Rate this item
(2 votes)

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 easily added in a model by just creating with a valid stereotyped classes.

Assuming having basic knowledge with Sparx Traditional add-ins, broadcast events and JavaScript.

Why model based add-ins

    • Accessed by all the users within 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 similar to traditional add-ins. 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 events references 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

    1. Create a class object with stereotype JavascriptAddin ( this stereotyped element can be found in Model Add-Ins tool box as shown below
      2
    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.
        2.1
      • 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 )
        3
    • Once selected all the added signals will be displayed in the class object.
      4
    1. After adding these events, its 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
      5
    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
      6
    1. Once the add-in is loaded you can find it in the ribbon
      7

    Note:

    For more details or customization please contact This email address is being protected from spambots. You need JavaScript enabled to view it.

Read 8079 times Last modified on Monday, 08 July 2019 05:52
Arshad Ahamed

Working as a consultant with a software development background in Sparx Systems India. Has assisted and worked with several teams to roll out their Architecture modeling practices, migration of their solution As-Is and To-Be view into Sparx Enterprise Architect from various enterprise tools.

Arshad is an expert in Customizing, Extending, and Integrating  Enterprise Architect with other software applications like Visio, MS office suite, service now, Jira, etc. 

Highly proficient in scripting (VBScript, Jscript) for Automation inside Enterprise Architect, Creating UML profiles, Creating document generation templates and custom MDG technologies based on client requirements.

Expert in developing custom addin for enterprise architect based on client requirements. 

For more articles and blogs refer to Sparx Systems India Blogs  |  Arshad 

 

https://www.linkedin.com/in/arshad-ahamed-1a836057/

3 comments

  • Comment Link yu2018 Friday, 08 January 2021 17:34 posted by yu2018

    Thanks for your introduction of Model Based Add-ins.

    After success with your example, I meet problem when write a new one.

    Is it possible to include existed Javascript in Model Based Add-ins Javascript?
    When !INC statement in the script, EA report errors and disable whole Model Based Add-ins.

    At first a stub in EA_MenuClick:
    if(ItemName == "About") {
    this.CalculateSum(Repository);
    }
    Then the function CalculateSum creaded as Add-ins Operation
    !INC Local Scripts.EAConstants-JScript [!!!! unexpected token: identifier]
    Session.prompt("This is a demo for "+String(otElement),4);

    When the project reload, the addin is not actived. The error message as following:
    1: function DemoAddin(){
    2: }
    3: DemoAddin.prototype.CalculateSum = function() {
    4: !INC Local Scripts.EAConstants-JScript [!!!! unexpected token: identifier]
    5: Session.prompt("This is a demo for "+String(otElement),4);

    The same statement is running OK as normal Javascript.

    Thanks.

  • Comment Link Arshad Ahamed Sunday, 07 June 2020 13:03 posted by Arshad Ahamed

    @philchudley Apologies for the late reply.

    Yes, at the moment its a bug (Version EA 15.1.1528)
    If you add more than one tab you can see the Tab names getting reflected in the window :D .

  • Comment Link philchudley Monday, 05 August 2019 11:57 posted by philchudley

    Nice intro and I have downloaded the example and am having a look at the code

    I do have a couple of questions:

    In the reception named EA_OnContextItemChanged I notice a couple of Repository class methods

    GetPropertiesTab
    SetPropertiesXML
    AddPropertiesTab

    I understand what these methods do, but they are not in the EA User Guide documentation, so I assume they are new methods and the documentation has not yet been updated.

    However, I noticed that the parameter value for these methods is this.tab1Name so I would expect the value of this attribute to be used as the name of the Properties tab, but the name of the properties tab is always Add-ins. I have tried changing the default value of the attribute and even used a Text literal value as the parameter, but the Properties tab name is always Add-Ins

    Is this the intended behaviour, a bug or am I missing something?

    Phil

Login to post comments