Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 » Change parent/owner
Change parent/owner [message #1832967] Wed, 30 September 2020 07:06 Go to next message
Christoph Lehr is currently offline Christoph LehrFriend
Messages: 24
Registered: June 2020
Junior Member
Hi all,

I'm currently developing a tool which imports a xml based model into UML. Unfortunately this xml based model has a structure that I know some properties after I created all items in the UML model.

So there are some references that change the hierarchy of the model for this I would need to change the owner/parent of an Element. Until know I did not find an easy method to accomplish changing of the owner via UML2 eclipse extension.

Is there a way to get this running without deleting the element and recreating as an owned Element of the desired parent?

Thanks for your help
Re: Change parent/owner [message #1832968 is a reply to message #1832967] Wed, 30 September 2020 07:38 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 950
Registered: February 2011
Senior Member
Hi,

UML has some specific containment references (e.g. Package#packagedElement references the PackageableElements contained in the Package, whereas Package#ownedComments references the Comments owned by the Package). You need to find the correct reference, then use something like this:

Package newParentPackage = ...
PackageableElement elementToReparent = ...
newParentPackage.getPackagedElements().add(elementToReparent);


The trick here is to find the correct containment reference. The UML Specification might help with that.

HTH,
Camille


Camille Letavernier
Re: Change parent/owner [message #1832972 is a reply to message #1832968] Wed, 30 September 2020 08:19 Go to previous messageGo to next message
Christoph Lehr is currently offline Christoph LehrFriend
Messages: 24
Registered: June 2020
Junior Member
Thanks for the tip.

Do you know is this also possible with classes?
In the Model Explorer in Papyrus I can create a class inside another class, but I can't find the possibility in UML2.

Re: Change parent/owner [message #1832976 is a reply to message #1832972] Wed, 30 September 2020 09:03 Go to previous messageGo to next message
German Vega is currently offline German VegaFriend
Messages: 104
Registered: December 2015
Location: Grenoble, France
Senior Member
HI

Any classifier can be declared within the scope of a class, according to the UML specification

Quote:

A Class acts as the namespace for various kinds of Classifiers defined within its scope, including Classes. Nested
Classifiers are members of the namespace of the containing Class. Classifier nesting is used for reasons of information
hiding.


The corresponding containment reference is Class#nestedClassifier, so you can try something like this :


Class parent = ...
Classifier nested = ...
parent.getNestedClassifiers().add(nested);

[Updated on: Wed, 30 September 2020 09:06]

Report message to a moderator

Re: Change parent/owner [message #1832978 is a reply to message #1832976] Wed, 30 September 2020 09:18 Go to previous messageGo to next message
Camille Letavernier is currently offline Camille LetavernierFriend
Messages: 950
Registered: February 2011
Senior Member
Hi,

If you're using Papyrus, you can toggle the "Advanced ModelExplorer" button in the ModelExplorer toolbar. This will show you all the references between the elements. The references with a small blue diamond are the containment ones; that's the reference you're looking for.

HTH,
Camille


Camille Letavernier
Re: Change parent/owner [message #1833053 is a reply to message #1832978] Thu, 01 October 2020 12:11 Go to previous message
Christoph Lehr is currently offline Christoph LehrFriend
Messages: 24
Registered: June 2020
Junior Member
Man thanks, that works perfectly for my usecase
Previous Topic:Reading and applying profile geneated through MagicDraw
Next Topic:Profile definition results in dangling references when using a model library
Goto Forum:
  


Current Time: Mon Jun 27 22:18:15 GMT 2022

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

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

Back to the top