Skip to main content



      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 15:53 Go to next message
Eclipse UserFriend
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 00:13 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Copy some containments from the referenced object to the referring object [message #1782887 is a reply to message #1782881] Sat, 03 March 2018 05:35 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 06:25:20 EDT 2025

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

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

Back to the top