Book a Demo

Author Topic: EA_OnPreNewElement - where is the element name?  (Read 3769 times)

Maymone D.

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
EA_OnPreNewElement - where is the element name?
« on: March 30, 2009, 04:39:19 pm »
Hello,
I am writing some validation rules that will be applied for the class/use case properties. I did not find how to retrieve the name of the element being added/saved during the  OnPreNewElement event.
Only the id, type and stereotype are published by EA.
Any idea?
Thanks

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: EA_OnPreNewElement - where is the element name
« Reply #1 on: March 30, 2009, 04:46:07 pm »
At the time EA_OnPreNewElement is called, the element doesn't have a name yet. EA_OnPreNewElement should be used for making "should I allow it to be created or not?" type decisions. Have a look at EA_OnPostNewElement instead which works better for "It's created, how do I make sure it's valid?" type decisions.
The Sparx Team
[email protected]

Maymone D.

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: EA_OnPreNewElement - where is the element name
« Reply #2 on: March 31, 2009, 03:08:26 am »
Thank you,
But how do I make it invalid in the EA_OnPostNewElement? I do not want that the element be saved if it is invalid.

Manfred Kröpfli

  • EA User
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: EA_OnPreNewElement - where is the element name
« Reply #3 on: March 31, 2009, 07:57:12 pm »
2 approaches using EA_OnPostNewElement():
1) Give the user a short notice (MessageBox) that the element is invalid and delete it right away after the user hits the OK button.
2) use the EA model validation concept by encapsulating the validating business logic in a rule and publish the checkig result (e.g. "element is invalid due to naming violation") -> see Project.PublishResult(). As long as the naming violation persists, the element validation will display the error message (-> menu Project->Model Validation->Validate Selected)

Hope it helps
M.
« Last Edit: March 31, 2009, 07:57:41 pm by kroepfli »
Cheers
Manfred