Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Fluegge2010-05-16 16:04:14 +0000
committerMartin Fluegge2010-05-16 16:04:14 +0000
commit468ae2103a4d6cf24aab3a2cabd4d764c5daaa5d (patch)
treeb1e8a80a173025cd6bd3b0924b1efddc50775ed8 /plugins/org.eclipse.emf.cdo.dawn.codegen/src
parentd1c0df56d49e38b5c5f5d8b9457973f63c468ad3 (diff)
downloadcdo-468ae2103a4d6cf24aab3a2cabd4d764c5daaa5d.tar.gz
cdo-468ae2103a4d6cf24aab3a2cabd4d764c5daaa5d.tar.xz
cdo-468ae2103a4d6cf24aab3a2cabd4d764c5daaa5d.zip
[308232] [Dawn] Develop collaborative support for GMF on CDO
https://bugs.eclipse.org/bugs/show_bug.cgi?id=308232
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.dawn.codegen/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/metamodel/Checks.chk0
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/metamodel/DawnCodeGen.ecore28
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/DawnCodeGenPlugin.java53
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateClientCodeAction.java87
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateDawnGenModelAction.java163
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/Creator.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/impl/GMFFragmentCreator.java141
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/ProjectCreationHelper.java499
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.java103
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/util.ext52
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/template/GMFFragmentTemplate.xpt1005
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/template/GeneratorExtensions.ext3
-rw-r--r--plugins/org.eclipse.emf.cdo.dawn.codegen/src/workflow/gmfFragmentGenerator.oaw91
13 files changed, 2246 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/metamodel/Checks.chk b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/metamodel/Checks.chk
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/metamodel/Checks.chk
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/metamodel/DawnCodeGen.ecore b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/metamodel/DawnCodeGen.ecore
new file mode 100644
index 0000000000..1fa1b67a82
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/metamodel/DawnCodeGen.ecore
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="dawngenmodel"
+ nsURI="http://www.eclipse.org/emf/cdo/dawn/2010/GenModel" nsPrefix="dawngenmodel">
+ <eClassifiers xsi:type="ecore:EClass" name="DawnGMFGenerator">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="fragmentName" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnEditorClassName" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnDocumentProviderClassName"
+ eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnEditorUtilClassName"
+ eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnCreationWizardClassName"
+ eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnCanonicalEditingPolicyClassName"
+ eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnDiagramEditPartClassName"
+ eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnEditPartFactoryClassName"
+ eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnEditPartProviderClassName"
+ eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="dawnEditPolicyProviderClassName"
+ eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EReference" name="GMFGenEditorGenerator"
+ eType="ecore:EClass platform:/plugin/org.eclipse.gmf.codegen/models/gmfgen.ecore#//GenEditorGenerator"/>
+ </eClassifiers>
+</ecore:EPackage>
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/DawnCodeGenPlugin.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/DawnCodeGenPlugin.java
new file mode 100644
index 0000000000..9f25b452b2
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/DawnCodeGenPlugin.java
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.codegen;
+
+import org.eclipse.core.runtime.Plugin;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Martin Fluegge
+ */
+public class DawnCodeGenPlugin extends Plugin
+{
+ public static final String PLUGIN_ID = "org.eclipse.emf.cdo.dawn.codegen"; //$NON-NLS-1$
+
+ private static DawnCodeGenPlugin plugin;
+
+ public DawnCodeGenPlugin()
+ {
+ }
+
+ @Override
+ public void start(BundleContext context) throws Exception
+ {
+ super.start(context);
+ plugin = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception
+ {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static DawnCodeGenPlugin getDefault()
+ {
+ return plugin;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateClientCodeAction.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateClientCodeAction.java
new file mode 100644
index 0000000000..2fbd43ada4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateClientCodeAction.java
@@ -0,0 +1,87 @@
+/**
+ * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.codegen.actions;
+
+import org.eclipse.emf.cdo.dawn.codegen.creators.Creator;
+import org.eclipse.emf.cdo.dawn.codegen.creators.impl.GMFFragmentCreator;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+
+/**
+ * @author Martin Fluegge
+ */
+public class GenerateClientCodeAction implements IObjectActionDelegate
+{
+ private IResource selectedElement;
+
+ private Object part;
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart)
+ {
+ part = targetPart;
+ }
+
+ public void run(IAction action)
+ {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ try
+ {
+ window.run(true, true, new IRunnableWithProgress()
+ {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
+ {
+ monitor.beginTask("Generate Dawn Code", 1000);
+ ArrayList<Creator> creators = new ArrayList<Creator>();
+ creators.add(new GMFFragmentCreator(selectedElement));
+
+ for (Creator creator : creators)
+ {
+ creator.create(new SubProgressMonitor(monitor, 1000 / creators.size()));
+ }
+ }
+ });
+ }
+ catch (InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection selection)
+ {
+ if (selection instanceof IStructuredSelection)
+ {
+ Object sel = ((IStructuredSelection)selection).getFirstElement();
+ if (sel instanceof IResource)
+ {
+ selectedElement = (IResource)sel;
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateDawnGenModelAction.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateDawnGenModelAction.java
new file mode 100644
index 0000000000..25cb4311e5
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/actions/GenerateDawnGenModelAction.java
@@ -0,0 +1,163 @@
+/**
+ * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.codegen.actions;
+
+import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawnGMFGenerator;
+import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawngenmodelFactory;
+import org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper;
+
+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.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+
+/**
+ * @author Martin Fluegge
+ */
+public class GenerateDawnGenModelAction implements IObjectActionDelegate
+{
+
+ private IResource selectedElement;
+
+ public static final String dawngenmodelFileExtension = "dawngenmodel";
+
+ private final String generalPrefix = "Dawn";
+
+ private Object part;
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart)
+ {
+ part = targetPart;
+ }
+
+ public void run(IAction action)
+ {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ try
+ {
+ window.run(true, true, new IRunnableWithProgress()
+ {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
+ {
+ monitor.beginTask("Generate Dawn Code", 1000);
+ IFile gmfGen = (IFile)selectedElement;
+
+ String gmfGenModelFile = gmfGen.getRawLocationURI().toString();
+ String path = gmfGenModelFile.replace(gmfGen.getName(), "");
+ String modelname = gmfGen.getName().replace(".gmfgen", "");
+
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("gmfgen",
+ new XMIResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("genmodel",
+ new XMIResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(dawngenmodelFileExtension,
+ new XMIResourceFactoryImpl());
+
+ URI gmfGenModelResourceUri = URI.createURI(gmfGenModelFile);
+ Resource gmfGenModelResource = resourceSet.getResource(gmfGenModelResourceUri, true);
+
+ String dawnGenModelResourcePath = path + "" + modelname + "." + dawngenmodelFileExtension;
+ Resource dawnGenModelResource = resourceSet.createResource(URI.createURI(dawnGenModelResourcePath));
+
+ GenEditorGenerator editorGenerator = (GenEditorGenerator)gmfGenModelResource.getContents().get(0);
+
+ DawnGMFGenerator dawnGMFGenerator = DawngenmodelFactory.eINSTANCE.createDawnGMFGenerator();
+
+ String dawnEditorClassName = getDawnEditorClassName(editorGenerator);
+
+ dawnGMFGenerator.setDawnEditorClassName(dawnEditorClassName);
+ dawnGMFGenerator.setFragmentName(editorGenerator.getPlugin().getID() + ".dawn");
+ dawnGMFGenerator.setDawnCanonicalEditingPolicyClassName(generalPrefix
+ + editorGenerator.getDiagram().getCanonicalEditPolicyClassName());
+ dawnGMFGenerator.setDawnCreationWizardClassName(generalPrefix
+ + editorGenerator.getDiagram().getCreationWizardClassName());
+ dawnGMFGenerator.setDawnDiagramEditPartClassName(generalPrefix
+ + editorGenerator.getDiagram().getEditPartClassName());
+ dawnGMFGenerator.setDawnDocumentProviderClassName(generalPrefix
+ + editorGenerator.getDiagram().getDocumentProviderClassName());
+ dawnGMFGenerator.setDawnEditorUtilClassName(generalPrefix
+ + editorGenerator.getDiagram().getDiagramEditorUtilClassName());
+ dawnGMFGenerator.setDawnEditPartFactoryClassName(generalPrefix
+ + editorGenerator.getDiagram().getEditPartFactoryClassName());
+ dawnGMFGenerator.setDawnEditPartProviderClassName(generalPrefix
+ + editorGenerator.getDiagram().getEditPartProviderClassName());
+ dawnGMFGenerator.setDawnEditPolicyProviderClassName(generalPrefix
+ + editorGenerator.getDiagram().getEditPartProviderClassName().replace("EditPart", "EditPolicy"));
+
+ dawnGMFGenerator.setGMFGenEditorGenerator(editorGenerator);
+
+ dawnGenModelResource.getContents().add(dawnGMFGenerator);
+
+ try
+ {
+ dawnGenModelResource.save(Collections.EMPTY_MAP);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+
+ ProjectCreationHelper.refreshProject(null, monitor);
+ }
+ });
+ }
+ catch (InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private String getDawnEditorClassName(GenEditorGenerator editorGenerator)
+ {
+ String dawnEditorClassName = editorGenerator.getEditor().getClassName();
+ if (dawnEditorClassName == null || dawnEditorClassName.equals(""))
+ {
+ dawnEditorClassName = "Dawn" + editorGenerator.getDomainGenModel() + "DiagramEditor";
+ }
+ dawnEditorClassName = generalPrefix + dawnEditorClassName;
+ return dawnEditorClassName;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection)
+ {
+ if (selection instanceof IStructuredSelection)
+ {
+ Object sel = ((IStructuredSelection)selection).getFirstElement();
+ if (sel instanceof IResource)
+ {
+ selectedElement = (IResource)sel;
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/Creator.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/Creator.java
new file mode 100644
index 0000000000..b8cd362343
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/Creator.java
@@ -0,0 +1,21 @@
+/**
+ * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.codegen.creators;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Martin Fluegge
+ */
+public interface Creator
+{
+ public void create(IProgressMonitor monitor);
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/impl/GMFFragmentCreator.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/impl/GMFFragmentCreator.java
new file mode 100644
index 0000000000..c481c5ccf2
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/creators/impl/GMFFragmentCreator.java
@@ -0,0 +1,141 @@
+/**
+ * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.codegen.creators.impl;
+
+import org.eclipse.emf.cdo.dawn.codegen.actions.GenerateDawnGenModelAction;
+import org.eclipse.emf.cdo.dawn.codegen.creators.Creator;
+import org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawnGMFGenerator;
+import org.eclipse.emf.cdo.dawn.codegen.util.ProjectCreationHelper;
+import org.eclipse.emf.cdo.dawn.codegen.util.Utils;
+
+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.eclipse.emf.mwe.core.WorkflowRunner;
+import org.eclipse.emf.mwe.core.monitor.NullProgressMonitor;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.pde.internal.core.natures.PDE;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Martin Fluegge
+ */
+public class GMFFragmentCreator implements Creator
+{
+ private final IResource selectedElement;
+
+ public GMFFragmentCreator(IResource selectedElement)
+ {
+ this.selectedElement = selectedElement;
+ }
+
+ public void create(IProgressMonitor monitor)
+ {
+ IFile dawnGenModelFile = (IFile)selectedElement;
+
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
+ GenerateDawnGenModelAction.dawngenmodelFileExtension, new XMIResourceFactoryImpl());
+
+ Resource dawnGenModelResource = resourceSet.getResource(URI.createURI(dawnGenModelFile.getRawLocationURI()
+ .toString()), true);
+
+ DawnGMFGenerator dawnGMFGenerator = (DawnGMFGenerator)dawnGenModelResource.getContents().get(0);
+
+ monitor.subTask("Create client fragment's basic structure");
+
+ String[] natures = new String[] { JavaCore.NATURE_ID, PDE.PLUGIN_NATURE };
+ ProjectCreationHelper projectCreationHelper = new ProjectCreationHelper();
+ projectCreationHelper.setName(dawnGMFGenerator.getFragmentName());
+ projectCreationHelper.setNatures(natures);
+ IProject project;
+ try
+ {
+ project = projectCreationHelper.createProject();
+ projectCreationHelper.createJavaProject(project);
+
+ monitor.worked(100);
+
+ monitor.subTask("Creating folder structure...");
+ projectCreationHelper.createFolder("lib", project);
+ projectCreationHelper.createFolder("META-INF", project);
+ projectCreationHelper.createFolder("icons", project);
+
+ monitor.worked(100);
+
+ monitor.subTask("Creating generic content...");
+ createGenericContent(monitor, project.getLocation());
+ ProjectCreationHelper.refreshProject(project, monitor);
+ }
+ catch (CoreException e1)
+ {
+ e1.printStackTrace();
+ }
+ catch (InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+
+ monitor.worked(100);
+
+ }
+
+ private void createGenericContent(IProgressMonitor monitor, IPath location)
+ {
+ IFile file = (IFile)selectedElement;
+ Map<String, String> properties = new HashMap<String, String>();
+
+ Map<String, ?> slotMap = new HashMap<String, Object>();
+ try
+ {
+ String dawnGenFile = file.getRawLocationURI().toString();// ;file.getLocation().toFile().getAbsoluteFile().toURI().toURL().toString();
+
+ IFile dawnGen = (IFile)selectedElement;
+ IProject hostProject = dawnGen.getProject();
+
+ Utils.setPackage(hostProject.getName());
+
+ String ouputFolder = location.toFile().getAbsoluteFile().toString();// + "/" + hostProject.getName()+".diagram";
+
+ properties.put("model", dawnGenFile);
+ properties.put("src-gen", ouputFolder);
+
+ URL workFlowURL = this.getClass().getClassLoader().getResource("/workflow/gmfFragmentGenerator.oaw");
+ WorkflowRunner workflowRunner = new WorkflowRunner();
+ String workflow = FileLocator.toFileURL(workFlowURL).getFile();
+
+ workflowRunner.run(workflow, new NullProgressMonitor(), properties, slotMap);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/ProjectCreationHelper.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/ProjectCreationHelper.java
new file mode 100644
index 0000000000..23c590da65
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/ProjectCreationHelper.java
@@ -0,0 +1,499 @@
+/**
+ * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.codegen.util;
+
+import org.eclipse.core.internal.resources.ResourceException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Martin Fluegge
+ */
+public class ProjectCreationHelper
+{
+
+ private String name;
+
+ private String[] natures;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public IProject getProject()
+ {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ }
+
+ public IProject createProject() throws CoreException
+ {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
+
+ // if (project.exists())
+ // {
+ // try
+ // {
+ // project.delete(true, null);
+ // }
+ // catch (Exception e)
+ // {
+ // System.out.println("Project could not be deleted!!!");
+ // }
+ // }
+ if (!project.exists())
+ {
+ project.create(null);
+ }
+
+ if (!project.isOpen())
+ {
+ project.open(null);
+ }
+
+ IProjectDescription description = project.getDescription();
+ description.setNatureIds(natures);
+ project.setDescription(description, null);
+
+ return project;
+ }
+
+ /**
+ * @param path
+ * @param javaProject
+ * @throws JavaModelException
+ */
+ public static void addJarToBuildPath(String path, IJavaProject javaProject) throws JavaModelException
+ {
+ IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(new Path(path), null, null);
+ ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry);
+ }
+
+ public static void addJarToBuildPath(IPath path, IJavaProject javaProject) throws JavaModelException
+ {
+ IClasspathEntry newLibraryEntry = JavaCore.newLibraryEntry(path, null, null);
+ ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry);
+ }
+
+ public static void addVariableEntryToBuildPath(IPath path, IJavaProject javaProject) throws JavaModelException
+ {
+ IClasspathEntry newLibraryEntry = JavaCore.newVariableEntry(path, null, null);
+ ProjectCreationHelper.addToClasspath(javaProject, newLibraryEntry);
+ }
+
+ /**
+ * adds all jar files in this folder to the build path. Searches only on level 1
+ *
+ * @param folder
+ * the folder which contains the jar files
+ * @param javaProject
+ * @throws CoreException
+ */
+ public static void addAllJarsToBuildPath(IFolder folder, IJavaProject javaProject) throws CoreException
+ {
+ try
+ {
+ folder.refreshLocal(100, new NullProgressMonitor());
+ for (IResource resource : folder.members())
+ {
+
+ if (resource instanceof IFile && resource.getRawLocation().toString().endsWith(".jar"))
+ {
+ addJarToBuildPath(resource.getRawLocation(), javaProject);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * @param javaProject
+ * @param newEntry
+ * @throws JavaModelException
+ */
+ public final static void addToClasspath(IJavaProject javaProject, IClasspathEntry newEntry) throws JavaModelException
+ {
+ if (newEntry == null)
+ {
+ return;
+ }
+ IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
+ IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
+ System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
+
+ newEntries[oldEntries.length] = newEntry;
+ javaProject.setRawClasspath(newEntries, null);
+ }
+
+ /**
+ * @param javaProject
+ * @param toBeRemoved
+ * @throws JavaModelException
+ */
+ private final static void removeFromClasspath(IJavaProject javaProject, IPath toBeRemoved) throws JavaModelException
+ {
+ IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
+ ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
+
+ for (IClasspathEntry classpathEntry : oldEntries)
+ {
+ if (!classpathEntry.getPath().equals(toBeRemoved))
+ {
+ newEntries.add(classpathEntry);
+ }
+ }
+ // IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
+ // System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
+
+ // newEntries[oldEntries.length] = newEntry;
+ IClasspathEntry[] newEntriesArray = new IClasspathEntry[newEntries.size()];
+ javaProject.setRawClasspath(newEntries.toArray(newEntriesArray), null);
+ }
+
+ /**
+ * @return
+ * @throws CoreException
+ */
+ public IJavaProject createJavaProject() throws CoreException
+ {
+ IProject project = createProject();
+ return createJavaProject(project);
+ }
+
+ /**
+ * @param project
+ * @return
+ */
+ public IJavaProject createJavaProject(IProject project)
+ {
+ try
+ {
+ // addJavaNature(project);
+ IJavaProject javaProject = JavaCore.create(project);
+ if (!javaProject.isOpen())
+ {
+ javaProject.open(null);
+ }
+ createBinFolder(project, javaProject);
+ clearSourcePath(javaProject);
+
+ IClasspathEntry sourceFolder = createSourceFolder("src", project);
+
+ addToClasspath(javaProject, sourceFolder);
+ addJREContainerToProject(javaProject);
+ return javaProject;
+ }
+ catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+
+ }
+
+ /**
+ * create a sysdeo Plugin Project
+ *
+ * @param project
+ * @return
+ */
+ public IJavaProject createSysdeoTomcatProject(IProject project)
+ {
+ try
+ {
+ IJavaProject javaProject = JavaCore.create(project);
+ createOutputFolder("WEB-INF/classes", project, javaProject);
+
+ /*
+ * quickfix because I could not figure out how the exclude "source" folder from root
+ */
+ clearSourcePath(javaProject);
+
+ addTomcatLibraries(javaProject);
+ addSourceFolder(project, javaProject);
+ addJREContainerToProject(javaProject);
+
+ return javaProject;
+ }
+ catch (CoreException e)
+ {
+
+ e.printStackTrace();
+ }
+ return null;
+
+ }
+
+ /**
+ * @param project
+ * @param javaProject
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private void addSourceFolder(IProject project, IJavaProject javaProject) throws CoreException, JavaModelException
+ {
+ IClasspathEntry sourceFolder = createSourceFolder("WEB-INF/src", project);
+ addToClasspath(javaProject, sourceFolder);
+ }
+
+ /**
+ * @param javaProject
+ * @throws JavaModelException
+ */
+ private void addJREContainerToProject(IJavaProject javaProject) throws JavaModelException
+ {
+ addToClasspath(javaProject, JavaRuntime.getDefaultJREContainerEntry());
+ }
+
+ /**
+ * this adds the Tomcat project typical Variable entries to the project
+ *
+ * @param javaProject
+ * @throws JavaModelException
+ */
+ private void addTomcatLibraries(IJavaProject javaProject) throws JavaModelException
+ {
+ addVariableEntryToBuildPath(new Path("TOMCAT_HOME/lib/annotations-api.jar"), javaProject);
+ addVariableEntryToBuildPath(new Path("TOMCAT_HOME/lib/el-api.jar"), javaProject);
+ addVariableEntryToBuildPath(new Path("TOMCAT_HOME/lib/jasper.jar"), javaProject);
+ addVariableEntryToBuildPath(new Path("TOMCAT_HOME/lib/jsp-api.jar"), javaProject);
+ addVariableEntryToBuildPath(new Path("TOMCAT_HOME/lib/servlet-api.jar"), javaProject);
+ }
+
+ /**
+ * @param javaProject
+ * @throws JavaModelException
+ */
+ private void clearSourcePath(IJavaProject javaProject) throws JavaModelException
+ {
+ javaProject.setRawClasspath(new IClasspathEntry[] {}, new NullProgressMonitor()); // clean classpath, means remove
+ // Project root from classpath
+ }
+
+ /**
+ * @param project
+ * @throws CoreException
+ */
+ private void addJavaNature(IProject project) throws CoreException
+ {
+ IProjectDescription description = project.getDescription();
+ String[] natures = description.getNatureIds();
+ String[] newNatures = new String[natures.length + 1];
+ System.arraycopy(natures, 0, newNatures, 0, natures.length);
+ newNatures[natures.length] = JavaCore.NATURE_ID;
+ description.setNatureIds(newNatures);
+ project.setDescription(description, new NullProgressMonitor());
+ }
+
+ /**
+ * @param path
+ * @param project
+ * @return
+ * @throws CoreException
+ */
+ private IClasspathEntry createSourceFolder(String path, IProject project) throws CoreException
+ {
+ IFolder srcFolder = project.getFolder(new Path(path));
+ if (!srcFolder.exists())
+ {
+ srcFolder.create(false, true, null);
+ IPath sourceFolderPath = srcFolder.getFullPath();
+ IClasspathEntry entry = JavaCore.newSourceEntry(sourceFolderPath);
+
+ return entry;
+ }
+ return null;
+ }
+
+ /**
+ * @param path
+ * @param project
+ * @param javaProject
+ * @return
+ * @throws CoreException
+ */
+ public IFolder createSourceFolder(String path, IProject project, IJavaProject javaProject) throws CoreException
+ {
+ IFolder srcFolder = project.getFolder(new Path(path));
+ if (!srcFolder.exists())
+ {
+ srcFolder.create(false, true, null);
+ IPath sourceFolderPath = srcFolder.getFullPath();
+ IClasspathEntry entry = JavaCore.newSourceEntry(sourceFolderPath);
+ addToClasspath(javaProject, entry);
+ return srcFolder;
+ }
+ return null;
+ }
+
+ /**
+ * @param project
+ * @param javaProject
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private void createBinFolder(IProject project, IJavaProject javaProject) throws CoreException, JavaModelException
+ {
+ createOutputFolder("bin", project, javaProject);
+ }
+
+ /**
+ * @param project
+ * @param javaProject
+ * @throws CoreException
+ * @throws JavaModelException
+ */
+ private void createOutputFolder(String path, IProject project, IJavaProject javaProject) throws CoreException,
+ JavaModelException
+ {
+ try
+ {
+ IFolder binFolder = project.getFolder(new Path(path));
+ if (!binFolder.exists())
+ {
+ binFolder.create(true, true, null);
+ javaProject.setOutputLocation(binFolder.getFullPath(), null);
+ }
+ }
+ catch (ResourceException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * @param name
+ * @param project
+ * @return
+ */
+ public IFolder createFolder(String name, IProject project)
+ {
+ IFolder folder = project.getFolder(name);
+
+ if (!folder.exists())
+ {
+ try
+ {
+ folder.create(IResource.NONE, true, null);
+ }
+ catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ return folder;
+ }
+
+ public IFolder getFolder(String name, IProject project)
+ {
+ IFolder folder = project.getFolder(name);
+
+ return folder;
+ }
+
+ /**
+ * @param name
+ * @param folder
+ * @param content
+ * @return
+ */
+ public IFile createFile(String name, IFolder folder, String content)
+ {
+ IFile file = folder.getFile("web.xml");
+
+ try
+ {
+
+ if (!file.exists())
+ {
+ byte[] bytes = content.getBytes();
+ InputStream source = new ByteArrayInputStream(bytes);
+ file.create(source, IResource.NONE, null);
+
+ }
+ }
+ catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+ return file;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String[] getNatures()
+ {
+ return natures;
+ }
+
+ public void setNatures(String[] natures)
+ {
+ this.natures = natures;
+ }
+
+ public ProjectCreationHelper()
+ {
+ }
+
+ public static void refreshProject(IResource resource, IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException
+ {
+ IRunnableWithProgress op = new WorkspaceModifyOperation(null)
+ {
+ @Override
+ protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException
+ {
+ try
+ {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ root.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+
+ }
+ catch (CoreException e)
+ {
+
+ e.printStackTrace();
+ }
+ }
+ };
+ op.run(monitor);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.java b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.java
new file mode 100644
index 0000000000..5da2a13e89
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/Utils.java
@@ -0,0 +1,103 @@
+/**
+ * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+package org.eclipse.emf.cdo.dawn.codegen.util;
+
+import org.eclipse.swt.widgets.Canvas;
+
+/**
+ * @author Martin Fluegge
+ */
+public class Utils
+{
+ public static String packagePath = "";
+
+ public static String packageName = "";
+
+ public static String diagramPluginID = "";
+
+ public static String diagramPackage = "";
+
+ public static String timestamp()
+ {
+ return String.valueOf(System.currentTimeMillis());
+ }
+
+ public static String getPackagePath()
+ {
+ return packagePath;
+ }
+
+ public static String getPackageName()
+ {
+ return packageName;
+ }
+
+ public static String getDiagramPluginID()
+ {
+ return diagramPluginID;
+ }
+
+ public static String setGlobals(Canvas e)
+ {
+ // packageName=e.getName();
+ // packagePath=e.getName().replace(".", "/");
+ return "";
+ }
+
+ public static String setPackage(String pName)
+ {
+ diagramPluginID = pName + ".diagram";
+ packageName = pName.replace("class", "clazz");
+ packagePath = pName.replace(".", "/");
+ return "";
+ }
+
+ public static String setDiagramPackage(String pName)
+ {
+ diagramPackage = pName;
+ return "";
+ }
+
+ public static String getDiagramPackage()
+ {
+ return diagramPackage;
+ }
+
+ public static String getRootPackage()
+ {
+ String ret = diagramPackage.replace(".diagram", "");
+ return ret;
+ }
+
+ public static String getDiagramPackagePath()
+ {
+ return diagramPackage.replace(".", "/");
+ }
+
+ public static String getUniqueIdentifierName(String uniqueIdentifier)
+ {
+ String ret = uniqueIdentifier.substring(uniqueIdentifier.lastIndexOf(".") + 1, uniqueIdentifier.length());
+ return ret;
+ }
+
+ public static String toModelName(String uniqueIdentifier)
+ {
+ String ret = uniqueIdentifier.substring(uniqueIdentifier.lastIndexOf(".") + 1, uniqueIdentifier.length());
+ ret = ret.substring(0, ret.lastIndexOf("_"));
+ return ret;
+ }
+
+ public static String toModelNameFromGetterName(String uniqueIdentifier)
+ {
+ String ret = uniqueIdentifier.replace("getFigure", "");
+ return ret;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/util.ext b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/util.ext
new file mode 100644
index 0000000000..756e770819
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/org/eclipse/emf/cdo/dawn/codegen/util/util.ext
@@ -0,0 +1,52 @@
+/**
+ * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Martin Fluegge - initial API and implementation
+ */
+import gmfgraph;
+import gmfgen;
+import emf;
+import genmodel;
+import ecore;
+
+String timestamp() :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.timestamp();
+
+ String setGlobals( Canvas e ) :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.setGlobals(org.eclipse.gmf.gmfgraph.Canvas);
+
+ String getPackagePath() :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getPackagePath();
+
+ String getPackageName() :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getPackageName();
+
+ String getDiagramPluginID() :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPluginID();
+
+ String setDiagramPackage(String s) :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.setDiagramPackage(java.lang.String);
+
+ String getDiagramPackage() :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPackage();
+
+ String getDiagramPackagePath() :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getDiagramPackagePath();
+
+ String getRootPackage() :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getRootPackage();
+
+ String getUniqueIdentifierName(String s ) :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.getUniqueIdentifierName(java.lang.String);
+
+ String toModelName(String s ) :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.toModelName(java.lang.String);
+
+ String toModelNameFromGetterName(String s ) :
+ JAVA org.eclipse.emf.cdo.dawn.codegen.util.Utils.toModelNameFromGetterName(java.lang.String);
+ \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/template/GMFFragmentTemplate.xpt b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/template/GMFFragmentTemplate.xpt
new file mode 100644
index 0000000000..660425ab15
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/template/GMFFragmentTemplate.xpt
@@ -0,0 +1,1005 @@
+«REM»
+ Copyright (c) 2010 Martin Fluegge (Berlin, Germany).
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ Martin Fluegge - initial API and implementation
+
+«ENDREM»
+
+«IMPORT gmfgen»
+«IMPORT gmfgraph»
+«IMPORT emf»
+«IMPORT genmodel»
+«IMPORT ecore»
+«IMPORT dawngenmodel»
+
+«EXTENSION org::eclipse::emf::cdo::dawn::codegen::util::util»
+
+«DEFINE main FOR DawnGMFGenerator»
+ «setDiagramPackage(this.GMFGenEditorGenerator.packageNamePrefix)»
+
+ «EXPAND dawnEditor FOR this»
+ «EXPAND dawnEditPart FOR this»
+ «EXPAND dawnEditPartFactory FOR this»
+ «EXPAND dawnCanonicalEditingPolicy FOR this»
+ «EXPAND dawnCreationWizard FOR this»
+ «EXPAND dawnEditorUtil FOR this»
+ «EXPAND dawnDocumentProvider FOR this»
+ «EXPAND dawnEditPartProvider FOR this»
+ «EXPAND fragmentXML FOR this»
+ «EXPAND dawnEditPolicyProvider FOR this»
+ «EXPAND manifestMF FOR this.GMFGenEditorGenerator»
+ «EXPAND buildPROPERTIES FOR this.GMFGenEditorGenerator»
+ «EXPAND classpath FOR this.GMFGenEditorGenerator»
+
+«ENDDEFINE»
+
+«REM»############################################ Extended Editor ##################################################################«ENDREM»
+«DEFINE dawnEditor FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/part/"+this.dawnEditorClassName+".java"»
+
+package «this.GMFGenEditorGenerator.editor.packageName»;
+
+import «this.GMFGenEditorGenerator.diagram.domainDiagramElement.genPackage.basePackage».«this.GMFGenEditorGenerator.diagram.domainDiagramElement.ecoreClass.ePackage.name».«this.GMFGenEditorGenerator.diagram.domainDiagramElement.ecoreClass.name»;
+import org.eclipse.emf.cdo.dawn.runtime.diagram.part.IDawnDiagramEditor;
+import org.eclipse.emf.cdo.dawn.runtime.notifications.DawnNotificationUtil;
+import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.ui.CDOEditorInput;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.net4j.util.transaction.TransactionException;
+
+import org.eclipse.emf.common.ui.URIEditorInput;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.AbstractDocumentProvider;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+
+«EXPAND generatedComment -»
+public class «this.dawnEditorClassName» extends «GMFGenEditorGenerator.editor.className» implements IDawnDiagramEditor
+{
+
+ private CDOTransaction transaction;
+
+ private boolean dirty;
+
+ public static String ID = "«this.GMFGenEditorGenerator.editor.packageName».«this.dawnEditorClassName» ";
+
+
+ «EXPAND generatedComment -»
+ public «this.dawnEditorClassName» ()
+ {
+ super();
+ setDocumentProvider(new «this.dawnDocumentProviderClassName»());
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public void setInput(IEditorInput input)
+ {
+ try
+ {
+ doSetInput(input, true);
+ }
+ catch (CoreException x)
+ {
+ x.printStackTrace(System.err);
+ String title = x.getMessage();
+ String msg = x.getMessage();
+ Shell shell = getSite().getShell();
+ ErrorDialog.openError(shell, title, msg, x.getStatus());
+ }
+ transaction = (CDOTransaction)((DawnEditorInput)input).getView();
+
+ DawnNotificationUtil.registerResourceListeners(getEditingDomain().getResourceSet(), this);
+ DawnNotificationUtil.registerTransactionListeners(transaction, this);
+ DawnNotificationUtil.setChangeSubscriptionPolicy(transaction);
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ protected void initializeGraphicalViewer()
+ {
+ super.initializeGraphicalViewer();
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public void doSave(IProgressMonitor monitor)
+ {
+ try
+ {
+ dirty = false;
+ updateState(getEditorInput());
+ validateState(getEditorInput());
+ performSave(false, monitor);
+ }
+ catch (TransactionException e)
+ {
+ if (e.getMessage().contains("conflict"))
+ {
+ MessageDialog.openError(Display.getDefault().getActiveShell(), "conflict",
+ "Your Resource is in conflict and cannot be committed");
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public boolean isDirty()
+ {
+ return dirty;
+ }
+
+ «EXPAND generatedComment -»
+ public String getContributorID()
+ {
+ return null;
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ protected void setDocumentProvider(IEditorInput input)
+ {
+ if (input instanceof IFileEditorInput || input instanceof URIEditorInput || input instanceof CDOEditorInput)
+ {
+ setDocumentProvider(getDocumentProvider());
+ }
+ else
+ {
+ super.setDocumentProvider(input);
+ }
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public void dispose()
+ {
+ try
+ {
+ super.dispose();
+ }
+ finally
+ {
+ if (transaction != null && !transaction.isClosed())
+ {
+ transaction.close();
+ }
+ }
+ }
+
+ «EXPAND generatedComment -»
+ public CDOView getView()
+ {
+ return transaction;
+ }
+
+ «EXPAND generatedComment -»
+ public void setDirty()
+ {
+ dirty = true;
+ ((AbstractDocumentProvider)getDocumentProvider()).changed(getEditorInput());
+ }
+}
+
+«ENDFILE»
+«ENDDEFINE»
+
+
+«REM»############################################ DawnXXXEditPart ##################################################################«ENDREM»
+«DEFINE dawnEditPart FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/edit/parts/"+this.dawnDiagramEditPartClassName+".java"»
+package «this.GMFGenEditorGenerator.diagram.editPartsPackageName»;
+
+import org.eclipse.emf.cdo.dawn.runtime.synchronize.DawnConflictHelper;
+
+import org.eclipse.emf.ecore.EObject;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.notation.View;
+
+«EXPAND generatedComment -»
+public class «this.dawnDiagramEditPartClassName» extends «this.GMFGenEditorGenerator.diagram.editPartClassName»
+{
+
+ «EXPAND generatedComment -»
+ public «this.dawnDiagramEditPartClassName»(View view)
+ {
+ super(view);
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ protected void removeChild(EditPart child)
+ {
+ if (DawnConflictHelper.isConflicted((EObject)child.getModel()))
+ {
+ return;
+ }
+ super.removeChild(child);
+ }
+}
+«ENDFILE»
+«ENDDEFINE»
+
+
+«REM»############################################ DawnXXXEditPartFactory ##################################################################«ENDREM»
+«DEFINE dawnEditPartFactory FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/edit/parts/"+this.dawnEditPartFactoryClassName+".java"»
+package «this.GMFGenEditorGenerator.diagram.editPartsPackageName»;
+
+
+import «this.GMFGenEditorGenerator.editor.packageName».«this.GMFGenEditorGenerator.diagram.visualIDRegistryClassName»;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.notation.View;
+
+«EXPAND generatedComment -»
+public class «this.dawnEditPartFactoryClassName» extends «this.GMFGenEditorGenerator.diagram.editPartFactoryClassName»
+{
+ «EXPAND generatedComment -»
+ public «this.dawnEditPartFactoryClassName»()
+ {
+ super();
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public EditPart createEditPart(EditPart context, Object model)
+ {
+ if (model instanceof View)
+ {
+ View view = (View)model;
+ switch («this.GMFGenEditorGenerator.diagram.visualIDRegistryClassName».getVisualID(view))
+ {
+ case «this.dawnDiagramEditPartClassName».VISUAL_ID:
+ return new «this.dawnDiagramEditPartClassName»(view);
+ }
+ }
+
+ return super.createEditPart(context, model);
+ }
+}
+
+«ENDFILE»
+«ENDDEFINE»
+
+
+«REM»############################################ DawnXXXCanonicalEditingPolicy ##################################################################«ENDREM»
+«DEFINE dawnCanonicalEditingPolicy FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/edit/policies/"+this.dawnCanonicalEditingPolicyClassName+".java"»
+package «this.GMFGenEditorGenerator.diagram.editPoliciesPackageName»;
+
+«EXPAND generatedComment -»
+public class «this.dawnCanonicalEditingPolicyClassName» extends «this.GMFGenEditorGenerator.diagram.canonicalEditPolicyClassName»
+{
+ «EXPAND generatedComment -»
+ public «this.dawnCanonicalEditingPolicyClassName»()
+ {
+ super();
+ }
+}
+«ENDFILE»
+«ENDDEFINE»
+
+«REM»############################################ DawnXXXCreationWizard ##################################################################«ENDREM»
+«DEFINE dawnCreationWizard FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/part/"+this.dawnCreationWizardClassName+".java"»
+package «this.GMFGenEditorGenerator.editor.packageName»;
+
+import org.eclipse.emf.cdo.dawn.runtime.preferences.PreferenceConstants;
+import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewDiagramResourceWizardPage;
+import org.eclipse.emf.cdo.dawn.ui.wizards.DawnCreateNewResourceWizardPage;
+import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.common.util.URI;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+
+import java.lang.reflect.InvocationTargetException;
+
+«EXPAND generatedComment -»
+public class «this.dawnCreationWizardClassName» extends «this.GMFGenEditorGenerator.diagram.creationWizardClassName»
+{
+ private CDOView view;
+
+ private DawnCreateNewDiagramResourceWizardPage dawnDiagramModelFilePage;
+
+ private DawnCreateNewResourceWizardPage dawnDomainModelFilePage;
+
+ «EXPAND generatedComment -»
+ public «this.dawnCreationWizardClassName»()
+ {
+ super();
+ CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
+ PreferenceConstants.getServerName());
+ CDOSession session = CDOConnectionUtil.instance.openSession();
+ view = CDOConnectionUtil.instance.openView(session);
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public boolean performFinish()
+ {
+ IRunnableWithProgress op = new WorkspaceModifyOperation(null)
+ {
+ @Override
+ protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException
+ {
+ URI diagramResourceURI = dawnDiagramModelFilePage.getURI();
+ URI domainModelResourceURI = dawnDomainModelFilePage.getURI();
+
+ diagram = «this.dawnEditorUtilClassName».createDiagram(diagramResourceURI, domainModelResourceURI, monitor);
+
+ if (isOpenNewlyCreatedDiagramEditor() && diagram != null)
+ {
+ try
+ {
+ «this.dawnEditorUtilClassName».openDiagram(diagram);
+ }
+ catch (PartInitException e)
+ {
+ ErrorDialog.openError(getContainer().getShell(), Messages.ClassdiagramCreationWizardOpenEditorError, null,
+ e.getStatus());
+ }
+ }
+ }
+ };
+ try
+ {
+ getContainer().run(false, true, op);
+ }
+ catch (InterruptedException e)
+ {
+ return false;
+ }
+ catch (InvocationTargetException e)
+ {
+ if (e.getTargetException() instanceof CoreException)
+ {
+ ErrorDialog.openError(getContainer().getShell(), "Error while creating diagram", null,
+ ((CoreException)e.getTargetException()).getStatus());
+ }
+ else
+ {
+ «this.GMFGenEditorGenerator.plugin.activatorClassName».getInstance().logError("Error creating diagram", e.getTargetException()); //$NON-NLS-1$
+ }
+ return false;
+ }
+ return diagram != null;
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public void addPages()
+ {
+
+ dawnDiagramModelFilePage = new DawnCreateNewDiagramResourceWizardPage("«this.GMFGenEditorGenerator.diagramFileExtension»", false, view);
+ dawnDiagramModelFilePage.setTitle(Messages.«this.GMFGenEditorGenerator.diagram.creationWizardClassName»_DiagramModelFilePageTitle);
+ dawnDiagramModelFilePage.setDescription(Messages.«this.GMFGenEditorGenerator.diagram.creationWizardClassName»_DiagramModelFilePageDescription);
+ dawnDiagramModelFilePage.setCreateAutomaticResourceName(true);
+ addPage(dawnDiagramModelFilePage);
+
+ dawnDomainModelFilePage = new DawnCreateNewResourceWizardPage("", true, view)
+ {
+ @Override
+ public void setVisible(boolean visible)
+ {
+ if (visible)
+ {
+ URI uri = dawnDiagramModelFilePage.getURI();
+ String fileName = uri.lastSegment();
+ fileName = fileName.substring(0, fileName.length() - ".«this.GMFGenEditorGenerator.diagramFileExtension»".length()); //$NON-NLS-1$
+ fileName += ".«this.GMFGenEditorGenerator.domainFileExtension»";
+ dawnDomainModelFilePage.setResourceNamePrefix(fileName);
+ dawnDomainModelFilePage.setResourcePath(dawnDiagramModelFilePage.getResourcePath());
+ }
+ super.setVisible(visible);
+ }
+ };
+ dawnDomainModelFilePage.setTitle(Messages.«this.GMFGenEditorGenerator.diagram.creationWizardClassName»_DomainModelFilePageTitle);
+ dawnDomainModelFilePage.setDescription(Messages.«this.GMFGenEditorGenerator.diagram.creationWizardClassName»_DomainModelFilePageDescription);
+
+ dawnDomainModelFilePage.setResourceValidationType(DawnCreateNewResourceWizardPage.VALIDATION_WARN);
+ addPage(dawnDomainModelFilePage);
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public void dispose()
+ {
+ view.close();
+ }
+}
+«ENDFILE»
+«ENDDEFINE»
+
+«REM»############################################ DawnXXXEditorUtil ##################################################################«ENDREM»
+«DEFINE dawnEditorUtil FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/part/"+this.dawnEditorUtilClassName+".java"»
+package «this.GMFGenEditorGenerator.editor.packageName»;
+
+import «this.GMFGenEditorGenerator.diagram.domainDiagramElement.genPackage.basePackage».«this.GMFGenEditorGenerator.diagram.domainDiagramElement.ecoreClass.ePackage.name».«this.GMFGenEditorGenerator.diagram.domainDiagramElement.ecoreClass.name»;
+import «this.GMFGenEditorGenerator.diagram.domainDiagramElement.genPackage.basePackage».«this.GMFGenEditorGenerator.diagram.domainDiagramElement.ecoreClass.ePackage.name».«this.GMFGenEditorGenerator.domainGenModel.modelName»Factory;
+
+import «this.GMFGenEditorGenerator.diagram.editPartsPackageName».«this.dawnDiagramEditPartClassName»;
+import org.eclipse.emf.cdo.dawn.runtime.commands.CreateSemanticResourceRecordingCommand;
+import org.eclipse.emf.cdo.dawn.runtime.preferences.PreferenceConstants;
+import org.eclipse.emf.cdo.dawn.runtime.transaction.DawnGMFEditingDomainFactory;
+import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
+import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+import java.io.IOException;
+import java.util.Collections;
+
+«EXPAND generatedComment -»
+public class «this.dawnEditorUtilClassName» extends «this.GMFGenEditorGenerator.diagram.diagramEditorUtilClassName»
+{
+
+ «EXPAND generatedComment -»
+ public static boolean openDiagram(Resource diagram) throws PartInitException
+ {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ return null != page.openEditor(new DawnEditorInput(diagram.getURI()), «this.dawnEditorClassName».ID);
+ }
+
+ «EXPAND generatedComment -»
+ public static void runWizard(Shell shell, Wizard wizard, String settingsKey)
+ {
+ IDialogSettings pluginDialogSettings = «this.GMFGenEditorGenerator.plugin.activatorClassName».getInstance().getDialogSettings();
+ IDialogSettings wizardDialogSettings = pluginDialogSettings.getSection(settingsKey);
+ if (wizardDialogSettings == null)
+ {
+ wizardDialogSettings = pluginDialogSettings.addNewSection(settingsKey);
+ }
+ wizard.setDialogSettings(wizardDialogSettings);
+ WizardDialog dialog = new WizardDialog(shell, wizard);
+ dialog.create();
+ dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
+ dialog.open();
+ }
+
+ «EXPAND generatedComment -»
+ public static Resource createDiagram(URI diagramURI, URI modelURI, IProgressMonitor progressMonitor)
+ {
+ TransactionalEditingDomain editingDomain = DawnGMFEditingDomainFactory.getInstance().createEditingDomain();
+
+ progressMonitor.beginTask(Messages.«this.GMFGenEditorGenerator.diagram.diagramEditorUtilClassName»_CreateDiagramProgressTask, 3);
+
+ CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(),
+ PreferenceConstants.getServerName());
+ CDOConnectionUtil.instance.openSession();
+ ResourceSet resourceSet = editingDomain.getResourceSet();
+
+ CDOTransaction transaction = CDOConnectionUtil.instance.openCurrentTransaction(resourceSet, diagramURI.toString());
+
+ final Resource diagramResource = resourceSet.createResource(diagramURI);
+
+
+ CreateSemanticResourceRecordingCommand createSemanticResourceCommand = new CreateSemanticResourceRecordingCommand(
+ editingDomain, transaction, modelURI.toString());
+
+ editingDomain.getCommandStack().execute(createSemanticResourceCommand);
+ final Resource modelResource = createSemanticResourceCommand.getResource();
+
+ final String diagramName = diagramURI.lastSegment();
+ AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain,
+ Messages.«this.GMFGenEditorGenerator.diagram.diagramEditorUtilClassName»_CreateDiagramCommandLabel, Collections.EMPTY_LIST)
+ {
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException
+ {
+ EObject model = null;
+ if (modelResource.getContents().size() > 0)
+ {
+ model = modelResource.getContents().get(0);
+ }
+ else
+ {
+ model = createInitialModel();
+ attachModelToResource(model, modelResource);
+ }
+
+ Diagram diagram = ViewService.createDiagram(model, «this.dawnDiagramEditPartClassName».MODEL_ID,
+ «this.GMFGenEditorGenerator.plugin.activatorClassName».DIAGRAM_PREFERENCES_HINT);
+ if (diagram != null)
+ {
+ diagramResource.getContents().add(diagram);
+ diagram.setName(diagramName);
+ diagram.setElement(model);
+ }
+
+ try
+ {
+ modelResource.save(Collections.EMPTY_MAP);
+ diagramResource.save(Collections.EMPTY_MAP);
+ }
+ catch (IOException e)
+ {
+ «this.GMFGenEditorGenerator.plugin.activatorClassName».getInstance().logError("Unable to store model and diagram resources", e); //$NON-NLS-1$
+ }
+
+ return CommandResult.newOKCommandResult();
+ }
+ };
+ try
+ {
+ OperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null);
+ }
+ catch (ExecutionException e)
+ {
+ «this.GMFGenEditorGenerator.plugin.activatorClassName».getInstance().logError("Unable to create model and diagram", e); //$NON-NLS-1$
+ }
+ setCharset(WorkspaceSynchronizer.getFile(modelResource));
+ setCharset(WorkspaceSynchronizer.getFile(diagramResource));
+ return diagramResource;
+ }
+
+ «EXPAND generatedComment -»
+ private static EObject createInitialModel()
+ {
+ return «this.GMFGenEditorGenerator.domainGenModel.modelName»Factory.eINSTANCE.create«this.GMFGenEditorGenerator.diagram.domainDiagramElement.ecoreClass.name»();
+ }
+
+ «EXPAND generatedComment -»
+ private static void attachModelToResource(EObject model, Resource resource)
+ {
+ resource.getContents().add(model);
+ }
+}
+
+
+«ENDFILE»
+«ENDDEFINE»
+
+«REM»############################################ DawnXXXDocumentProvider ##################################################################«ENDREM»
+«DEFINE dawnDocumentProvider FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/part/"+this.dawnDocumentProviderClassName+".java"»
+package «this.GMFGenEditorGenerator.editor.packageName»;
+
+import org.eclipse.emf.cdo.dawn.runtime.transaction.DawnDiagramEditingDomainFactory;
+import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput;
+import org.eclipse.emf.cdo.dawn.util.DawnDiagramUpdater;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.ui.URIEditorInput;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.transaction.NotificationFilter;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DiagramDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument;
+import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.util.DiagramIOUtil;
+import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+«EXPAND generatedComment -»
+public class «this.dawnDocumentProviderClassName» extends «this.GMFGenEditorGenerator.diagram.documentProviderClassName»
+{
+
+ «EXPAND generatedComment -»
+ public «this.dawnDocumentProviderClassName» ()
+ {
+ super();
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ protected IDocument createEmptyDocument()
+ {
+ DiagramDocument document = new DiagramDocument();
+ document.setEditingDomain(createEditingDomain());
+ return document;
+ }
+
+ «EXPAND generatedComment -»
+ private TransactionalEditingDomain createEditingDomain()
+ {
+ TransactionalEditingDomain editingDomain = DawnDiagramEditingDomainFactory.getInstance().createEditingDomain();
+ editingDomain.setID("org.eclipse.emf.cdo.dawn.reference.editor.diagram.EditingDomain"); //$NON-NLS-1$
+ final NotificationFilter diagramResourceModifiedFilter = NotificationFilter.createNotifierFilter(
+ editingDomain.getResourceSet()).and(NotificationFilter.createEventTypeFilter(Notification.ADD)).and(
+ NotificationFilter.createFeatureFilter(ResourceSet.class, ResourceSet.RESOURCE_SET__RESOURCES));
+ editingDomain.getResourceSet().eAdapters().add(new Adapter()
+ {
+ private Notifier myTarger;
+
+ public Notifier getTarget()
+ {
+ return myTarger;
+ }
+
+ public boolean isAdapterForType(Object type)
+ {
+ return false;
+ }
+
+ public void notifyChanged(Notification notification)
+ {
+ if (diagramResourceModifiedFilter.matches(notification))
+ {
+ Object value = notification.getNewValue();
+ if (value instanceof Resource)
+ {
+ ((Resource)value).setTrackingModification(true);
+ }
+ }
+ }
+
+ public void setTarget(Notifier newTarget)
+ {
+ myTarger = newTarget;
+ }
+ });
+
+ return editingDomain;
+ }
+
+
+ «EXPAND generatedComment -»
+ @Override
+ protected void setDocumentContent(IDocument document, IEditorInput element) throws CoreException
+ {
+ IDiagramDocument diagramDocument = (IDiagramDocument)document;
+ TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
+ if (element instanceof FileEditorInput)
+ {
+ IStorage storage = ((FileEditorInput)element).getStorage();
+ Diagram diagram = DiagramIOUtil.load(domain, storage, true, getProgressMonitor());
+ document.setContent(diagram);
+ }
+ else if (element instanceof URIEditorInput)
+ {
+ URIEditorInput editorInput = (URIEditorInput)element;
+
+ URI uri = editorInput.getURI();
+ Resource resource = null;
+ try
+ {
+ URI dawnURI = URI.createURI(uri.toString().replace("cdo", "dawn"));
+ resource = domain.getResourceSet().getResource(dawnURI, false);
+ if (resource == null)
+ {
+ resource = domain.getResourceSet().getResource(dawnURI, true);
+ }
+
+ if (editorInput instanceof DawnEditorInput)
+ {
+ ((DawnEditorInput)editorInput).setResource((CDOResource)resource);
+ }
+ if (!resource.isLoaded())
+ {
+ try
+ {
+ Map options = new HashMap(GMFResourceFactory.getDefaultLoadOptions());
+ resource.load(options);
+ }
+ catch (IOException e)
+ {
+ resource.unload();
+ throw e;
+ }
+ }
+ if (uri.fragment() != null)
+ {
+ EObject rootElement = resource.getEObject(uri.fragment());
+ if (rootElement instanceof Diagram)
+ {
+ Diagram diagram = (Diagram)rootElement;
+ DawnDiagramUpdater.initializeElement(diagram);
+ document.setContent(diagram);
+
+ return;
+ }
+ }
+ else
+ {
+ for (Iterator<?> it = resource.getContents().iterator(); it.hasNext();)
+ {
+ Object rootElement = it.next();
+ if (rootElement instanceof Diagram)
+ {
+ Diagram diagram = (Diagram)rootElement;
+ DawnDiagramUpdater.initializeElement(diagram);
+ document.setContent(diagram);
+
+ return;
+ }
+ }
+ }
+ throw new RuntimeException(Messages.ClassdiagramDocumentProvider_NoDiagramInResourceError);
+ }
+ catch (Exception e)
+ {
+ CoreException thrownExcp = null;
+ if (e instanceof CoreException)
+ {
+ thrownExcp = (CoreException)e;
+ }
+ else
+ {
+ String msg = e.getLocalizedMessage();
+ thrownExcp = new CoreException(new Status(IStatus.ERROR, «this.GMFGenEditorGenerator.plugin.activatorClassName».ID, 0,
+ msg != null ? msg : Messages.«this.GMFGenEditorGenerator.diagram.documentProviderClassName»_DiagramLoadingError, e));
+ }
+ throw thrownExcp;
+ }
+ }
+ else
+ {
+ throw new CoreException(new Status(IStatus.ERROR, ClassdiagramDiagramEditorPlugin.ID, 0, NLS.bind(
+ Messages.«this.GMFGenEditorGenerator.diagram.documentProviderClassName»_IncorrectInputError, new Object[] { element,
+ "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$
+ null));
+ }
+ }
+
+ «EXPAND generatedComment -»
+ @Override
+ public void changed(Object element)
+ {
+ if (element instanceof IEditorInput)
+ {
+ fireElementDirtyStateChanged(element, true);
+ }
+ }
+}
+«ENDFILE»
+«ENDDEFINE»
+
+
+«REM»############################################ DawnXXXEditPartProvider ##################################################################«ENDREM»
+«DEFINE dawnEditPartProvider FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/providers/"+this.dawnEditPartProviderClassName+".java"»
+package «this.GMFGenEditorGenerator.diagram.providersPackageName»;
+
+import «this.GMFGenEditorGenerator.diagram.editPartsPackageName».«this.dawnEditPartFactoryClassName»;
+import «this.GMFGenEditorGenerator.editor.packageName».«this.GMFGenEditorGenerator.plugin.activatorClassName»;
+
+«EXPAND generatedComment -»
+public class «this.dawnEditPartProviderClassName» extends «this.GMFGenEditorGenerator.diagram.editPartProviderClassName»
+{
+
+ «EXPAND generatedComment -»
+ public «this.dawnEditPartProviderClassName»()
+ {
+ super();
+ setFactory(new «this.dawnEditPartFactoryClassName»());
+ }
+}
+
+
+«ENDFILE»
+«ENDDEFINE»
+
+«REM»############################################ DawnXXXEditPolicyProvider ##################################################################«ENDREM»
+«DEFINE dawnEditPolicyProvider FOR DawnGMFGenerator»
+«FILE "src/"+getDiagramPackagePath()+"/providers/"+dawnEditPolicyProviderClassName+".java"»
+package «this.GMFGenEditorGenerator.diagram.providersPackageName»;
+
+import «this.GMFGenEditorGenerator.diagram.editPartsPackageName».«this.GMFGenEditorGenerator.diagram.editPartClassName»;
+import «this.GMFGenEditorGenerator.diagram.editPoliciesPackageName».«this.dawnCanonicalEditingPolicyClassName»;
+import «this.GMFGenEditorGenerator.editor.packageName».«this.GMFGenEditorGenerator.plugin.activatorClassName»;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+
+«EXPAND generatedComment -»
+public class «dawnEditPolicyProviderClassName» extends AbstractProvider implements IEditPolicyProvider
+{
+ public static String ID = "«this.GMFGenEditorGenerator.diagram.providersPackageName».«this.dawnEditPolicyProviderClassName»";
+
+ «EXPAND generatedComment -»
+ public boolean provides(IOperation operation)
+ {
+ if (operation instanceof CreateEditPoliciesOperation)
+ {
+ CreateEditPoliciesOperation editPoliciesOperation = (CreateEditPoliciesOperation)operation;
+ if (editPoliciesOperation.getEditPart() instanceof «this.GMFGenEditorGenerator.diagram.editPartClassName»)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ «EXPAND generatedComment -»
+ public void createEditPolicies(EditPart editPart)
+ {
+ if (editPart instanceof «this.GMFGenEditorGenerator.diagram.editPartClassName»)
+ {
+ editPart.installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new «this.dawnCanonicalEditingPolicyClassName»());
+ }
+ }
+}
+
+«ENDFILE»
+«ENDDEFINE»
+
+«REM»########################################## fragment.xml ####################################################################«ENDREM»
+«DEFINE fragmentXML FOR DawnGMFGenerator»
+«FILE "fragment.xml"»<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<fragment>
+<extension
+ point="org.eclipse.ui.editors">
+ <editor
+
+ class="«this.GMFGenEditorGenerator.editor.packageName».«this.dawnEditorClassName»"
+ contributorClass="«this.GMFGenEditorGenerator.editor.packageName».«this.GMFGenEditorGenerator.editor.actionBarContributorClassName»"
+ default="true"
+ extensions="«this.GMFGenEditorGenerator.diagramFileExtension»"
+ icon="«this.GMFGenEditorGenerator.editor.iconPath»"
+ id="«this.GMFGenEditorGenerator.editor.packageName».«this.dawnEditorClassName»"
+ matchingStrategy="«this.GMFGenEditorGenerator.editor.packageName».«this.GMFGenEditorGenerator.diagram.matchingStrategyClassName»"
+ name="Dawn «this.GMFGenEditorGenerator.modelID» Diagram">
+ </editor>
+ </extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <wizard
+ category="org.eclipse.ui.Examples"
+ class="«this.GMFGenEditorGenerator.editor.packageName».«this.dawnCreationWizardClassName»"
+ icon="«this.GMFGenEditorGenerator.editor.iconPath»"
+ id="«this.GMFGenEditorGenerator.editor.packageName».«this.dawnCreationWizardClassName»"
+ name="Dawn «this.GMFGenEditorGenerator.modelID» Diagram">
+ <description>
+ description body text
+ </description>
+ </wizard>
+
+ </extension>
+ <extension
+ point="org.eclipse.gmf.runtime.diagram.ui.resources.editor.documentProviders">
+ <provider
+ class="«this.GMFGenEditorGenerator.editor.packageName».«this.dawnDocumentProviderClassName»"
+ documentType="org.eclipse.gmf.runtime.diagram.ui.editor.IDocument"
+ id="«this.GMFGenEditorGenerator.editor.packageName».«this.dawnDocumentProviderClassName»"
+ inputTypes="org.eclipse.emf.common.ui.URIEditorInput">
+ </provider>
+ </extension>
+ <extension
+ point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
+ <editpolicyProvider
+ class="«this.GMFGenEditorGenerator.diagram.providersPackageName».«this.dawnEditPolicyProviderClassName»">
+ <Priority
+ name="Low">
+ </Priority>
+ </editpolicyProvider>
+ </extension>
+ <extension point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders" id="ep-provider">
+ <?gmfgen generated="true"?>
+ <editpartProvider class="«this.GMFGenEditorGenerator.diagram.providersPackageName».«this.dawnEditPartProviderClassName»">
+ <Priority name="Medium"/>
+ <object class="org.eclipse.gmf.runtime.notation.Diagram" id="generated-diagram">
+ <method name="getType()" value="«this.GMFGenEditorGenerator.modelID»"/>
+ </object>
+ <context views="generated-diagram"/>
+ </editpartProvider>
+ </extension>
+</fragment>
+
+«ENDFILE»
+«ENDDEFINE»
+
+
+
+«REM»##############################################################################################################«ENDREM»
+«DEFINE manifestMF FOR GenEditorGenerator»
+«FILE "META-INF/MANIFEST.MF"»Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Dawn
+Bundle-SymbolicName: org.eclipse.emf.cdo.dawn.reference.editor.diagram.dawn;singleton:=true
+Bundle-Version: 0.2.0.qualifier
+Fragment-Host: org.eclipse.emf.cdo.dawn.reference.editor.diagram;bundle-version="0.2.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.eclipse.emf.cdo.dawn.runtime;bundle-version="0.2.0",
+ org.eclipse.emf.cdo.dawn.util;bundle-version="0.0",
+ org.eclipse.emf.cdo.ui;bundle-version="3.0.0",
+ org.eclipse.emf.cdo.dawn.ui;bundle-version="0.2.0"
+Export-Package: org.eclipse.emf.cdo.dawn.reference.editor.classdiagram.diagram.edit.parts;version="0.2.0",
+ org.eclipse.emf.cdo.dawn.reference.editor.classdiagram.diagram.edit.policies;version="0.2.0",
+ org.eclipse.emf.cdo.dawn.reference.editor.classdiagram.diagram.part;version="0.2.0",
+ org.eclipse.emf.cdo.dawn.reference.editor.classdiagram.diagram.providers;version="0.2.0"
+«ENDFILE»
+«ENDDEFINE»
+
+
+«DEFINE buildPROPERTIES FOR GenEditorGenerator»
+«FILE "build.properties"»source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ fragment.xml
+«ENDFILE»
+«ENDDEFINE»
+«REM»################################### . classpath ###########################################################################«ENDREM»
+
+«DEFINE classpath FOR GenEditorGenerator»
+«FILE ".classpath"»<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
+«ENDFILE»
+«ENDDEFINE»
+
+«DEFINE generatedComment FOR Object-»
+/**
+ *@generated
+ */
+ «ENDDEFINE»
+
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/template/GeneratorExtensions.ext b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/template/GeneratorExtensions.ext
new file mode 100644
index 0000000000..a09f8d3b2f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/template/GeneratorExtensions.ext
@@ -0,0 +1,3 @@
+
+
+
diff --git a/plugins/org.eclipse.emf.cdo.dawn.codegen/src/workflow/gmfFragmentGenerator.oaw b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/workflow/gmfFragmentGenerator.oaw
new file mode 100644
index 0000000000..82afa8e03f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.dawn.codegen/src/workflow/gmfFragmentGenerator.oaw
@@ -0,0 +1,91 @@
+<?xml version="1.0"?>
+<!--
+ Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ Martin Fluegge - initial API and implementation
+-->
+
+<workflow>
+
+ <!--<property name="model" value="file:/D:/Development/CDO/org.eclipse.emf.cdo.dawn.reference.editor/model/classdiagram.gmfgen" />-->
+ <property name="model" value="file:/D:/Development/INSTANCES/Dawn_Instance1/Dawn/model/classdiagram.dawngenmodel" />
+
+ <property name="src-gen" value="d:/temp/source" />
+ <!--<property name="src-gen" /> --> <!--just declare it to make it accessable -->
+
+ <!-- set up EMF for standalone execution -->
+ <bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
+ <platformUri value=".."/>
+ </bean>
+
+ <!-- load model and store it in slot 'model' -->
+ <component class="org.eclipse.emf.mwe.utils.Reader">
+ <uri value="${model}" />
+ <modelSlot value="model" />
+ </component>
+
+
+
+ <!-- check model -->
+ <!--loads different metamodels-->
+ <component class="org.eclipse.xtend.check.CheckComponent">
+ <metaModel id="ecore" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.emf.ecore.EcorePackage"/>
+ </metaModel>
+
+ <metaModel id="genmodel" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage"/>
+ </metaModel>
+
+ <metaModel id="dawngenmodel" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawngenmodelPackage"/>
+ </metaModel>
+
+ <metaModel id="mmGGr" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.gmf.gmfgraph.GMFGraphPackage"/>
+ </metaModel>
+
+ <metaModel id="mmGGen" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.gmf.codegen.gmfgen.GMFGenPackage"/>
+ </metaModel>
+ <checkFile value="metamodel::Checks" />
+ <emfAllChildrenSlot value="model" />
+ </component>
+
+ <!-- generate code for the meta specified templates -->
+ <component class="org.eclipse.xpand2.Generator">
+
+ <metaModel id="ecore" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.emf.ecore.EcorePackage"/>
+ </metaModel>
+
+ <metaModel id="genmodel" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage"/>
+ </metaModel>
+
+ <metaModel id="dawngenmodel" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.emf.cdo.dawn.codegen.dawngenmodel.DawngenmodelPackage"/>
+ </metaModel>
+
+ <metaModel id="mmGGr" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.gmf.gmfgraph.GMFGraphPackage"/>
+ </metaModel>
+
+ <metaModel id="mmGGen" class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
+ <metaModelPackage value="org.eclipse.gmf.codegen.gmfgen.GMFGenPackage"/>
+ </metaModel>
+
+ <expand value="template::GMFFragmentTemplate::main FOR model" />
+ <outlet path="${src-gen}" >
+ <postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
+ </outlet>
+
+ <!--<prSrcPaths value="${src-gen}"/>
+ <prExcludes value=", *.xml, *.hbm"/>-->
+ </component>
+</workflow>

Back to the top