Skip to main content



      Home
Home » Modeling » UML2 » Change parent/owner
Change parent/owner [message #1832967] Wed, 30 September 2020 03:06 Go to next message
Eclipse UserFriend
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 03:38 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Change parent/owner [message #1832972 is a reply to message #1832968] Wed, 30 September 2020 04:19 Go to previous messageGo to next message
Eclipse UserFriend
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 05:03 Go to previous messageGo to next message
Eclipse UserFriend
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 05:06] by Moderator

Re: Change parent/owner [message #1832978 is a reply to message #1832976] Wed, 30 September 2020 05:18 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Change parent/owner [message #1833053 is a reply to message #1832978] Thu, 01 October 2020 08:11 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 10:35:16 EDT 2025

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

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

Back to the top