Przeglądaj źródła

Create Wizard for generic Xpand Generators

holger.willebrandt@gmail.com 14 lat temu
rodzic
commit
c8a22b53f7

+ 40 - 34
plugins/org.yakindu.sct.generator.genmodel.ui/.project

@@ -1,34 +1,40 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
-	<name>org.yakindu.sct.generator.genmodel.ui</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.pde.ManifestBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.pde.SchemaBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>org.eclipse.pde.PluginNature</nature>
-		<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
-	</natures>
-</projectDescription>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.generator.genmodel.ui</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.xtend.shared.ui.xtendBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+		<nature>org.eclipse.xtend.shared.ui.xtendXPandNature</nature>
+	</natures>
+</projectDescription>

+ 4 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,4 @@
+#Thu Nov 24 11:01:00 CET 2011
+eclipse.preferences.version=1
+encoding//src/org/yakindu/sct/generator/genmodel/ui/wizard/DefaultTemplate.xpt=ISO-8859-1
+encoding//xtend-gen/org/yakindu/sct/generator/genmodel/ui/wizard/ProjectTemplate.java=UTF-8

+ 3 - 1
plugins/org.yakindu.sct.generator.genmodel.ui/META-INF/MANIFEST.MF

@@ -24,7 +24,9 @@ Require-Bundle: org.yakindu.sct.generator.genmodel;visibility:=reexport,
  org.eclipse.xtext.xtend2;bundle-version="2.0.0",
  org.eclipse.xtext.xtend2.lib;bundle-version="2.0.0",
  org.yakindu.sct.ui.editor;bundle-version="1.0.0",
- org.eclipse.xtext.xbase.ui
+ org.eclipse.xtend.shared.ui;bundle-version="1.0.1",
+ org.eclipse.xtext.xbase.ui,
+ org.apache.commons.lang;bundle-version="2.4.0"
 Import-Package: org.apache.log4j,
  org.apache.commons.logging
 Bundle-RequiredExecutionEnvironment: J2SE-1.5

+ 8 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/plugin.xml

@@ -215,6 +215,14 @@
             name="YAKINDU Statechart Generator Model"
             project="false">
       </wizard>
+      <wizard
+            category="YAKINDU"
+            class="org.yakindu.sct.generator.genmodel.ui.SGenExecutableExtensionFactory:org.yakindu.sct.generator.genmodel.ui.wizard.XpandGeneratorProjectWizard"
+            icon="icons/GenModel-16.png"
+            id="org.yakindu.sct.generator.genmodel.ui.XtendGeneratorProjectWizard"
+            name="YAKINDU Xpand Generator Project"
+            project="true">
+      </wizard>
    </extension>
 
   <extension point="org.eclipse.compare.contentViewers">

+ 16 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/wizard/DefaultTemplate.xpt

@@ -0,0 +1,16 @@
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+«IMPORT sgen»
+
+«DEFINE main(sgen::GeneratorEntry entry) FOR sexec::ExecutionFlow-»
+«FILE this.name+'.txt' -»
+The name of the Statemachine is '«this.name-»'
+
+The Statemachine has the following states:
+
+«FOREACH this.states AS state-»
+«state.name.replaceFirst(this.name+'\\.','')»
+«ENDFOREACH-»
+«ENDFILE-»
+«ENDDEFINE»

+ 61 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/wizard/ProjectData.java

@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.generator.genmodel.ui.wizard;
+
+import org.eclipse.core.resources.IProject;
+
+/**
+ * 
+ * @author holger willebrandt - Initial contribution and API
+ */
+public class ProjectData {
+	IProject project;
+	boolean pluginExport;
+	boolean typeLibrary;
+	String projectName;
+	String generatorId;
+	String generatorDescription;
+	String generatorName;
+	String generatorClass;
+
+	public boolean isPluginExport() {
+		return pluginExport;
+	}
+
+	public boolean isTypeLibrary() {
+		return typeLibrary;
+	}
+
+	public String getProjectName() {
+		return projectName;
+	}
+
+	public String getGeneratorId() {
+		return generatorId;
+	}
+
+	public String getGeneratorDescription() {
+		return generatorDescription;
+	}
+
+	public String getGeneratorName() {
+		return generatorName;
+	}
+
+	public IProject getProject() {
+		return project;
+	}
+
+	public String getGeneratorClass() {
+		return generatorClass;
+	}
+
+}

+ 210 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/wizard/ProjectTemplate.xtend

