Skip to main content



      Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [EMF.Edit] removeCommand (exception when using removecommand to edit an EMF model)
[EMF.Edit] removeCommand [message #675409] Tue, 31 May 2011 08:41 Go to next message
Eclipse UserFriend
Hello,
I built my ecore metamodel (GGraph metamodel) and built a model instance (myModel) using plugins generated by genmodel (edit, editor, ...)
I tried now to edit my model (remove and add elements).
I created a popup menue plugin to add a new label in the model contextual menue (when right clicking on model) "editing model". this is part of the code that executes when select the model:

....
public void run(IAction action)
{

updateSelectedEObject();
selectedElement=getSelectedEObject();
List<GIMPLE_Node> all_nodes =selectedElement.getNodes();
GIMPLE_Node n= all_nodes.get(1);
remove_node(selectedElement, n);
}

public void remove_node(GIMPLE_Graph gg, GIMPLE_Node gn)
{

EditingDomain ed = AdapterFactoryEditingDomain.getEditingDomainFor(gg);
Command cmd= RemoveCommand.create(ed, gn);
ed.getCommandStack().execute(cmd);

}

the node that I try to remove is well removed but when I try to save the model (ctrl s) I get this exception:

org.eclipse.emf.ecore.xmi.DanglingHREFException: The object 'GGraph.impl.GIMPLE_State_CondImpl@1baeec3 (name: S_COND1, label: L1) (kind: eq_exp)' is not contained in a resource.
at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.handleDanglingHREF(XMLHelperImpl.java:760)
at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getURIFragment(XMLHelperImpl.java:731)
at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getIDREF(XMLHelperImpl.java:753)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveIDRefMany(XMLSaveImpl.java:2003)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1355)

any idea ? did I miss some thing ?

Thank you very much

Asma

Re: [EMF.Edit] removeCommand [message #675479 is a reply to message #675409] Tue, 31 May 2011 12:24 Go to previous messageGo to next message
Eclipse UserFriend
Hello,

The problem comes from the fact that the node to remove is referenced by other classes in the same model.
in fact Command cmd= RemoveCommand.create(ed, gn); is the same than

Command cmd = new RemoveCommand(ed,gn.eContainer(),GGraphPackage.eINSTANCE.getGIMPLE_Graph_Nodes(),gn);

it removes only references betwwen the element and its container but did not check other references!!!!

when I removed manually the other references of the element to remove, The exception disappear and I can save my model.

I am wondering what is the role of the ItemProvider, the AdapterFactory, and other classes generated by EMF if we should remove manually all the references of the element to remove.

I think that I miss some thing. any idea ? should I call explicitly the adapters, notifychange,etc ?

thank you very much.

Asma
Re: [EMF.Edit] removeCommand [message #675495 is a reply to message #675479] Tue, 31 May 2011 12:40 Go to previous messageGo to next message
Eclipse UserFriend
Asma,

It sounds like you want the effect of a DeleteCommand, which cleans up
all references using RemoveCommand and SetCommand, depending on
multiplicity.

charfi asma wrote:
> Hello,
>
> The problem comes from the fact that the node to remove is referenced
> by other classes in the same model. in fact Command cmd=
> RemoveCommand.create(ed, gn); is the same than
>
> Command cmd = new
> RemoveCommand(ed,gn.eContainer(),GGraphPackage.eINSTANCE.getGIMPLE_Graph_Nodes(),gn);
>
>
> it removes only references betwwen the element and its container but
> did not check other references!!!!
>
> when I removed manually the other references of the element to remove,
> The exception disappear and I can save my model.
>
> I am wondering what is the role of the ItemProvider, the
> AdapterFactory, and other classes generated by EMF if we should
> remove manually all the references of the element to remove.
> I think that I miss some thing. any idea ? should I call explicitly
> the adapters, notifychange,etc ?
>
> thank you very much.
>
> Asma
Re: [EMF.Edit] removeCommand [message #675682 is a reply to message #675495] Wed, 01 June 2011 03:53 Go to previous message
Eclipse UserFriend
Hello Ed,

yes, I want the effect of the DeleteCommand !! I was not aware of the existing of such command Smile thank you very much for your help.

Asma
Previous Topic:[EMF Compare] Inverse use of EMF Compare
Next Topic:[EEF] Label of Group widget is not generated
Goto Forum:
  


Current Time: Fri Jul 04 23:22:45 EDT 2025

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

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

Back to the top