Book a Demo

Author Topic: EA_OnNotifyContextItemModified (change of attribute)  (Read 6029 times)

Kristofer

  • EA User
  • **
  • Posts: 52
  • Karma: +0/-0
    • View Profile
EA_OnNotifyContextItemModified (change of attribute)
« on: April 13, 2016, 07:23:45 pm »
Hi!

I am trying to catch a change of an attribute, and sync the change with another attribute (connected via "Link to Element Feature"). I cannot however understand how OnNotifyContextItemModified works. So I have done some testing:

If I change an attribute from the Features dialog box, OnNotifyContextItemModified is fired when I click on the Close button (not when focus is changed to another attribute, which is when i was expecting the save to happen) and the type is otElement. Does this mean that I need to iterate all attributes on the element to make sure that they are syncronized?

I have also noticed that when I change the Note text from the Notes window (View -> Notes), OnNotifyContextItemModified is not fired at all. How can I make sure that the Note text is synced in that case?

Should I use OnContextItemChanged instead? But it seems to be unnecessary since I don't want to do anything if nothing is changed. So I thought that OnNotifyContextItemModified would be more suitable.

Thanks in advance!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: EA_OnNotifyContextItemModified (change of attribute)
« Reply #1 on: April 13, 2016, 07:48:13 pm »
Kristofer,

You should be using OnNotifyContextItemModified.
The fact that it doesn't fire when changing the notes is something I consider a bug that should be reported.

The annoying thing about this event is indeed that you get the element, and not the attribute that has changed.
So you'll have to first somehow record the state of all attributes of an element, and then compare that to the state of the attributes after the element has been modified.

I've done something similar (to keep track of changes in operations) in one of my example EA-Matic scripts: https://bellekens.com/2015/02/10/automatically-synchronize-overrides-in-enterprise-architect-with-ea-matic/

Geert

Kristofer

  • EA User
  • **
  • Posts: 52
  • Karma: +0/-0
    • View Profile
Re: EA_OnNotifyContextItemModified (change of attribute)
« Reply #2 on: April 13, 2016, 08:37:37 pm »
Ahh, that's how you do it. And when I think about it, it is problably a good idea anyway to record the state before the change, in case someone changes the target while the user is writing. Not likely to happen in our case, but why not be on the safe side.  :-)

I have also been thinking of running a script every night to do the syncing. Somehow it feels more reliable to not have to rely on events, but it also has its downsides.

EA-Matic seems interesting. It would make updating (once my add-in is deployed) the code easier if the users does not need to re-install my add-in.

Thanks for the information!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: EA_OnNotifyContextItemModified (change of attribute)
« Reply #3 on: April 13, 2016, 09:27:50 pm »
EA-Matic seems interesting. It would make updating (once my add-in is deployed) the code easier if the users does not need to re-install my add-in.

Yes, that was exactly the use case behind EA-Matic, to have the flexibility of scripts, but still be able to respond to events in EA.

Geert