Book a Demo

Author Topic: EA_OnPreNewElement - no ParentID/ParentID always 0  (Read 6876 times)

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
EA_OnPreNewElement - no ParentID/ParentID always 0
« on: January 15, 2010, 12:16:35 am »
Hi.
I am trying to write an addin which prevents the creation of Activities within Activities.
For this I need to know the ParentID of the new Elements(to make sure, that, should the new Element be an Activity, it's parent isn't one), which should be available via the EventProperties.
But for some reason the EventPropertie which should hold the ParentID is always zero :/

Did I missunderstand the Parent Property  or is there something wrong >.>?

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_OnPreNewElement - no ParentID/ParentID alwa
« Reply #1 on: January 15, 2010, 01:26:11 am »
Could it be that the parentID is only filled in after the event has been launched?

Geert

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: EA_OnPreNewElement - no ParentID/ParentID alwa
« Reply #2 on: January 22, 2010, 12:55:40 am »
What would be the point of the parameter then?
I mean it's a method which is called PRE-element-creation.

I "solved" the problem by deleting the element post-creation if it has a bad parent, but I am not happy with this workaround.

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_OnPreNewElement - no ParentID/ParentID alwa
« Reply #3 on: January 22, 2010, 01:20:23 am »
I don't know, EA works in misterious ways ::)

Geert

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: EA_OnPreNewElement - no ParentID/ParentID alwa
« Reply #4 on: January 31, 2010, 07:16:07 am »
If there is a developer or someone with deeper insight into EA, could you please verify that the EA_OnPrewNewElement Info.get("ParentID") is always 0?

A definite answer would be awesome because I can't get over the fact that I did a workaround. :/

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: EA_OnPreNewElement - no ParentID/ParentID alwa
« Reply #5 on: January 31, 2010, 10:49:04 am »
While I can't provide a definitive answer, nor have I used the particular event, I may be able to shed some light.

I guess you are trying to use this when you drag onto the diagram from the tool box.  Please say if not...

If the other values (Type, Stereotype, DiagramID) are correct, then I would suggest the following experiment:

See if creating an element from the Browser givens the same result.  (Select the parent Activity and use the context menu to create the child Activity).

If this scenario does set the Parent ID then I think I can explain what is happening...

Can you also confirm that you are "Dropping" the dragged activity on to an activity diagram corresponding to the parent activity?

If you can answer those questions, I may be able to suggest why you are seeing the behaviour you experience.  Hopefully, I may be able to suggest how you night be able use the information you ARE provided with to achieve your desired outcomes.

HTH,
Paolo

« Last Edit: January 31, 2010, 10:50:44 am by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: EA_OnPreNewElement - no ParentID/ParentID alwa
« Reply #6 on: February 06, 2010, 04:13:22 am »
Yes, I have been dragging the elements from the toolbox.

The event does not occur for already existing elements - it is not called when you drag an element from the treeview into the diagram.
However it is called when you create new elements by dragging an element from treeview to diagram and choose to create something different from a simple link.
In this case the parentID is once again zero.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: EA_OnPreNewElement - no ParentID/ParentID alwa
« Reply #7 on: February 06, 2010, 07:20:18 pm »
Sorry to keep asking questions, but the creating a different type of element from the browser is likely to generate a 0 Parent ID.

Also does creating a new activity under an existing element in the browser (using the context menu) trigger the event?

What happens to the Parent ID then?

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

MalkContent

  • EA User
  • **
  • Posts: 24
  • Karma: +0/-0
    • View Profile
Re: EA_OnPreNewElement - no ParentID/ParentID alwa
« Reply #8 on: February 06, 2010, 09:19:57 pm »
yes it triggers the event, yes the parentID is not zero

still - it's not very satisfying ^^
« Last Edit: February 06, 2010, 09:20:47 pm by MalkContent »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: EA_OnPreNewElement - no ParentID/ParentID alwa
« Reply #9 on: February 07, 2010, 01:02:05 pm »
Thanks for bearing with me...  Here's what I think is happening and why...  (Perhaps a helpful Sparxian would confirm/deny this).

The reason why the Parent ID is NOT zero in the last case (adding a nested element from a selected browser element by using the context menu - quite a mouthful no?) is that EA can work out easily which element is the parent - it is told by the browser!

In the other cases (dragging onto the diagram from the toolbox), EA can't directly work out the parent.  If you drag any element onto any diagram except an Activity Diagram, you don't expect the ParentID to be set.  This is because - apart from the special case of the Activity Diagram - diagrams are not directly mentioned in the UML specification.

However, in UML the Activity Diagram IS the Activity.  In other words, an Activity Diagram MUST represent the elaboration of the named Activity.  Notionally, there can only be one Activity Diagram per activity in the model and every Activity diagram must elaborate only one Activity.  Now, I don't know about you, but I - like, I suspect, most modellers - honour this requirement "more in the breach than the observance".  That is, we abuse this constraint - regularly.

However, from the point of view of this issue, this constraint may help you solve your problem.  EA uses the fact that you're adding the element to an Activity Diagram to determine the parent Activity and assign the parent Activity as the parent of the newly created element.

You should therefore be able to take the DiagramID (remember I initially asked you to check that the DiagramID was correct), check to see if it's an Activity Diagram, then check that the Diagram itself has a ParentID - which means it's an Activity Diagram under an Element (and not one created under a Package).  Check the Diagram's Parent Element to see if it it's an Activity and then make your decision...

HTH,
Paolo
« Last Edit: February 07, 2010, 01:04:08 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!