@@ -0,0 +1,210 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.generator.genmodel.ui.wizard
+
+import org.eclipse.xtext.generator.IGenerator
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.xtext.generator.IFileSystemAccess
+import org.eclipse.core.runtime.IProgressMonitor
+import org.eclipse.core.resources.IContainer
+import org.eclipse.core.runtime.Path
+import org.eclipse.core.resources.IFolder
+import org.eclipse.core.resources.IResource
+import org.eclipse.xtend.shared.ui.wizards.EclipseHelper
+import org.eclipse.core.resources.ResourcesPlugin
+import org.apache.commons.lang.StringEscapeUtils
+/**
+ * 
+ * @author holger willebrandt - Initial contribution and API
+ */
+class ProjectTemplate {
+	
+	def doGenerate(ProjectData data, IProgressMonitor monitor) {
+		var folderPath = 'src/'+data.targetPackage.asFolder
+		createFolder(folderPath,data.project, monitor)
+		var generatorFolder = data.project.getFolder(new Path(folderPath))
+		
+		EclipseHelper::createFile('.settings/org.eclipse.core.resources.prefs',data.project,
+			data.projectSettings(ResourcesPlugin::encoding).toString,monitor)
+		
+		EclipseHelper::createFile('.settings/org.eclipse.xtend.shared.ui.prefs',data.project,
+			data.xpandSettings.toString,monitor)
+		
+		EclipseHelper::createFile(data.templateName+'.xpt',generatorFolder,
+			resource('DefaultTemplate.xpt','iso-8859-1'),monitor)
+		
+		if (data.pluginExport) {
+			EclipseHelper::createFile('plugin.xml',data.project,data.plugin.toString,monitor)
+			EclipseHelper::createFile('src/'+data.generatorClass.javaFilename,data.project,data.generator.toString,monitor)
+			if (data.typeLibrary) {
+				createFolder('library', data.project, monitor)
+				//TODO create FeatureTypeLibrary.xmi							
+			}
+			EclipseHelper::createFile('build.properties',data.project,data.buildProperties.toString,monitor)
+		}
+	}
+	
+	
+	def templateName(ProjectData data) {
+		if (data.pluginExport)
+			data.generatorClass.simpleName
+		else
+			'Main'
+	}
+	
+	def resource(String name, String encoding) {
+		XpandGeneratorProjectWizard::getResourceContents(name,encoding)
+	}
+	
+	def targetPackage(ProjectData data) {
+		if (data.pluginExport)
+			data.generatorClass.packageName
+		else
+			'org.yakindu.sct.generator.xpand'
+	}
+	
+	def asFolder(String s) {
+		s.replaceAll('\\.','/')
+	}
+	
+	def javaPathToXpand(String s) {
+		s.replaceAll('\\.','::')
+	}
+	
+	def simpleName(String s) {
+		s.substring(s.lastIndexOf('.')+1)
+	}
+	
+	def packageName(String s) {
+		s.substring(0, s.lastIndexOf('.'))	
+	}
+	
+	def providerClass(ProjectData data){
+		data.generatorClass+'DefaultValueProvider'
+	}
+	
+	def javaFilename(String s) {
+		s.replaceAll('\\.','/')+'.java'
+	}
+	
+	def createFolder(String folderPath, IContainer container,
+			IProgressMonitor monitor) {
+		createFolderHierarchy(container.getFolder(new Path(folderPath)), monitor);
+	}
+
+	 def createFolderHierarchy(IFolder folder, IProgressMonitor monitor) {
+		if (!folder.exists) {
+			if (!folder.parent.exists
+					&& folder.parent.type == IResource::FOLDER) {
+				createFolderHierarchy(folder.parent as IFolder, monitor);
+			}
+			folder.create(true, true, monitor);
+		}
+	}
+	
+	def escapeForXml(String s) {
+		StringEscapeUtils::escapeXml(s)
+	}
+	
+	
+	def plugin(ProjectData data) '''
+		<?xml version="1.0" encoding="UTF-8"?>
+		<?eclipse version="3.4"?>
+		<plugin>
+		   <extension
+		         point="org.yakindu.sct.generator.core.generator">
+		      <SCTGenerator class="«data.generatorClass»"
+		            description="«data.generatorDescription.escapeForXml»"
+		            id="«data.generatorId»"
+		            name="«data.generatorName.escapeForXml»">
+		      </SCTGenerator>
+		   </extension>
+		«IF data.typeLibrary»
+		   <extension
+		         point="org.yakindu.sct.generator.core.featuretypes">
+		      <FeatureLibrary generatorId="«data.generatorId»" 
+		      defaultProvider="«data.providerClass»"
+		            uri="platform:/plugin/«data.project.name»/library/FeatureTypeLibrary.xmi">
+		      </FeatureLibrary>
+		   </extension>
+		«ENDIF»   
+		</plugin>
+	'''
+	
+	def generator(ProjectData data) '''
+		package «data.generatorClass.packageName»;
+		
+		import org.yakindu.sct.generator.core.impl.AbstractXpandBasedCodeGenerator;
+		
+		/**
+		 * Generator using Xpand template "«data.generatorClass.javaPathToXpand»::main"
+		 */
+		public class «data.generatorClass.simpleName» extends AbstractXpandBasedCodeGenerator {
+		
+			@Override
+			public String getTemplatePath() {
+				return "«data.generatorClass.javaPathToXpand»::main";
+			}
+		}
+	'''
+	
+	def defaultProvider(ProjectData data) '''
+		package «data.providerClass.packageName»;
+		
+		import org.yakindu.sct.generator.core.features.AbstractDefaultFeatureValueProvider;
+		
+		/**
+		 * Default value proivder for «data.generatorName» feature library
+		 */
+		public class «data.providerClass.simpleName» extends AbstractDefaultFeatureValueProvider {
+		
+			private static final String LIBRARY_NAME = "«data.generatorName»";
+			
+			@Override
+			protected void setDefaultValue(FeatureParameterValue parameterValue,
+					Statechart statechart) {
+				String parameterName = parameterValue.getParameter().getName();
+				//TODO: set the default values
+			}
+		
+			public boolean isProviderFor(FeatureTypeLibrary library) {
+				return library.getName().equals(LIBRARY_NAME);
+			}
+		
+			public IStatus validateParameterValue(FeatureParameterValue value) {
+				String name = value.getParameter().getName();
+				//TODO implement validation
+				return Status.OK_STATUS;
+			}
+		}
+	'''
+	
+	def projectSettings(ProjectData data, String encoding) '''
+	eclipse.preferences.version=1
+	encoding/<project>=«encoding»
+	
+	'''
+
+	def xpandSettings(ProjectData data) '''
+	eclipse.preferences.version=1
+	project.specific.metamodel=true
+	metamodelContributor=org.eclipse.xtend.typesystem.emf.ui.EmfMetamodelContributor
+	
+	'''
+	
+	def buildProperties(ProjectData data) '''
+		source.. = src/,\
+		           src-gen
+		bin.includes = META-INF/,\
+		               .,\
+		               plugin.xml
+	'''
+ }

