|
Re: Moving model elements into a new model instance [message #481257 is a reply to message #481203] |
Thu, 20 August 2009 09:17 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Jevon,
Comments below.
Jevon Wright wrote:
> Hi,
>
> I wanted to write a command to move an EMF model element instance into
> a new file, yet keep all of its references from the old file(s) -- a
> cheap way of refactoring a model instance. I found that the following
> code does this:
>
> EObject object = ...;
> TransactionalEditingDomain domain = ...;
>
> // within a GMF AbstractTransactionalCommand
> URI uri = ...;
> Resource modelResource = domain.getResourceSet().createResource(uri);
> modelResource.getContents().add(object);
> modelResource.save(...);
>
> It seems that's all I need to do! I don't have to modify the source
> model instance in any way, and the new model remain in sync with the
> original model (i.e. I can edit properties/connections of one and they
> reflect on the other). It also works recursively, and works
> beautifully with GMF.
>
> My question is, is this expected behaviour? It seemed to work too
> easily. :-)
Other than the fact that object.eContainer might be != null before you
add it to the resource contents and be == null after, I'd certainly
expect it to work. If object.eContainmentReference().isResolveProxies()
is true, then I'd expect the eContainer to be preserved.
>
> Thanks,
>
> Jevon
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Moving model elements into a new model instance [message #481269 is a reply to message #481257] |
Thu, 20 August 2009 09:23 |
Jevon Messages: 164 Registered: July 2009 |
Senior Member |
|
|
Ed,
Thanks for the info, that's amazing! The Ecore editor automatically sets
Resolve Proxies to 'true' by default, it seems.
Jevon
Ed Merks wrote:
> Jevon,
>
> Comments below.
>
> Jevon Wright wrote:
>> Hi,
>>
>> I wanted to write a command to move an EMF model element instance into
>> a new file, yet keep all of its references from the old file(s) -- a
>> cheap way of refactoring a model instance. I found that the following
>> code does this:
>>
>> EObject object = ...;
>> TransactionalEditingDomain domain = ...;
>>
>> // within a GMF AbstractTransactionalCommand
>> URI uri = ...;
>> Resource modelResource = domain.getResourceSet().createResource(uri);
>> modelResource.getContents().add(object);
>> modelResource.save(...);
>>
>> It seems that's all I need to do! I don't have to modify the source
>> model instance in any way, and the new model remain in sync with the
>> original model (i.e. I can edit properties/connections of one and they
>> reflect on the other). It also works recursively, and works
>> beautifully with GMF.
>>
>> My question is, is this expected behaviour? It seemed to work too
>> easily. :-)
> Other than the fact that object.eContainer might be != null before you
> add it to the resource contents and be == null after, I'd certainly
> expect it to work. If object.eContainmentReference().isResolveProxies()
> is true, then I'd expect the eContainer to be preserved.
>>
>> Thanks,
>>
>> Jevon
|
|
|
Powered by
FUDForum. Page generated in 0.02642 seconds