[GMF] Deleting element synchronization problem (EMF/GMF)) [message #659448] |
Mon, 14 March 2011 04:28 |
Yu Sun Messages: 58 Registered: July 2009 |
Member |
|
|
Hi everyone,
I have been doing a project to manipulate (add/delete) models by programming in a GMF project.
When I want to add some new element, I do it by directly adding new EObject in the EMF model, as follows:
ResourceSet resourceSet = new ResourceSetImpl();
Resource targetResource = resourceSet.getResource(targetURI, true);
RootModel root = targetResource.getContents().get(0);
// ..... add some new EObject to the root
targetResource.save(null);
Once calling the save resource function, the new elements are added in both EMF model and the GMF view diagram!
However, this approach (changing EMF object directly) does not work when I am trying to delete EObjects.
After loading the RootModel from EMF resource, I tried to delete the objects using EcoreUtil.delete(element, true)
After calling the save resource function, the EMF model is changed correctly, but the GMF diagram is messed up, with a lot of error marks.
I know that the right way to delete element maybe is to use the Command. However, in my case, I need to delete the elements without opening the diagram. Does the Command approach still work in this case?
To sum up, does anyone know how to correctly delete elements from the EMF/GMF model by programming without opening them in the editor?
Thanks so much.
Yu
|
|
|
Re: [GMF] Deleting element synchronization problem (EMF/GMF)) [message #659452 is a reply to message #659448] |
Mon, 14 March 2011 04:37 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Yu,
It sounds like the GMF diagram (the notation model instance) will still
be referencing your deleted objects. You'd need to load it into the
resource set as well if you want references from that model to be
deleted as well. Even then, you'll have notation elements that don't
refer to anything. That's likely going to be a problem too. You need
somehow to clean up the diagram. I'm not sure if there are utility
methods to do that...
Yu Sun wrote:
> Hi everyone,
>
> I have been doing a project to manipulate (add/delete) models by
> programming in a GMF project.
>
> When I want to add some new element, I do it by directly adding new
> EObject in the EMF model, as follows:
>
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource targetResource = resourceSet.getResource(targetURI, true);
> RootModel root = targetResource.getContents().get(0);
>
> // ..... add some new EObject to the root
>
> targetResource.save(null);
>
> Once calling the save resource function, the new elements are added in
> both EMF model and the GMF view diagram!
>
> However, this approach (changing EMF object directly) does not work
> when I am trying to delete EObjects.
>
> After loading the RootModel from EMF resource, I tried to delete the
> objects using EcoreUtil.delete(element, true)
>
> After calling the save resource function, the EMF model is changed
> correctly, but the GMF diagram is messed up, with a lot of error marks.
>
> I know that the right way to delete element maybe is to use the
> Command. However, in my case, I need to delete the elements without
> opening the diagram. Does the Command approach still work in this case?
>
> To sum up, does anyone know how to correctly delete elements from the
> EMF/GMF model by programming without opening them in the editor?
>
> Thanks so much.
>
> Yu
>
>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04179 seconds