+ 163 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/wizard/XpandGeneratorProjectWizard.java

@@ -0,0 +1,163 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.generator.genmodel.ui.wizard;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.eclipse.xtend.shared.ui.wizards.EclipseHelper;
+
+/**
+ * 
+ * @author holger willebrandt - Initial contribution and API
+ */
+public class XpandGeneratorProjectWizard extends Wizard implements
+		IWorkbenchWizard {
+
+	private XpandGeneratorWizardPage1 projectPage;
+	private final ProjectTemplate template = new ProjectTemplate();
+
+	public void init(IWorkbench workbench, IStructuredSelection selection) {
+		setWindowTitle("New YAKINDU Xpand Generator Project");
+		setNeedsProgressMonitor(true);
+	}
+
+	@Override
+	public void addPages() {
+		projectPage = new XpandGeneratorWizardPage1("project"); //$NON-NLS-1$
+		projectPage.setTitle("New YAKINDU Xpand Generator Project");
+		projectPage.setDescription("Configure the Generator Project");
+		addPage(projectPage);
+	}
+
+	@Override
+	public boolean performFinish() {
+
+		final ProjectData projectData = projectPage.getProjectData();
+
+		final IRunnableWithProgress op = new IRunnableWithProgress() {
+			public void run(final IProgressMonitor monitor)
+					throws InvocationTargetException {
+				try {
+					doCreateProject(projectData, monitor);
+				} catch (CoreException e) {
+					e.printStackTrace();
+				} finally {
+					monitor.done();
+				}
+			}
+		};
+		try {
+			getContainer().run(true, false, op);
+		} catch (final InterruptedException e) {
+			return false;
+		} catch (final InvocationTargetException e) {
+			final Throwable realException = e.getTargetException();
+			MessageDialog.openError(getShell(), "Failed to create project",
+					realException.getMessage());
+			return false;
+		}
+		return true;
+	}
+
+	protected void doCreateProject(ProjectData projectData,
+			IProgressMonitor monitor) throws CoreException {
+		int ticks = projectData.pluginExport ? 10 : 7;
+		monitor.beginTask("Create YAKINDU Xpand Generator Project", ticks);
+
+		final IProject project = initProject(projectData.projectName,
+				projectData.pluginExport, monitor);
+
+		if (project == null) {
+			return;
+		}
+
+		projectData.project = project;
+
+		template.doGenerate(projectData, monitor);
+
+		project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+	}
+
+	protected IProject initProject(String projectName, boolean pluginExport,
+			IProgressMonitor monitor) {
+		List<IProject> referencedProjects = Collections.emptyList();
+		List<String> exportedPackages = Collections.emptyList();
+		final List<String> srcFolders = new ArrayList<String>();
+		srcFolders.add("src"); //$NON-NLS-1$
+		srcFolders.add("src-gen"); //$NON-NLS-1$
+		final Set<String> requiredBundles = new HashSet<String>();
+		requiredBundles.add("org.eclipse.jdt.core;bundle-version=\"3.5.0\"");//$NON-NLS-1$
+		requiredBundles.add("org.apache.commons.logging");//$NON-NLS-1$
+		requiredBundles.add("org.apache.log4j;resolution:=optional");//$NON-NLS-1$
+		requiredBundles.add("org.eclipse.xtend.profiler;resolution:=optional");//$NON-NLS-1$
+		requiredBundles
+				.add("org.yakindu.sct.model.sexec;bundle-version=\"1.0.0\"");//$NON-NLS-1$
+		requiredBundles
+				.add("org.yakindu.sct.model.sgen;bundle-version=\"1.0.0\"");//$NON-NLS-1$
+		requiredBundles
+				.add("org.yakindu.sct.model.sgraph;bundle-version=\"1.0.0\"");//$NON-NLS-1$
+		requiredBundles
+				.add("org.yakindu.sct.model.stext;bundle-version=\"1.0.0\"");//$NON-NLS-1$
+		if (pluginExport) {
+			requiredBundles
+					.add("org.yakindu.sct.generator.core;bundle-version=\"1.0.0\"");//$NON-NLS-1$
+		}
+
+		IProject project = EclipseHelper.createExtXptProject(projectName,
+				srcFolders, referencedProjects, requiredBundles,
+				exportedPackages, new SubProgressMonitor(monitor, 3),
+				getShell());
+		return project;
+	}
+
+	public static String getResourceContents(final String resource,
+			String encoding) {
+		try {
+			final InputStream inputStream = XpandGeneratorProjectWizard.class
+					.getResourceAsStream(resource);
+			final byte[] buffer = new byte[4096];
+			final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+			while (true) {
+				int read;
+				read = inputStream.read(buffer);
+				if (read == -1) {
+					break;
+				}
+				outputStream.write(buffer, 0, read);
+			}
+			outputStream.close();
+			inputStream.close();
+			return outputStream.toString(encoding);
+		} catch (final IOException e) {
+			e.printStackTrace();
+			return "";
+		}
+	}
+}

