[EMF.Edit] removeCommand [message #675409] |
Tue, 31 May 2011 08:41  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04008 seconds