Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Copy some containments from the referenced object to the referring object
Copy some containments from the referenced object to the referring object [message #1782876] Fri, 02 March 2018 20:53 Go to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi guys,

I have a question. How can I copy some containments from the referenced object to the referring object as soon as the user sets the reference in the editor.

A small example:

I have a connector and a connector type.

connector
=> has many contacts as containments
=> has a cross-reference to a connectorType

connectorType
=> has many contacts as containments

Now I need the following behavior in the Editor:

As soon as the user has set the connectorType of a connector I want to copy the contacts of the connector type to the connector as containments. Now the user can adjust the names of the copied contacts for each connector individual .

What is the best way to do this? Or is there a better solution?
A small example would be really nice.

PS: I'm a newbie in EMF :9

Many thanks and have a nice evening
Re: Copy some containments from the referenced object to the referring object [message #1782881 is a reply to message #1782876] Sat, 03 March 2018 05:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
The generated item providers act as factories for the commands used to modify the model. So in your ConnectorItemProvider you could specialize org.eclipse.emf.edit.provider.ItemProviderAdapter.createSetCommand(EditingDomain, EObject, EStructuralFeature, Object, int) to create a CompoundCommand that not only sets the conntetorType feature, but also copies the ConnectorType's contacts and adds them (using an AddCommand) to the Connector's contacts feature. You could create the copies using org.eclipse.emf.edit.command.CopyCommand.create(EditingDomain, Collection<?>) or using org.eclipse.emf.ecore.util.EcoreUtil.copyAll(Collection<? extends T>) where where the former generally does the same thing as the latter, unless the item providers are specialized to do something fancy with their org.eclipse.emf.edit.provider.ItemProviderAdapter.createCreateCopyCommand(EditingDomain, EObject, Helper) or org.eclipse.emf.edit.provider.ItemProviderAdapter.createInitializeCopyCommand(EditingDomain, EObject, Helper) methods.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Copy some containments from the referenced object to the referring object [message #1782887 is a reply to message #1782881] Sat, 03 March 2018 10:35 Go to previous message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi Ed,

many thanks for your detailed help!!! :)

Have a nice weekend!!!
Previous Topic:defining model scope for XMI loader
Next Topic:How to access/set xsi:schemaLocation via API?
Goto Forum:
  


Current Time: Fri Apr 26 10:31:33 GMT 2024

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

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

Back to the top