+ 219 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/wizard/XpandGeneratorWizardPage1.java

@@ -0,0 +1,219 @@
+package org.yakindu.sct.generator.genmodel.ui.wizard;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class XpandGeneratorWizardPage1 extends WizardPage {
+	// (ID::)+ID
+	private static final String GENERATOR_ID_REGEX = "([a-zA-Z_][a-zA-Z0-9_]*::)+[a-zA-Z_][a-zA-Z0-9_]*"; //$NON-NLS-1$
+	private static final String GENERATOR_CLASS_REGEX = "([a-zA-Z_][a-zA-Z0-9_]*\\.)+[a-zA-Z_][a-zA-Z0-9_]*"; //$NON-NLS-1$
+	// project will be an OSGI bundle, so there are some name restrictions
+	private static final String PROJECT_REGEX = "[A-Za-z0-9\\._]"; //$NON-NLS-1$
+	private Group generatorGroup;
+	private Text txtGeneratorDesc;
+	private Text txtGeneratorId;
+	private Button cbGenerator;
+	private Text txtProjectName;
+	private Button cbLibrary;
+	private Text txtGeneratorName;
+	private Text txtGeneratorClass;
+	private final KeyListenerAdapter textBoxListener = new KeyListenerAdapter() {
+
+		@Override
+		public void keyReleased(KeyEvent e) {
+			validate();
+		}
+	};
+
+	protected XpandGeneratorWizardPage1(String pageName) {
+		super(pageName);
+	}
+
+	public void createControl(Composite container) {
+		Composite parent = new Composite(container, SWT.NULL);
+		setControl(parent);
+		parent.setLayout(new GridLayout(1, false));
+
+		Composite projectNameGroup = new Composite(parent, SWT.NULL);
+		projectNameGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
+				false, 1, 1));
+		projectNameGroup.setLayout(new GridLayout(2, false));
+
+		Label lblProjectName = new Label(projectNameGroup, SWT.WRAP);
+		lblProjectName.setText("Project name:");
+		txtProjectName = new Text(projectNameGroup, SWT.SINGLE | SWT.BORDER);
+		txtProjectName.addKeyListener(textBoxListener);
+		GridDataFactory.fillDefaults().grab(true, false)
+				.applyTo(txtProjectName);
+
+		Composite generatorCheckboxGroup = new Composite(parent, SWT.NULL);
+		generatorCheckboxGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP,
+				true, false, 1, 1));
+		generatorCheckboxGroup.setLayout(new GridLayout(2, false));
+
+		Label lblGeneratorCheckBox = new Label(generatorCheckboxGroup, SWT.WRAP);
+		lblGeneratorCheckBox.setText("Configure for Plugin Export");
+		cbGenerator = new Button(generatorCheckboxGroup, SWT.CHECK);
+		cbGenerator.addSelectionListener(new SelectionListenerAdapter() {
+
+			public void widgetSelected(SelectionEvent e) {
+				setGeneratorGroupEnabled(cbGenerator.getSelection());
+				validate();
+			}
+		});
+
+		generatorGroup = new Group(parent, SWT.NONE);
+		generatorGroup.setLayout(new GridLayout(2, false));
+		generatorGroup.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
+				false, 1, 1));
+
+		Label lblGeneratorId = new Label(generatorGroup, SWT.WRAP);
+		lblGeneratorId.setText("Generator Id:");
+
+		txtGeneratorId = new Text(generatorGroup, SWT.SINGLE | SWT.BORDER);
+		txtGeneratorId.setText("custom::xpand");
+		txtGeneratorId.addKeyListener(textBoxListener);
+		GridDataFactory.fillDefaults().grab(true, false)
+				.applyTo(txtGeneratorId);
+
+		Label lblGeneratorName = new Label(generatorGroup, SWT.WRAP);
+		lblGeneratorName.setText("Generator name:");
+
+		txtGeneratorName = new Text(generatorGroup, SWT.SINGLE | SWT.BORDER);
+		txtGeneratorName.addKeyListener(textBoxListener);
+		GridDataFactory.fillDefaults().grab(true, false)
+				.applyTo(txtGeneratorName);
+
+		Label lblGeneratorClass = new Label(generatorGroup, SWT.WRAP);
+		lblGeneratorClass.setText("Generator class:");
+
+		txtGeneratorClass = new Text(generatorGroup, SWT.SINGLE | SWT.BORDER);
+		txtGeneratorClass.addKeyListener(textBoxListener);
+		GridDataFactory.fillDefaults().grab(true, false)
+				.applyTo(txtGeneratorClass);
+
+		Label lblGeneratorDesc = new Label(generatorGroup, SWT.WRAP);
+		lblGeneratorDesc.setText("Generator description:");
+
+		txtGeneratorDesc = new Text(generatorGroup, SWT.SINGLE | SWT.BORDER);
+		txtGeneratorDesc.addKeyListener(textBoxListener);
+		GridDataFactory.fillDefaults().grab(true, false)
+				.applyTo(txtGeneratorDesc);
+
+		Label lblLibraryCheckBox = new Label(generatorGroup, SWT.WRAP);
+		lblLibraryCheckBox.setText("Create Fetaure Library");
+		lblLibraryCheckBox.setVisible(false);
+		cbLibrary = new Button(generatorGroup, SWT.CHECK);
+		cbLibrary.setVisible(false);
+
+		setGeneratorGroupEnabled(false);
+		setPageComplete(false);
+	}
+
+	protected final void validate() {
+		setPageComplete(checkPageComplete());
+	}
+
+	protected boolean checkPageComplete() {
+		boolean complete = checkProjectName() && checkGeneratorOptions();
+		if (complete) {
+			setErrorMessage(null);
+		}
+		return complete;
+	}
+
+	private boolean checkProjectName() {
+		if (txtProjectName.getText().isEmpty()) {
+			setErrorMessage("Project name must be set");
+			return false;
+		}
+		if (!txtProjectName.getText().matches(PROJECT_REGEX)) {
+			setErrorMessage("Invalid Project name");
+			return false;
+		}
+		if (ResourcesPlugin.getWorkspace().getRoot()
+				.getProject(txtProjectName.getText()).exists()) {
+			setErrorMessage("Project already exists");
+			return false;
+		}
+		return true;
+	}
+
+	private boolean checkGeneratorOptions() {
+		if (generatorGroup.isEnabled()) {
+			if (txtGeneratorId.getText().isEmpty()) {
+				setErrorMessage("Generator Id must be set");
+				return false;
+			}
+			if (!txtGeneratorId.getText().matches(GENERATOR_ID_REGEX)) {
+				setErrorMessage("Invalid Generator Id");
+				return false;
+			}
+			if (txtGeneratorName.getText().isEmpty()) {
+				setErrorMessage("Generator name must be set");
+				return false;
+			}
+			if (txtGeneratorClass.getText().isEmpty()) {
+				setErrorMessage("Generator class must be set");
+				return false;
+			}
+			if (!txtGeneratorClass.getText().matches(GENERATOR_CLASS_REGEX)) {
+				setErrorMessage("Generator class must be a full qualified java identifier");
+				return false;
+			}
+		}
+		return true;
+	}
+
+	protected void setGeneratorGroupEnabled(boolean enabled) {
+		generatorGroup.setEnabled(enabled);
+		txtGeneratorId.setEnabled(enabled);
+		txtGeneratorName.setEnabled(enabled);
+		txtGeneratorDesc.setEnabled(enabled);
+		cbLibrary.setEnabled(enabled);
+	}
+
+	public ProjectData getProjectData() {
+		ProjectData data = new ProjectData();
+		data.projectName = txtProjectName.getText().trim();
+		data.generatorClass = txtGeneratorClass.getText().trim();
+		data.generatorDescription = txtGeneratorDesc.getText().trim();
+		data.generatorId = txtGeneratorId.getText().trim();
+		data.generatorName = txtGeneratorName.getText().trim();
+		data.pluginExport = cbGenerator.getSelection();
+		data.typeLibrary = cbLibrary.getSelection();
+		return data;
+	}
+	static abstract class SelectionListenerAdapter implements SelectionListener {
+
+		public void widgetDefaultSelected(SelectionEvent e) {
+			widgetSelected(e);
+		}
+	}
+
+	static abstract class KeyListenerAdapter implements KeyListener {
+
+		public void keyPressed(KeyEvent e) {
+			// empty
+		}
+
+		public void keyReleased(KeyEvent e) {
+			// empty
+		}
+
+	}
+
+}

