If you get very strange results using Copy&Paste in GMF diagram editor then in all likelihood your EMF model doesn’t use Universally Unique Identifiers. EMF’s XMIResourceImpl supports generation of UUID transparently but it’s disabled by default. To enable it you have to overwrite XMIResourceImpl‘s useUUIDs() method and make model plug-in use that new Resource implementation.
- Overwrite useUUIDs()
- Prepare special ResourceFactory
- Wire new ResourceFactory with model plug-in
Create new class which extends XMIResourceImpl and overwrites useUUIDs(). Put it for example in yourmodel.utils package.
package mymodel.util; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl; public class MymodelResource extends XMIResourceImpl { public MymodelResource() { super(); } public MymodelResource(URI uri) { super(uri); } /* (non-Javadoc) * @see org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl#useUUIDs() */ protected boolean useUUIDs() { return true; } }
This ResourceFactory factory should always create instances of MymodelResource class.
package mymodel.util; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; public class MymodelResourceFactory extends XMIResourceFactoryImpl { public MymodelResourceFactory() { super(); } /* (non-Javadoc) * @see org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl#createResource(org.eclipse.emf.common.util.URI) */ public Resource createResource(URI uri) { return new MymodelResource(uri); } }
To plug.xml of your model plug-in add extension_parser extension:
<extension point="org.eclipse.emf.ecore.extension_parser"> <parser type="gnmsmodel" class="com.globalus.globnms.model.gnmsmodel.util.GnmsmodelResourceFactory"> </parser> </extension>
All done. Now when you modify your model and save it you will get UUID’s stored in XMI file. This will of course bread relations from GMF’a notation model. Notation model should be deleted and initialized again.
[ratings]
Hello, thx for your post. It helped me a lot :)
I am able to copy and paste the elements in a compartment, however when i am copying the element which has compartment i am facing serious problems.
How to disable copy and paste from the editor?? Please let me know
I don’t know. Try to ask on GMF forum http://www.eclipse.org/forums/index.php?t=thread&frm_id=16
Of course, what a fantastic blog and instructive posts, I will bookmark your blog.Have an awsome day!