about searching
How To Enable UUID In EMF Generated Model To Get Copy&Paste Working
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]
| Print article | This entry was posted by Seweryn Niemiec on 2007-03-5 at 21:30, and is filed under . Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 3 years ago
Hello, thx for your post. It helped me a lot :)
about 2 years ago
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.
about 2 years ago
How to disable copy and paste from the editor?? Please let me know
about 2 years ago
I don’t know. Try to ask on GMF forum http://www.eclipse.org/forums/index.php?t=thread&frm_id=16