+ 455 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/xtend-gen/org/yakindu/sct/generator/genmodel/ui/wizard/ProjectTemplate.java

@@ -0,0 +1,455 @@
+package org.yakindu.sct.generator.genmodel.ui.wizard;
+
+import org.apache.commons.lang.StringEscapeUtils;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.xtend.shared.ui.wizards.EclipseHelper;
+import org.eclipse.xtext.xbase.lib.BooleanExtensions;
+import org.eclipse.xtext.xbase.lib.IntegerExtensions;
+import org.eclipse.xtext.xbase.lib.ObjectExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+import org.yakindu.sct.generator.genmodel.ui.wizard.ProjectData;
+import org.yakindu.sct.generator.genmodel.ui.wizard.XpandGeneratorProjectWizard;
+
+@SuppressWarnings("all")
+public class ProjectTemplate {
+  
+  public IFile doGenerate(final ProjectData data, final IProgressMonitor monitor) throws CoreException {
+    IFile _xblockexpression = null;
+    {
+      String _targetPackage = this.targetPackage(data);
+      String _asFolder = this.asFolder(_targetPackage);
+      String _operator_plus = StringExtensions.operator_plus("src/", _asFolder);
+      String folderPath = _operator_plus;
+      IProject _project = data.getProject();
+      this.createFolder(folderPath, _project, monitor);
+      IProject _project_1 = data.getProject();
+      Path _path = new Path(folderPath);
+      IFolder _folder = _project_1.getFolder(_path);
+      IFolder generatorFolder = _folder;
+      IProject _project_2 = data.getProject();
+      String _encoding = ResourcesPlugin.getEncoding();
+      StringConcatenation _projectSettings = this.projectSettings(data, _encoding);
+      String _string = _projectSettings.toString();
+      EclipseHelper.createFile(".settings/org.eclipse.core.resources.prefs", _project_2, _string, monitor);
+      IProject _project_3 = data.getProject();
+      StringConcatenation _xpandSettings = this.xpandSettings(data);
+      String _string_1 = _xpandSettings.toString();
+      EclipseHelper.createFile(".settings/org.eclipse.xtend.shared.ui.prefs", _project_3, _string_1, monitor);
+      String _templateName = this.templateName(data);
+      String _operator_plus_1 = StringExtensions.operator_plus(_templateName, ".xpt");
+      String _resource = this.resource("DefaultTemplate.xpt", "iso-8859-1");
+      EclipseHelper.createFile(_operator_plus_1, generatorFolder, _resource, monitor);
+      IFile _xifexpression = null;
+      boolean _isPluginExport = data.isPluginExport();
+      if (_isPluginExport) {
+        IFile _xblockexpression_1 = null;
+        {
+          IProject _project_4 = data.getProject();
+          StringConcatenation _plugin = this.plugin(data);
+          String _string_2 = _plugin.toString();
+          EclipseHelper.createFile("plugin.xml", _project_4, _string_2, monitor);
+          String _generatorClass = data.getGeneratorClass();
+          String _javaFilename = this.javaFilename(_generatorClass);
+          String _operator_plus_2 = StringExtensions.operator_plus("src/", _javaFilename);
+          IProject _project_5 = data.getProject();
+          StringConcatenation _generator = this.generator(data);
+          String _string_3 = _generator.toString();
+          EclipseHelper.createFile(_operator_plus_2, _project_5, _string_3, monitor);
+          boolean _isTypeLibrary = data.isTypeLibrary();
+          if (_isTypeLibrary) {
+            IProject _project_6 = data.getProject();
+            this.createFolder("library", _project_6, monitor);
+          }
+          IProject _project_7 = data.getProject();
+          StringConcatenation _buildProperties = this.buildProperties(data);
+          String _string_4 = _buildProperties.toString();
+          IFile _createFile = EclipseHelper.createFile("build.properties", _project_7, _string_4, monitor);
+          _xblockexpression_1 = (_createFile);
+        }
+        _xifexpression = _xblockexpression_1;
+      }
+      _xblockexpression = (_xifexpression);
+    }
+    return _xblockexpression;
+  }
+  
+  public String templateName(final ProjectData data) {
+    String _xifexpression = null;
+    boolean _isPluginExport = data.isPluginExport();
+    if (_isPluginExport) {
+      String _generatorClass = data.getGeneratorClass();
+      String _simpleName = this.simpleName(_generatorClass);
+      _xifexpression = _simpleName;
+    } else {
+      _xifexpression = "Main";
+    }
+    return _xifexpression;
+  }
+  
+  public String resource(final String name, final String encoding) {
+    String _resourceContents = XpandGeneratorProjectWizard.getResourceContents(name, encoding);
+    return _resourceContents;
+  }
+  
+  public String targetPackage(final ProjectData data) {
+    String _xifexpression = null;
+    boolean _isPluginExport = data.isPluginExport();
+    if (_isPluginExport) {
+      String _generatorClass = data.getGeneratorClass();
+      String _packageName = this.packageName(_generatorClass);
+      _xifexpression = _packageName;
+    } else {
+      _xifexpression = "org.yakindu.sct.generator.xpand";
+    }
+    return _xifexpression;
+  }
+  
+  public String asFolder(final String s) {
+    String _replaceAll = s.replaceAll("\\.", "/");
+    return _replaceAll;
+  }
+  
+  public String javaPathToXpand(final String s) {
+    String _replaceAll = s.replaceAll("\\.", "::");
+    return _replaceAll;
+  }
+  
+  public String simpleName(final String s) {
+    int _lastIndexOf = s.lastIndexOf(".");
+    int _operator_plus = IntegerExtensions.operator_plus(((Integer)_lastIndexOf), ((Integer)1));
+    String _substring = s.substring(_operator_plus);
+    return _substring;
+  }
+  
+  public String packageName(final String s) {
+    int _lastIndexOf = s.lastIndexOf(".");
+    String _substring = s.substring(0, _lastIndexOf);
+    return _substring;
+  }
+  
+  public String providerClass(final ProjectData data) {
+    String _generatorClass = data.getGeneratorClass();
+    String _operator_plus = StringExtensions.operator_plus(_generatorClass, "DefaultValueProvider");
+    return _operator_plus;
+  }
+  
+  public String javaFilename(final String s) {
+    String _replaceAll = s.replaceAll("\\.", "/");
+    String _operator_plus = StringExtensions.operator_plus(_replaceAll, ".java");
+    return _operator_plus;
+  }
+  
+  public Object createFolder(final String folderPath, final IContainer container, final IProgressMonitor monitor) throws CoreException {
+    Path _path = new Path(folderPath);
+    IFolder _folder = container.getFolder(_path);
+    Object _createFolderHierarchy = this.createFolderHierarchy(_folder, monitor);
+    return _createFolderHierarchy;
+  }
+  
+  public Object createFolderHierarchy(final IFolder folder, final IProgressMonitor monitor) throws CoreException {
+    Object _xifexpression = null;
+    boolean _exists = folder.exists();
+    boolean _operator_not = BooleanExtensions.operator_not(_exists);
+    if (_operator_not) {
+      {
+        boolean _operator_and = false;
+        IContainer _parent = folder.getParent();
+        boolean _exists_1 = _parent.exists();
+        boolean _operator_not_1 = BooleanExtensions.operator_not(_exists_1);
+        if (!_operator_not_1) {
+          _operator_and = false;
+        } else {
+          IContainer _parent_1 = folder.getParent();
+          int _type = _parent_1.getType();
+          boolean _operator_equals = ObjectExtensions.operator_equals(((Integer)_type), ((Integer)IResource.FOLDER));
+          _operator_and = BooleanExtensions.operator_and(_operator_not_1, _operator_equals);
+        }
+        if (_operator_and) {
+          IContainer _parent_2 = folder.getParent();
+          this.createFolderHierarchy(((IFolder) _parent_2), monitor);
+        }
+        folder.create(true, true, monitor);
+      }
+    }
+    return _xifexpression;
+  }
+  
+  public String escapeForXml(final String s) {
+    String _escapeXml = StringEscapeUtils.escapeXml(s);
+    return _escapeXml;
+  }
+  
+  public StringConcatenation plugin(final ProjectData data) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+    _builder.newLine();
+    _builder.append("<?eclipse version=\"3.4\"?>");
+    _builder.newLine();
+    _builder.append("<plugin>");
+    _builder.newLine();
+    _builder.append("   ");
+    _builder.append("<extension");
+    _builder.newLine();
+    _builder.append("         ");
+    _builder.append("point=\"org.yakindu.sct.generator.core.generator\">");
+    _builder.newLine();
+    _builder.append("      ");
+    _builder.append("<SCTGenerator class=\"");
+    String _generatorClass = data.getGeneratorClass();
+    _builder.append(_generatorClass, "      ");
+    _builder.append("\"");
+    _builder.newLineIfNotEmpty();
+    _builder.append("            ");
+    _builder.append("description=\"");
+    String _generatorDescription = data.getGeneratorDescription();
+    String _escapeForXml = this.escapeForXml(_generatorDescription);
+    _builder.append(_escapeForXml, "            ");
+    _builder.append("\"");
+    _builder.newLineIfNotEmpty();
+    _builder.append("            ");
+    _builder.append("id=\"");
+    String _generatorId = data.getGeneratorId();
+    _builder.append(_generatorId, "            ");
+    _builder.append("\"");
+    _builder.newLineIfNotEmpty();
+    _builder.append("            ");
+    _builder.append("name=\"");
+    String _generatorName = data.getGeneratorName();
+    String _escapeForXml_1 = this.escapeForXml(_generatorName);
+    _builder.append(_escapeForXml_1, "            ");
+    _builder.append("\">");
+    _builder.newLineIfNotEmpty();
+    _builder.append("      ");
+    _builder.append("</SCTGenerator>");
+    _builder.newLine();
+    _builder.append("   ");
+    _builder.append("</extension>");
+    _builder.newLine();
+    {
+      boolean _isTypeLibrary = data.isTypeLibrary();
+      if (_isTypeLibrary) {
+        _builder.append("<extension");
+        _builder.newLine();
+        _builder.append("      ");
+        _builder.append("point=\"org.yakindu.sct.generator.core.featuretypes\">");
+        _builder.newLine();
+        _builder.append("   ");
+        _builder.append("<FeatureLibrary generatorId=\"");
+        String _generatorId_1 = data.getGeneratorId();
+        _builder.append(_generatorId_1, "   ");
+        _builder.append("\" ");
+        _builder.newLineIfNotEmpty();
+        _builder.append("   ");
+        _builder.append("defaultProvider=\"");
+        String _providerClass = this.providerClass(data);
+        _builder.append(_providerClass, "   ");
+        _builder.append("\"");
+        _builder.newLineIfNotEmpty();
+        _builder.append("         ");
+        _builder.append("uri=\"platform:/plugin/");
+        IProject _project = data.getProject();
+        String _name = _project.getName();
+        _builder.append(_name, "         ");
+        _builder.append("/library/FeatureTypeLibrary.xmi\">");
+        _builder.newLineIfNotEmpty();
+        _builder.append("   ");
+        _builder.append("</FeatureLibrary>");
+        _builder.newLine();
+        _builder.append("</extension>");
+        _builder.newLine();
+      }
+    }
+    _builder.append("</plugin>");
+    _builder.newLine();
+    return _builder;
+  }
+  
+  public StringConcatenation generator(final ProjectData data) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("package ");
+    String _generatorClass = data.getGeneratorClass();
+    String _packageName = this.packageName(_generatorClass);
+    _builder.append(_packageName, "");
+    _builder.append(";");
+    _builder.newLineIfNotEmpty();
+    _builder.newLine();
+    _builder.append("import org.yakindu.sct.generator.core.impl.AbstractXpandBasedCodeGenerator;");
+    _builder.newLine();
+    _builder.newLine();
+    _builder.append("/**");
+    _builder.newLine();
+    _builder.append(" ");
+    _builder.append("* Generator using Xpand template \"");
+    String _generatorClass_1 = data.getGeneratorClass();
+    String _javaPathToXpand = this.javaPathToXpand(_generatorClass_1);
+    _builder.append(_javaPathToXpand, " ");
+    _builder.append("::main\"");
+    _builder.newLineIfNotEmpty();
+    _builder.append(" ");
+    _builder.append("*/");
+    _builder.newLine();
+    _builder.append("public class ");
+    String _generatorClass_2 = data.getGeneratorClass();
+    String _simpleName = this.simpleName(_generatorClass_2);
+    _builder.append(_simpleName, "");
+    _builder.append(" extends AbstractXpandBasedCodeGenerator {");
+    _builder.newLineIfNotEmpty();
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("@Override");
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("public String getTemplatePath() {");
+    _builder.newLine();
+    _builder.append("\t\t");
+    _builder.append("return \"");
+    String _generatorClass_3 = data.getGeneratorClass();
+    String _javaPathToXpand_1 = this.javaPathToXpand(_generatorClass_3);
+    _builder.append(_javaPathToXpand_1, "		");
+    _builder.append("::main\";");
+    _builder.newLineIfNotEmpty();
+    _builder.append("\t");
+    _builder.append("}");
+    _builder.newLine();
+    _builder.append("}");
+    _builder.newLine();
+    return _builder;
+  }
+  
+  public StringConcatenation defaultProvider(final ProjectData data) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("package ");
+    String _providerClass = this.providerClass(data);
+    String _packageName = this.packageName(_providerClass);
+    _builder.append(_packageName, "");
+    _builder.append(";");
+    _builder.newLineIfNotEmpty();
+    _builder.newLine();
+    _builder.append("import org.yakindu.sct.generator.core.features.AbstractDefaultFeatureValueProvider;");
+    _builder.newLine();
+    _builder.newLine();
+    _builder.append("/**");
+    _builder.newLine();
+    _builder.append(" ");
+    _builder.append("* Default value proivder for ");
+    String _generatorName = data.getGeneratorName();
+    _builder.append(_generatorName, " ");
+    _builder.append(" feature library");
+    _builder.newLineIfNotEmpty();
+    _builder.append(" ");
+    _builder.append("*/");
+    _builder.newLine();
+    _builder.append("public class ");
+    String _providerClass_1 = this.providerClass(data);
+    String _simpleName = this.simpleName(_providerClass_1);
+    _builder.append(_simpleName, "");
+    _builder.append(" extends AbstractDefaultFeatureValueProvider {");
+    _builder.newLineIfNotEmpty();
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("private static final String LIBRARY_NAME = \"");
+    String _generatorName_1 = data.getGeneratorName();
+    _builder.append(_generatorName_1, "	");
+    _builder.append("\";");
+    _builder.newLineIfNotEmpty();
+    _builder.append("\t");
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("@Override");
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("protected void setDefaultValue(FeatureParameterValue parameterValue,");
+    _builder.newLine();
+    _builder.append("\t\t\t");
+    _builder.append("Statechart statechart) {");
+    _builder.newLine();
+    _builder.append("\t\t");
+    _builder.append("String parameterName = parameterValue.getParameter().getName();");
+    _builder.newLine();
+    _builder.append("\t\t");
+    _builder.append("//TODO: set the default values");
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("}");
+    _builder.newLine();
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("public boolean isProviderFor(FeatureTypeLibrary library) {");
+    _builder.newLine();
+    _builder.append("\t\t");
+    _builder.append("return library.getName().equals(LIBRARY_NAME);");
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("}");
+    _builder.newLine();
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("public IStatus validateParameterValue(FeatureParameterValue value) {");
+    _builder.newLine();
+    _builder.append("\t\t");
+    _builder.append("String name = value.getParameter().getName();");
+    _builder.newLine();
+    _builder.append("\t\t");
+    _builder.append("//TODO implement validation");
+    _builder.newLine();
+    _builder.append("\t\t");
+    _builder.append("return Status.OK_STATUS;");
+    _builder.newLine();
+    _builder.append("\t");
+    _builder.append("}");
+    _builder.newLine();
+    _builder.append("}");
+    _builder.newLine();
+    return _builder;
+  }
+  
+  public StringConcatenation projectSettings(final ProjectData data, final String encoding) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("eclipse.preferences.version=1");
+    _builder.newLine();
+    _builder.append("encoding/<project>=");
+    _builder.append(encoding, "");
+    _builder.newLineIfNotEmpty();
+    _builder.newLine();
+    return _builder;
+  }
+  
+  public StringConcatenation xpandSettings(final ProjectData data) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("eclipse.preferences.version=1");
+    _builder.newLine();
+    _builder.append("project.specific.metamodel=true");
+    _builder.newLine();
+    _builder.append("metamodelContributor=org.eclipse.xtend.typesystem.emf.ui.EmfMetamodelContributor");
+    _builder.newLine();
+    _builder.newLine();
+    return _builder;
+  }
+  
+  public StringConcatenation buildProperties(final ProjectData data) {
+    StringConcatenation _builder = new StringConcatenation();
+    _builder.append("source.. = src/,\\");
+    _builder.newLine();
+    _builder.append("           ");
+    _builder.append("src-gen");
+    _builder.newLine();
+    _builder.append("bin.includes = META-INF/,\\");
+    _builder.newLine();
+    _builder.append("               ");
+    _builder.append(".,\\");
+    _builder.newLine();
+    _builder.append("               ");
+    _builder.append("plugin.xml");
+    _builder.newLine();
+    return _builder;
+  }
+}