Base class for given element

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Base class for given element

Postby urs.gulba@schulz-soluware.com » Sat Feb 10, 2018 5:42 am

Hi all,

for a dynamic legend I need to differentiate beween ports, parts and classes (with their specific stereotypes).

I need something like this:

if(elt.xxx()=="Port")
...
}

or a similar static method xxx(elt)=="Port"

Actually I thought this should be easy but either it is not or I am making a silly mistake.

Can anybody help ?

Thx in advance
Urs
urs.gulba@schulz-soluware.com
Forum Newbie
Forum Newbie
 
Posts: 10
Posts Rating:0
Joined: Tue Jan 24, 2017 6:47 am

Re: Base class for given element

Postby ieva.n » Mon Feb 12, 2018 8:56 am

Hello,

Just to clarify: you want to create dynamic legend in some kind plugin via code, or you simply do not know how to form the query for dynamic legend?

Sincerely,
No Magic, Inc. Customer Support
ieva.n
No Magic
No Magic
 
Posts: 299
Posts Rating:22
Joined: Thu Aug 02, 2012 5:02 am
Full name: Ieva

Re: Base class for given element

Postby urs.gulba@schulz-soluware.com » Mon Feb 12, 2018 9:02 am

The dynamic legend is not the problem. It works already with some groovy code.
What I want to do is to handle blocks and parts differently (the parts get the color depending on the typed block...). Basically this is also working.
The only thing that is missing is some expression with which I can differentiate a block (class is enough) from a part or port:

if(elt.xxx()="Class"){
...
}

I think it is not a legend specific issue, it is quite general.

Thx in advance
urs.gulba@schulz-soluware.com
Forum Newbie
Forum Newbie
 
Posts: 10
Posts Rating:0
Joined: Tue Jan 24, 2017 6:47 am

Re: Base class for given element

Postby ieva.n » Mon Feb 12, 2018 9:35 am

Hello,

The question was if you create the legend programatically from code or are writing a script directly in the legend from application. If you are using it from application, you can set element type recognition directly from "Elements by Condition" dialog and make a nested criteria with both your script and other criteria.

Sincerely,
No Magic, Inc. Customer Support
ieva.n
No Magic
No Magic
 
Posts: 299
Posts Rating:22
Joined: Thu Aug 02, 2012 5:02 am
Full name: Ieva

Re: Base class for given element

Postby urs.gulba@schulz-soluware.com » Mon Feb 12, 2018 9:39 am

Yes, I have seen that possibility but in this case I would like to differentiate in the code.
urs.gulba@schulz-soluware.com
Forum Newbie
Forum Newbie
 
Posts: 10
Posts Rating:0
Joined: Tue Jan 24, 2017 6:47 am

Re: Base class for given element

Postby mindaugas.genutis » Tue Feb 13, 2018 2:31 am

Dear Urs,

You should check if the given element (elt) is of Port, Property (part) or Class (block) instance. Exact qualified name of these types is:

Code: Select all
com.nomagic.uml2.ext.magicdraw.compositestructures.mdports.Port
com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Property
com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Class


In Java you would check that with instance of keyword:

Code: Select all
if (elt instanceof com.nomagic.uml2.ext.magicdraw.compositestructures.mdports.Port)
{

}


Groovy also has analogous instanceof checking, you should employ the Groovy way of doing the same.

Yours Sincerely,

-- Mindaugas Genutis
User avatar
mindaugas.genutis
Customer Support
Customer Support
 
Posts: 484
Posts Rating:30
Joined: Thu Feb 04, 2010 1:57 am
Location: Kaunas

Re: Base class for given element

Postby urs.gulba@schulz-soluware.com » Tue Feb 13, 2018 2:49 am

Hi Mindaugas,

thanks a lot, it worked. It was like I feared - surprisingly simple ;-)
You helped me a lot.

Best wishes
Urs
urs.gulba@schulz-soluware.com
Forum Newbie
Forum Newbie
 
Posts: 10
Posts Rating:0
Joined: Tue Jan 24, 2017 6:47 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: Google [Bot] and 0 guests