Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: gervais.b on November 02, 2016, 06:31:27 pm

Title: Java API, react to change on diagram
Post by: gervais.b on November 02, 2016, 06:31:27 pm
Hi there,

I have a Java app that use the Java API Bridge to query our enterprises repository. I would like to have this app, running as standalone, notified when an user changes something in a diagram.
Ideally I would like to warn the user about the consequence of his changes and trigger a long running process on my Java app if he confirm.

The first idea would be to create one add-in that would listen for changes and call a REST service when the user agree. But I have no idea on how to listen for changes on one specific diagram.
Title: Re: Java API, react to change on diagram
Post by: Geert Bellekens on November 02, 2016, 07:13:48 pm
You have to use an add-in in order to be able to react to events in EA.

Unfortunately you cannot write add-ins in Java, only .Net

Geert
Title: Re: Java API, react to change on diagram
Post by: qwerty on November 02, 2016, 08:24:36 pm
A simple reason for the need of an add-in is that diagram changes are made local to a user in memory. Only when a save is issued, data are written to the database.

q.
Title: Re: Java API, react to change on diagram
Post by: gervais.b on November 02, 2016, 08:44:15 pm
Only when a save is issued, data are written to the database.

Then ideally I would like to react "on_pre_save"

Unfortunately you cannot write add-ins in Java, only .Net
Thanks, that's a minor problem.
Title: Re: Java API, react to change on diagram
Post by: qwerty on November 02, 2016, 11:06:10 pm
There's only EA_OnPostCloseDiagram (see http://www.sparxsystems.com/enterprise_architect_user_guide/13.0/automation/broadcastevents.html (http://www.sparxsystems.com/enterprise_architect_user_guide/13.0/automation/broadcastevents.html)

q.

P.S. Don't forget to check out Geert's blog about writing an add-in.
Title: Re: Java API, react to change on diagram
Post by: gervais.b on November 02, 2016, 11:50:26 pm
Because the idea would be to react when the user move or add one Component to a Node into a deployment diagram. Is it other/cleaner solutions than listening for EA_OnPostCloseDiagram event or polling the Diagram.ModifiedDate ?
Title: Re: Java API, react to change on diagram
Post by: qwerty on November 03, 2016, 06:13:29 am
You could either subscribe to EA_OnPostNewDiagramObject (added something to a diagram) and/or EA_OnPostNewElement (any entirely new element).

q.
Title: Re: Java API, react to change on diagram
Post by: Geert Bellekens on November 03, 2016, 07:27:36 pm
It seems like you should be checking the actual connection between the node and the component, not the location on the diagram.
You can do that by subscribing to the context events, checking the relation between the node and the component when it gets selected, and when something else gets selected.

The articles qwerty was referring too can be found here: http://bellekens.com/writing-ea-add-ins/

Geert