Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » [GMF] Deleting element synchronization problem (EMF/GMF))
[GMF] Deleting element synchronization problem (EMF/GMF)) [message #659448] Mon, 14 March 2011 00:28 Go to next message
Eclipse UserFriend
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 00:37 Go to previous messageGo to next message
Eclipse UserFriend
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
>
>
>
>
Re: [GMF] Deleting element synchronization problem (EMF/GMF)) [message #659454 is a reply to message #659452] Mon, 14 March 2011 01:11 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Ed. I might need to try to load the GMFResource and delete the correspondent view objects.

If anyone had done this before, please let me know. Thanks a lot!
Re: [GMF] Deleting element synchronization problem (EMF/GMF)) [message #714445 is a reply to message #659454] Wed, 10 August 2011 10:29 Go to previous messageGo to next message
Eclipse UserFriend
I have a similar problem Yu. Did you ever end up resolving this issue? I.e., keeping the GMF editor in synch with the EMF model on a delete? My issues is, when the GMF Editor is closed, my GMF editor gets out of synch with the EMF model for object deletes.
Re: [GMF] Deleting element synchronization problem (EMF/GMF)) [message #714545 is a reply to message #714445] Wed, 10 August 2011 15:37 Go to previous message
Eclipse UserFriend
Hi Vinny,

If I remember it correctly, I think the solution is to use the GMF command stack.

I cannot find the source code for you right now, but I am sure you can find it somewhere online.

Basically, you need to get the Command Stack from your GMF editor. Then, if you want to delete the element, you create a GMF Delete Command (there is a class for command), and then execute it in the command stack.

In this way, GMF deletes the element and then automatically update the EMF model.

Please let me know if this helps.

Yu
Previous Topic:GMF Tooling 2.4.0 Release ????
Next Topic:adding background image in compartment
Goto Forum:
  


Current Time: Sun Jul 06 16:09:05 EDT 2025

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

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

Back to the top