Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Creating diagram from modelset?
Creating diagram from modelset? [message #1712269] Thu, 22 October 2015 14:18 Go to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 195
Registered: January 2013
Location: Sweden
Senior Member
I've managed to create model set using the second snippet in this post.
However I have two questions.

First, how do get the various models from the modelset, i.e notation. di and uml? I guess I should use the getModel() method but what should the argument be?

Second, how can I create a diagram from the modelset. I don't want to use DragDropRequest as described here since I don't have and active editor open. and I want to do it without having one.

Regards
Patrik
Re: Creating diagram from modelset? [message #1712285 is a reply to message #1712269] Thu, 22 October 2015 16:06 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 195
Registered: January 2013
Location: Sweden
Senior Member
OK, I managed to get the models using getModel().

However when I use UmlModel umlModel = UmlUtils.getUmlModel(ms); i the a UmlModel (obviously) but how got i the the actual UML2 model Model element?

I guess I could use the modelset to find the resource for the actual .uml model and load it but I guess there is a better way?

/Patrik
Re: Creating diagram from modelset? [message #1712303 is a reply to message #1712285] Thu, 22 October 2015 17:54 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Patrik,

As you now have an UmlModel, you can ask it for its "root object" using
the lookupRoot() method. But, that has problems (IMHO): the return
result of this method is EObject, not Package (or, at least, Element).
And, it just gets whatever is the first element of the *.uml resource's
contents list, hoping that this is some kind of UML element. In
practice, it usually is, but ...

Better would be to do

(Package)EcoreUtil.getObjectByType(umlModel.getResource(),
UMLPackage.Literals.PACKAGE)

which might be null or might not. This is what the
UmlModel::lookupRoot() method should be doing, too.

On the subject of initial population of a diagram, well, that's very
complicated. Some diagrams (especially the behavior diagrams) rely
heavily on their EditParts to sensibly configure the layout of the
views (regions in state machines being a particularly good example of
this), so it is probably not feasible to do this without actually
automating an actual diagram editor instance. In any case, you might
have a look at the (confusingly named) "Diagram Template" component in
the Papyrus Extras, which purports to address the initial diagram
population use case.

HTH,

Christian


On 2015-10-22 16:06:30 +0000, Patrik Nandorf said:

> OK, I managed to get the models using getModel().
> However when I use UmlModel umlModel = UmlUtils.getUmlModel(ms); i the
> a UmlModel (obviously) but how got i the the actual UML2 model Model
> element?
>
> I guess I could use the modelset to find the resource for the actual
> .uml model and load it but I guess there is a better way?
>
> /Patrik
Re: Creating diagram from modelset? [message #1712336 is a reply to message #1712303] Fri, 23 October 2015 07:36 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 195
Registered: January 2013
Location: Sweden
Senior Member
Thanks again Christian, but I can't your get your suggested code snippet to work since EcoreUtil.getObjectByType() takes a collection as the first argument.

On your comment on populating diagrams, you suggest that I do it in an open diagram editor. The 'problem' I see with that is that if I need to polulate different diagrams I need to open several editors to do it which could be confusing to the user. Or am I again missing something?
Re: Creating diagram from modelset? [message #1712358 is a reply to message #1712336] Fri, 23 October 2015 09:31 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 952
Registered: February 2011
Senior Member
Hi Patrik,

Indeed, it is much easier to manipulate diagrams programatically when you can manipulate the actual EditParts. The easiest way for that being to actually open a Papyrus editor. However, GMF also supports an "Offscreen" mode, where you can load the EditPart hierarchy without actually rendering anything. We barely use that in Papyrus, so I can't give a detailed example, but the entry point would be "OffscreenEditPartFactory".

Something like this:

OffscreenEditPartFactory.getInstance().createDiagramEditPart(diagram, shell)


Then rely on Drag/Drop requests to populate this edit part, without actually rendering the diagram or opening an editor.

As I said, we barely use this in Papyrus, so you may encounter a few exceptions, but I would expect them to be quite easily fixed (If they occur at all), so please feel free to report any issue you'd have with this approach

HTH,
Camille


Camille Letavernier
Re: Creating diagram from modelset? [message #1712365 is a reply to message #1712358] Fri, 23 October 2015 10:22 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 195
Registered: January 2013
Location: Sweden
Senior Member
Thanks Camille, I'll have a look at it.

/Patrik
Re: Creating diagram from modelset? [message #1712383 is a reply to message #1712336] Fri, 23 October 2015 12:40 Go to previous message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Patrik,

Sorry, I forgot the bit about getting the resource's contents list.


(Package)EcoreUtil.getObjectByType(umlModel.getResource().getContents(),
UMLPackage.Literals.PACKAGE)

cW


On 2015-10-23 07:36:43 +0000, Patrik Nandorf said:

> Thanks again Christian, but I can't your get your suggested code
> snippet to work since EcoreUtil.getObjectByType() takes a collection as
> the first argument.
>
> On your comment on populating diagrams, you suggest that I do it in an
> open diagram editor. The 'problem' I see with that is that if I need to
> polulate different diagrams I need to open several editors to do it
> which could be confusing to the user. Or am I again missing something?
Previous Topic:Proposal: Adding palette tool entries for "missing" classifiers
Next Topic:OCL evaluating derived stereotype attributes
Goto Forum:
  


Current Time: Fri Mar 29 05:12:12 GMT 2024

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

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

Back to the top