Book a Demo

Author Topic: Using collection.addNew() with stereotypes  (Read 8298 times)

Hermes

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Using collection.addNew() with stereotypes
« on: November 10, 2009, 06:19:15 am »
Dear All,

I'm able to create a new element (ie: a connector)
but I don't know how to create a stereotyped element with ALL its features.

For example, by only setting the desidered sterotype with:
Code: [Select]
conn.Stereotype = "MyStereotype" makes only the field stereotype to be as wanted.

But, if this stereotype is defined with a set of attributes,
this set will not be included in the new element, as normally happens by EA user interface, and as I want to be.

How can I fix this?
(considering that I'd like to make it works for any feature from any stereotype).

Thank you all.

/D
« Last Edit: November 10, 2009, 06:20:21 am by hermes »

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #1 on: November 10, 2009, 07:07:25 am »
Hi,

You could try the other way round. Create an appropriate stereotype for your element/association in a Profile, and react on changes the users apply on elements(associations  of this stereotype. There are numerous events that can be captured by the AddIn to achieve this. In the profiled stereotype definition you can also predefine some element/association intrinsic values, e.g. how your stereotypes should be rendered. This technique should also work for elements/associations where the user decides to set the stereotype afterwards.
One of the powers of profiled stereotypes is also that you're able to define custom tagged values there. These can be used to carry all the additional information you'll need in your stereotyped elements/associations. You're doing s.th. about requirements modelling, right? This seems to be likely to need such additional informations, IMHO. You can use the tagged values to steer your AddIn event handlers, or to change rendering, using the shape-script engine.

I'm not sure if it was you, recently asking on the forum about the need for MDG AddIns or not. As far I have understood it, these are necessary, if you need to handle code language engineering.

Here's some more information about profile development:
http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/umlprofiles_2.html

and the relevant AddIn events:
http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/broadcastevents.html

HTH
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #2 on: November 10, 2009, 07:37:24 am »
Hi again,

Sorry, I didn't read thoroughly enough. So I guess, you have this setup already, and just want to know how to set the stereotype programmatically, using the EA AddIn SDK.
As far I remember, I've developed some code, to create/synch all necessary tagged values explicitely. Just setting the stereotype field and update didn't work here, as you mentioned.
I even asked the same question here more or less :P, but not all of the hints worked for me:
http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1238534229/0#0

HTH
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #3 on: November 10, 2009, 10:23:26 am »
The answer is buried deep in one of the links that Günther gave you:
Code: [Select]
Repository.CustomCommand("Repository", "SynchProfile", "Profile=PPP;Stereotype=SSS;");
What this will do is search for all elements in the database with the stereotype «SSS» from profile "PPP" and bring their list of tagged values up-to-date. So if you are adding several stereotyped elements, just run this command once at the end.
« Last Edit: November 10, 2009, 10:24:42 am by KP »
The Sparx Team
[email protected]

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #4 on: November 10, 2009, 10:32:46 am »
Hi KP,

Quote
The answer is buried deep in one of the links that Günther gave you:
Code: [Select]
Repository.CustomCommand("Repository", "SynchProfile", "Profile=PPP;Stereotype=SSS;");
What this will do is search for all elements in the database with the stereotype «SSS» from profile "PPP" and bring their list of tagged values up-to-date. So if you are adding several stereotyped elements, just run this command once at the end.
As far I remember this was the thingey I didn't get to work. I've tried various versions for PPP and SSS, with full stereotype namespace, without, etc. But maybe I've just missed something. At least I ended up implementing the mentioned synch code, and that worked well.

WBR
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #5 on: November 10, 2009, 10:58:46 am »
Quote
As far I remember this was the thingey I didn't get to work. I've tried various versions for PPP and SSS, with full stereotype namespace, without, etc. But maybe I've just missed something. At least I ended up implementing the mentioned synch code, and that worked well.

WBR
Günther
If you were taking it from this post it is missing a semi-colon after the stereotype. Maybe that was the problem?
The Sparx Team
[email protected]

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #6 on: November 10, 2009, 12:02:19 pm »
Yup, that was it! The code's still active in my EventHandlerBase class:
Code: [Select]
string syncParams = string.Format("Profile=Protobuf;[highlight]Stereotype={0}[/highlight]", stereotype);
Repository.CustomCommand("Repository", "SynchProfile", syncParams);
Could be I've been missing your hint then.

THX
Günther

Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

Hermes

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #7 on: November 10, 2009, 11:33:12 pm »
first of all, thank you all for your valued suggestions  :)

Then...

I've tried to add this lines AFTER updating the new connection and refreshing its collection.

Code: [Select]
syncParams="Profile=MY[highlight] [/highlight]Requirement[highlight] [/highlight]Profile;Stereotype=MYLink;";
string res = rep.CustomCommand("Repository", "SynchProfile", syncParams);

Then I've tried to run this code, but it does not work :(
If may help, rep.CustomCommand() returns "true" and, as I have highlighted, my profile name contains spaces.

Do I forget something?

/D

Hermes

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #8 on: November 13, 2009, 02:40:00 am »
I'm Yet Stucked on this issue.

I've tried to remove spaces from my profile name and running this code:

Code: [Select]
EA.Connector newconn = (EA.Connector)this.link_from.Connectors.AddNew("", "Dependency");
newconn.SupplierID = link_to.ElementID;
newconn.Stereotype = [highlight]"trace"[/highlight];
newconn.StereotypeEx = [highlight]"trace,MyTraceLink"[/highlight];

newconn.Update();
this.link_from.Connectors.Refresh();

string syncParams = string.Format("Profile={0};Stereotype={1};", "MyProfile", "trace,MyTraceLink");          
string res = rep.CustomCommand("Repository", "SynchProfile", syncParams);

But I still cant get it works.  :(

Actually things got worse because I have another UML profiling issue:
( http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1257960198 )

[highlight]NOTE [/highlight]that the stereotype form "trace,MyTrace" derives from an Issue explained in that post.


So Actually I cant sync anythig, even if I use the EA interface.

Moreover I've tried to add tags manually, but I've no idea how to match created TaggedValues behaviour with the same defined in my profile.

Any Idea/suggestion? :)
Thanks
/D


« Last Edit: November 13, 2009, 02:43:03 am by hermes »

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #9 on: November 13, 2009, 02:50:36 am »
Hi,

When I said 'Yup, that was it', I didn't test if this fix changes any behavior of my AddIn, to be honest. I have my synch code for tagged values in there anyway.
So I can't confirm that KP's suggestion works ... Would have to test it again, and I'm currently in the very middle of completely different stuff.

Just to let you know,

Günther

Hermes

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #10 on: November 13, 2009, 03:04:12 am »
Ok Günther,

Can I ask you How did you faced TaggedValue Behaviour from Stereotype definition?

for example:
if I have defined in my profile a Tag with an associated set of possible values (user selectable by a combobox),
how can I include this behaviour in a tag AdHoc created by my code?

Thanks,
/D

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #11 on: November 13, 2009, 08:27:28 am »
Hi,

In principle I have always reasonable default values for all the stereotype specific tagged values. These can be assigned either an initial default or a calculated value from the context (I have to provide e.g. tag numbers := unique ids for attributes appearing inside an element).
Definitions for the tagged values' defaults are also defined in the associated UML-profile. The synch routine(s) also ensure consistency of tagged values changed by the user from the UI with UML intrinsic definitions (e.g. multiplicity of an attribute).
The code, even if reduced to an excerpt is too complex to be posted here, IMHO.

If you leave an eMail adress in my message box, I can send you the AddIn code and related profile database. I didn't put a licencse on it, just note the copyright please.

Quote
Would have to test it again, and I'm currently in the very middle of completely different stuff.
Funny enough, some not too long time from when I wrote this, a collegue came over, and asked me to get an installation tomorrow. So I anyway had to go back on it again now. There are still some issues and bugs to fix.

HTH
Günther

Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

Hermes

  • EA User
  • **
  • Posts: 41
  • Karma: +0/-0
    • View Profile
Re: Using collection.addNew() with stereotypes
« Reply #12 on: November 13, 2009, 10:34:53 pm »
dear Günther,
I've sent you a private message.

Quote
There are still some issues and bugs to fix.

Of course if I find out how to make it works right, i will post my solution :)

/D