Obtain PresentationElements from Diagram

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Obtain PresentationElements from Diagram

Postby Raul Lorenzo » Tue Apr 04, 2006 1:06 pm

Hello,

I am trying to get a list of all PresentationElements in a Diagram, to
do an operation with the elements represent by the diagram.
I use this code:

for (Iterator it =
PlugInREM_Logic.getInstance().getProject().getDiagram(diagrama).getPresentationElements().iterator();
it.hasNext();)
{
pe=(PresentationElement)it; <------Crash Here
elemento=pe.getElement();
}

this crashes with java.lang.Exception: java.lang.ClassCastException:
java.util.AbstractList$Itr why?

Thanks in advance
Raul Lorenzo
 
Posts Rating:

Re: Obtain PresentationElements from Diagram

Postby Tomas Pugzlys » Wed Apr 05, 2006 12:23 am

Hello,

The crash line should be changed to the following:
pe=(PresentationElement)it.next();


Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363- IV, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple

nntp://news.nomagic.com/nomagic.products.magicdrawuml.openapi wrote:
> Hello,
>
> I am trying to get a list of all PresentationElements in a Diagram, to
> do an operation with the elements represent by the diagram.
> I use this code:
>
> for (Iterator it =
> PlugInREM_Logic.getInstance().getProject().getDiagram(diagrama).getPresentationElements().iterator();
> it.hasNext();)
> {
> pe=(PresentationElement)it; <------Crash Here
> elemento=pe.getElement();
> }
>
> this crashes with java.lang.Exception: java.lang.ClassCastException:
> java.util.AbstractList$Itr why?
>
> Thanks in advance
>

Tomas Pugzlys
 
Posts Rating:

Re: Obtain PresentationElements from Diagram and removing some of them

Postby Raul Lorenzo » Wed Apr 05, 2006 3:42 am

Opss, how did I forget that!!!!

Ok, but when I try this code, obtaining the presentation elements for
deleting some of them, if flow goes to leaf then the execution stops
without any exception. It´s extrange, it should continue procesing other
elements from pes.iterator().
Any Idea?

Collection
pes=PlugInREM_Logic.getInstance().getProject().getDiagram(diagrama).getPresentationElements();
for (Iterator it = pes.iterator(); it.hasNext();)
{
pe=(PresentationElement)it.next();
elemento=pe.getElement();
shown=PlugInREM_Logic.getInstance().getModel_Logic().GetValueStereoType_Elemento(elemento,"databaseEntity",
"shown");
if (shown.compareTo("[true]")==0)
{
StereotypesHelper.clearStereotypeProperty(elemento,"databaseEntity","shown",true);
}
else
{
PresentationElementsManager.getInstance().deletePresentationElement(pe);
}
}

Tomas Pugzlys escribió:
> Hello,
>
> The crash line should be changed to the following:
> pe=(PresentationElement)it.next();
>
>
> Regards,
Raul Lorenzo
 
Posts Rating:

Re: Obtain PresentationElements from Diagram and removing some of them

Postby Raul Lorenzo » Wed Apr 05, 2006 3:44 am

I mean if flow goes to false leaf then stops when call
PresentationElementsManager.getInstance().deletePresentationElement(pe);

Tomas Pugzlys escribió:
> Hello,
>
> The crash line should be changed to the following:
> pe=(PresentationElement)it.next();
>
>
> Regards,
Raul Lorenzo
 
Posts Rating:

Re: Obtain PresentationElements from Diagram and removing some of them

Postby Tomas Pugzlys » Thu Apr 06, 2006 3:59 am

Hello,

I was enable to reproduce your problem.
I need more details to reproduce it.

I had tried the following code with several diagrams
and it worked in all cases:

DiagramPresentationElement dpe = ...;
List presentationElements = dpe.getPresentationElements();
SessionManager.getInstance().createSession("");
for (int i = 0; i < presentationElements.size(); i++)
{
PresentationElement pe = (PresentationElement) presentationElements.get(i);
try
{
PresentationElementsManager.getInstance().deletePresentationElement(pe);
}
catch (ReadOnlyElementException e)
{
e.printStackTrace();
}
}
SessionManager.getInstance().closeSession();

> if flow goes to leaf then the execution stops
> without any exception.
By saying "execution stops" you mean that
MagicDraw hangs on deletePresentationElement(pe) method
and you need to restart MagicDraw?

For me it would be interesting to know presentation element class:
pe.getClass().getName();

Regards,
--
Tomas Pugzlys
Programmer
No Magic Lithuanian Development Center
Savanoriu pr. 363- IV, LT-49425, Kaunas
P.O. box 2166, LT-44011, Kaunas
Phone: +370 37 324032 Fax: +370 37 320670
e-mail : tomasp
WWW: http://www.magicdraw.com
--
MagicDraw - UML Made Simple

nntp://news.nomagic.com/nomagic.products.magicdrawuml.openapi wrote:
> Opss, how did I forget that!!!!
>
> Ok, but when I try this code, obtaining the presentation elements for
> deleting some of them, if flow goes to leaf then the execution stops
> without any exception. It´s extrange, it should continue procesing other
> elements from pes.iterator().
> Any Idea?
>
> Collection
> pes=PlugInREM_Logic.getInstance().getProject().getDiagram(diagrama).getPresentationElements();
> for (Iterator it = pes.iterator(); it.hasNext();)
> {
> pe=(PresentationElement)it.next();
> elemento=pe.getElement();
> shown=PlugInREM_Logic.getInstance().getModel_Logic().GetValueStereoType_Elemento(elemento,"databaseEntity",
> "shown");
> if (shown.compareTo("[true]")==0)
> {
> StereotypesHelper.clearStereotypeProperty(elemento,"databaseEntity","shown",true);
> }
> else
> {
> PresentationElementsManager.getInstance().deletePresentationElement(pe);
> }
> }
>
> Tomas Pugzlys escribió:
>> Hello,
>>
>> The crash line should be changed to the following:
>> pe=(PresentationElement)it.next();
>>
>>
>> Regards,
>

Tomas Pugzlys
 
Posts Rating:

Re: Obtain PresentationElements from Diagram and removing some of them

Postby Raul Lorenzo » Thu Apr 06, 2006 8:12 am

Hello,

I note you open a session, this could be the problem.
I will try this piece of code.

>
>> if flow goes to leaf then the execution stops
>> without any exception.
> By saying "execution stops" you mean that
> MagicDraw hangs on deletePresentationElement(pe) method
> and you need to restart MagicDraw?
No, MagicDraw continue running well, I mean that normal plugin flow
stops running (it does´t continue to next line in code).
>
> For me it would be interesting to know presentation element class:
> pe.getClass().getName();
com.nomagic.magicdraw.uml.symbols.shapes.UseCaseView
Raul Lorenzo
 
Posts Rating:


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 2 guests

cron