Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Create graphic elements programmatically
Create graphic elements programmatically [message #1386567] Wed, 18 June 2014 09:33 Go to next message
Natalia B. is currently offline Natalia B.Friend
Messages: 2
Registered: May 2014
Junior Member
Hi,

I am newbie to papyrus and am trying to create models, diagrams, classes...programmatically.
I have been reading the forum and I got to create the model with this post: http://www.eclipse.org/forums/index.php/t/514308/ and created the diagram by means of commands.
My next step would be to create, for example a element (i.e. a class) graphically. I read the forum and the source code but I didn´t find anything that could help me.
The Developer Guide says something like I can use the UMLViewProvider of a specific diagram to create elements and for that I need to create a UML element first and then use the provider to create the associated view but I am not sure how to do that.

Can anyone help me with this problem? or tell me any other way to do that?

Thanks.
Re: Create graphic elements programmatically [message #1386776 is a reply to message #1386567] Fri, 20 June 2014 11:21 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi Natalia,

Currently, the simplest way for creating graphic elements is to use a DropObjectRequest, which provides the same behavior you'd have when dropping objects from the Model Explorer to a specific diagram. The diagram will take care of converting this DropRequest to a set of commands to create the diagram elements.

You can find an example of DropObjectsRequests being used for generating diagrams programatically in this class:

https://git.eclipse.org/c/papyrus/org.eclipse.papyrus.git/tree/extraplugins/diagramtemplate/org.eclipse.papyrus.diagramtemplate.editor/src/org/eclipse/papyrus/diagramtemplate/launcher/DiagramTemplateLauncher.java

Have a look at this method:

protected EditPart showElementIn(EObject elementToShow, DiagramEditor activeEditor, EditPart editPart, int position)

Regards,
Camille


Camille Letavernier
Re: Create graphic elements programmatically [message #1400526 is a reply to message #1386567] Mon, 14 July 2014 10:23 Go to previous messageGo to next message
Natalia B. is currently offline Natalia B.Friend
Messages: 2
Registered: May 2014
Junior Member
Thanks a lot for your reply.

I created a simple example in my diagram with 2 classes linked by an association and each class with one attribute. I was be able to draw the classes and association using DropObjectRequest but not the attributes inside the classes, but I can see them in the model explorer.

What did I miss? Do I have to do something special for elements inside the classes (attributes, operations)?

Thanks in advance.
Re: Create graphic elements programmatically [message #1400588 is a reply to message #1400526] Mon, 14 July 2014 12:29 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Natalia,

Are you looking for the same result as a drag-and-drop operation with
the Control modifier key (on Windows; on Mac it's the Option key)? If
so, then I think you just need to add the value of DND.DROP_COPY to the
drop request's extended data. Something like

request.getExtendedData().put("EVENT_DETAIL", DND.DROP_COPY);

The "EVENT_DETAIL" string is available as a constant in the
CustomizableDropEditPolicy class, but I don't know whether that's a
supported public API.

HTH,

Christian


On 2014-07-14 10:23:00 +0000, Natalia B. said:

> Thanks a lot for your reply.
>
> I created a simple example in my diagram with 2 classes linked by an
> association and each class with one attribute. I was be able to draw
> the classes and association using DropObjectRequest but not the
> attributes inside the classes, but I can see them in the model explorer.
>
> What did I miss? Do I have to do something special for elements inside
> the classes (attributes, operations)?
>
> Thanks in advance.
Re: Create graphic elements programmatically [message #1403553 is a reply to message #1400588] Thu, 24 July 2014 11:41 Go to previous messageGo to next message
Annette P is currently offline Annette PFriend
Messages: 2
Registered: July 2012
Junior Member
Hello,

I have a similar question.
I create statemachine diagrams programmatically using DropObjectRequests. This works fine for states but it does not work for transitions between states.
What do I have to do for creating a graphical representation of transitions?

Thanks in advance
Annette
Re: Create graphic elements programmatically [message #1412483 is a reply to message #1403553] Tue, 26 August 2014 09:20 Go to previous message
Kristian Kostadinov is currently offline Kristian KostadinovFriend
Messages: 1
Registered: August 2014
Junior Member
Hello,
How can I create Comment Links in the diagram?
I managed to create the Comments using DropObjectsRequests, but since the links don't have an element I doubt I could do it in the same way.

Cheers,
Kristian
Previous Topic:Project Explorer does not show projects
Next Topic:Performance issue related to forcing decorator updates in the Model Explorer
Goto Forum:
  


Current Time: Thu Apr 25 04:34:07 GMT 2024

Powered by FUDForum. Page generated in 0.03746 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top