Author Topic: Importing JS libraries in Model Addins  (Read 11626 times)

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1313
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Importing JS libraries in Model Addins
« on: February 10, 2024, 02:48:55 am »
Hi,

I'm trying to understand how to import/include external librairies in a Javascript Model Addin based on the MyDemoAddin example in EAExample project.
It call calls objects defined in "Utilities" EA classes e.g. JSxml. In the TestXML method, the following line creates an object: var doc = new JSxml();

How does the MyDemoAddin know the other Utilities classes? I can't test the above method as it doesn't seem to be called from an addin menu. I wonder if it's simply managed with the dependency links to the Utilities classes.

Opening the JSxml class code (right click > Features > Edit Internal Code), I can see an "Imports" item in the tree structure before the list of methods. The class seems to include an external library but I can't figure how this is achieve.




Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7983
  • Karma: +114/-20
    • View Profile
Re: Importing JS libraries in Model Addins
« Reply #1 on: February 12, 2024, 08:22:00 am »
A UML Dependency connector.

Elpis

  • EA Novice
  • *
  • Posts: 18
  • Karma: +4/-0
    • View Profile
Re: Importing JS libraries in Model Addins
« Reply #2 on: February 16, 2024, 08:53:22 pm »
By chance ;-) , Eve's reply seems to answer my other question https://sparxsystems.com/forums/smf/index.php/topic,48243.0.html

Elpis

  • EA Novice
  • *
  • Posts: 18
  • Karma: +4/-0
    • View Profile
Re: Importing JS libraries in Model Addins
« Reply #3 on: February 16, 2024, 09:22:57 pm »
Opening the JSxml class code (right click > Features > Edit Internal Code), I can see an "Imports" item in the tree structure before the list of methods. The class seems to include an external library but I can't figure how this is achieve.

I can see initial value set for document attribute of JSxml:
Code: [Select]
new COMObject("Msxml2.DOMDocument.4.0")(I guess, COM interfacing library is predefined in EA script engine)

Still, I don't know what purpose of Import section (of internal code) is and what can be placed there. The section seems to appear automaticaly in any ordinary Class's internal code - but not in <<JavascriptAddin>> stereotyped one  ???

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 7983
  • Karma: +114/-20
    • View Profile
Re: Importing JS libraries in Model Addins
« Reply #4 on: February 19, 2024, 10:34:37 am »
Still, I don't know what purpose of Import section (of internal code) is and what can be placed there. The section seems to appear automaticaly in any ordinary Class's internal code - but not in <<JavascriptAddin>> stereotyped one  ???
Imports is a field in the database that used (language dependent) to add imports associated with that class to the code generation of a new file. It's showing because you likely have the default language set to Java and it's used for Java generation. It's not used for Javascript add-ins, so it's not shown.

Elpis

  • EA Novice
  • *
  • Posts: 18
  • Karma: +4/-0
    • View Profile
Re: Importing JS libraries in Model Addins
« Reply #5 on: February 28, 2024, 02:31:51 am »
Imports is a field in the database that used (language dependent) to add imports associated with that class to the code generation of a new file. It's showing because you likely have the default language set to Java and it's used for Java generation. It's not used for Javascript add-ins, so it's not shown.

Yes, indeed, I have default language set to Java. And setting an element's (ordinary Class) Language property to something else (e.g. Javascript) have no impact on that EA behavior.