archimatetool / archi-scripting-plugin

jArchi - Scripting for Archi: ArchiMate Modelling Tool
https://www.archimatetool.com
118 stars 33 forks source link

Feature request: event handlers for jArchi #119

Closed gxpcluster closed 5 months ago

gxpcluster commented 1 year ago

How hard is it to add event handlers to Archi and jArchi? It would be great to have such a feature at least for basic events: changing the concept on the diagram, opening the model, closing the model, changing the diagram... As far as I understand it, this could be done as follows:

  1. Archi checks if the jArchi plugin is installed
  2. When an event occurs, Archi checks if there are handlers for that event in some jArchi script and executes the handler.
  3. When creating the plugin, the developer must register the event handler so that Archi stores it and knows about it and which script it is in.

Thanks!

Phillipus commented 1 year ago

Archi already has an event handler - the Eclipse Modelling Framework (EMF) eCore framework. Every model change sends an event that is handled by the UI or another handler. This can be used in Archi plug-ins...if the plug-in is well-behaved and properly places any changes to the model on the Undo/Redo stack.

jArchi is a wrapper around Archi's commands and implements things so that it is well behaved and creates proper Undo/Redo command stack events. If this was exposed to downstream scripts the resulting behaviour would be unpredictable.

So, the short answer is, I won't be implementing this in jArchi because of the reasons above and, even if it were possible, would take a lot of time and effort. But thanks for the idea!

gxpcluster commented 1 year ago

Thank you @Phillipus. I have situations where it would be very convenient to have a script triggered by certain user actions. For example, when a user adds a new concept to a diagram or changes an existing concept, I need to record in a text file what happened - the ID of the added or changed concept. So far, I haven't figured out how to do this without running the script manually. Unfortunately, I'm not good at Java to write a separate plugin. Thanks for explaining how events work in Archi.