Emf2gv allow to generate diagrams outside of Eclipse, for example in a standalone application.
To do that, one has at first to get all the required libraries (go to the dependencies page for more details).
This can be done manually by going (by retrieving it in the eclipse directory) or through an automated way (see the following paragraph).
org.emftools.emf2gv.standalonefeature
for the project's name and click Finish
feature.xml
file and replace the file content by the following code :<?xml version="1.0" encoding="UTF-8"?> <feature id="org.emftools.emf2gv.standalonefeature" label="Standalone" version="1.0.0.qualifier"> <!-- Your model and edit plugins (replace the school sample libraries) --> <plugin id="org.emftools.samples.school" version="0.0.0"/> <plugin id="org.emftools.samples.school.edit" version="0.0.0"/> <!-- Required dependencies for the standalone mode --> <plugin id="org.emftools.emf2gv.processor.core" version="0.0.0"/> <plugin id="org.emftools.emf2gv.graphdesc" version="0.0.0"/> <plugin id="org.emftools.emf2gv.util" version="0.0.0"/> <plugin id="org.emftools.validation.utils" version="0.0.0"/> <plugin id="org.eclipse.core.runtime" version="0.0.0"/> <plugin id="org.eclipse.emf.ecore" version="0.0.0"/> <plugin id="org.eclipse.emf.common" version="0.0.0"/> <plugin id="org.eclipse.emf.ecore.xmi" version="0.0.0"/> <plugin id="org.eclipse.equinox.common" version="0.0.0"/> <plugin id="org.eclipse.ocl.ecore" version="0.0.0"/> <plugin id="org.eclipse.ocl" version="0.0.0"/> <plugin id="org.eclipse.emf.edit" version="0.0.0"/> <plugin id="lpg.runtime.java" version="0.0.0"/> </feature>
build-libs.xml
(don't name it build.xml
or it may be replaced during the PDE build) with the following content :<project name="test" default="default"> <target name="default"> <pde.exportFeatures features="org.emftools.emf2gv.standalonefeature" destination="out" exportType="directory" useJARFormat="true"/> </target> </project>
Now that we have retrieved the dependencies, wit's time to create the sample application.
org.emftools.emf2gv.standaloneapp
for the project's name and click Finish
lib
in the projectStandaloneApp
in the package org.emftools.emf2gv.standaloneapp
StandaloneApp
class and replace the file content by the following code :
package org.emftools.emf2gv.standaloneapp; import java.io.File; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; import org.emftools.emf2gv.graphdesc.GVFigureDescription; import org.emftools.emf2gv.graphdesc.GraphdescPackage; import org.emftools.emf2gv.processor.core.StandaloneProcessor; import org.emftools.samples.school.SchoolPackage; public class StandaloneApp { public static void main(String[] args) { try { // Packages initialization SchoolPackage.eINSTANCE.eClass(); GraphdescPackage.eINSTANCE.eClass(); // Load the model resource System.out.println("Loading the model..."); ResourceSet rs = new ResourceSetImpl(); rs.getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); Resource modelResource = rs.getResource(URI.createURI( StandaloneApp.class.getResource("sample.school") .toString(), true), true); // Load the graphical description System.out.println("Loading the graphical description..."); Resource graphDescResource = rs.getResource(URI.createURI( StandaloneApp.class.getResource("sample.graphdesc") .toString(), true), true); // Graphical description retrieval GVFigureDescription gvFigureDescription = (GVFigureDescription) graphDescResource .getContents().get(0); // Diagram generation System.out.println("Diagram generation..."); StandaloneProcessor.process(modelResource.getContents(), // model gvFigureDescription, // Figure description new File("emf2gvWorkDir"), // Work directory "sample.jpg", // diagram file null, // Callback null, // Icon provider null, // dot command true, // Add validation decorators ? false, // Keep generated Graphviz source file ? "UTF-8", // Graphviz source encoding null, // Additional filters null, // ILogger null); // Progress monitor System.out.println("Done."); } catch (Throwable t) { System.err.println("An unexpected error occured"); t.printStackTrace(); } } } |
Standalone
class (follow the link)Standalone
class (follow the link)StandaloneApp
(right click on the class, select Run As > Java Applicationsample.jpg
appears in the project