|
|
Re: Creating diagram from modelset? [message #1712303 is a reply to message #1712285] |
Thu, 22 October 2015 17:54 |
|
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 #1712358 is a reply to message #1712336] |
Fri, 23 October 2015 09:31 |
Camille Letavernier 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 #1712383 is a reply to message #1712336] |
Fri, 23 October 2015 12:40 |
|
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?
|
|
|
Powered by
FUDForum. Page generated in 0.02772 seconds