Copy some containments from the referenced object to the referring object [message #1782876] |
Fri, 02 March 2018 15:53  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04160 seconds