Author Topic: EA_OnPostNewElement / EA_OnPreNewElement  (Read 3378 times)

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
EA_OnPostNewElement / EA_OnPreNewElement
« on: October 07, 2007, 11:13:41 am »
I'm trying to write an add-in to detect when a user creates a duplicate element (ie. same stereotype / type and name).

There are 2 ways a user can create an element - drag/drop from the toolbox onto a diagram or adding to a package via the project browser.

I can use the EA_OnPreNewElement event from the project browser as that fires after the prompt for the new element name.  I can check for a duplicate, prompt the user and cancel and the element is not created.

Problem is when an element is created via the toolbox - drag & drop to a diagram.  In this case, the "Pre" event is created before the element is created - but this is no use as it uses EA default element name.  The "Post" even then fires, and then the dialog is displayed to the user to get the element name.  No further events fire.

I need to be able to either prevent the creation of a duplicate element via the toolbox - or do a retrospective delete on the duplicate.  Problem is - no further events fire that I can capture / use (short of a workaround like posting an asynchronous call or monitoring windows level messages...)

Any ideas?  Or could this be a feature request to Sparx to implement the event calling order consistently between the two ways of adding the element (especially the post event - which happens in one case (projetc browser) after the dialog to edit element details, and in the other case before)(toolbox drag / drop).

Thanks,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
EA_OnPostNewElement / EA_OnPreNewElement
« Reply #1 on: October 18, 2007, 05:51:12 pm »
Has anyone got any ideas to help me here please?

What I need is a consistent way of detecting the addition of a duplicate element, and prevent (or delete post creation).

Thanks,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: EA_OnPostNewElement / EA_OnPreNewElement
« Reply #2 on: October 18, 2007, 08:12:23 pm »
Quote
Has anyone got any ideas to help me here please?
Hi David,
I presume if you added the appropriate uniqueness constraint to the database, you'd get an exception that you'd be able to use to back out...

If you don't get the exception why don't you?

Paolo
[size=10]Using EA in spite of EA, NOT because of it![/size] TM[/color]

Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: EA_OnPostNewElement / EA_OnPreNewElement
« Reply #3 on: October 25, 2007, 01:08:42 pm »
Thanks Paolo,

I'll give it a try, however I think the DB error will be returned to EA (and not the add-in) which in most cases when you monkey with the EA database in ways EA doesn't expect, EA crashes (it uses a lot of "select *" in embedded SQL, rather than named columns in result sets - or even better, SPs).

Thanks,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"