فهرست منبع

SCT Nature with automated Builder for Genmodels

holger.willebrandt@gmail.com 14 سال پیش
والد
کامیت
4691b2e4b1

+ 4 - 2
plugins/org.yakindu.sct.generator.core/META-INF/MANIFEST.MF

@@ -17,10 +17,12 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.jdt.launching,
  org.eclipse.ui.console,
  org.eclipse.xtext.xbase;bundle-version="2.0.0",
- org.yakindu.sct.model.sgen;bundle-version="1.0.0"
+ org.yakindu.sct.model.sgen;bundle-version="1.0.0",
+ org.eclipse.core.expressions
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
 Export-Package: org.yakindu.sct.generator.core,
  org.yakindu.sct.generator.core.extensions,
  org.yakindu.sct.generator.core.features,
- org.yakindu.sct.generator.core.impl
+ org.yakindu.sct.generator.core.impl,
+ org.yakindu.sct.builder.nature

+ 65 - 2
plugins/org.yakindu.sct.generator.core/plugin.xml

@@ -36,9 +36,72 @@
           class="org.yakindu.sct.generator.core.impl.GenericJavaBasedGenerator"
           description="Generate Code using Xpand Templates"
           id="yakindu::generic"
-          name="Custom Java-based Generator">
+          name="Custom Xtend2/Java-based Generator">
     </SCTGenerator>
  </extension>
- 
+  <extension
+         id="org.yakindu.sct.builder.SCTBuilder"
+         name="YAKINDU HMI Builder"
+         point="org.eclipse.core.resources.builders">
+      <builder hasNature="true">
+         <run  class="org.yakindu.sct.builder.SCTBuilder">
+         </run>
+      </builder>
+   </extension>
+   <extension
+         point="org.eclipse.core.resources.natures"
+         id="org.yakindu.sct.builder.SCTNature"
+         name="YAKINDU SCT Project Nature">
+      <runtime>
+         <run class="org.yakindu.sct.builder.nature.SCTNature">
+         </run>
+      </runtime>
+      <builder
+            id="org.yakindu.sct.builder.SCTBuilder">
+      </builder>
+   </extension>
+   <extension
+         point="org.eclipse.ui.popupMenus">
+      <objectContribution
+            adaptable="true"
+            objectClass="org.eclipse.core.resources.IProject"
+            nameFilter="*"
+            id="org.yakindu.sct.builder.addNature">
+         <action
+               label="Add YAKINDU SCT Nature"
+               class="org.yakindu.sct.builder.nature.ToggleSCTNatureAction"
+               menubarPath="org.eclipse.ui.projectConfigure/additions"
+               enablesFor="+"
+               id="org.yakindu.sct.builder.addRemoveNatureAction">
+         </action>
+           <visibility>
+         	<not>
+	            <objectState
+    	              name="nature"
+        	          value="org.yakindu.sct.builder.SCTNature">
+            	</objectState>
+            </not>
+         </visibility>
+      </objectContribution>
+      <objectContribution
+            adaptable="true"
+            objectClass="org.eclipse.core.resources.IProject"
+            nameFilter="*"
+            id="org.yakindu.sct.builder.removeNature">
+         <action
+               label="Remove YAKINDU SCT Nature"
+               class="org.yakindu.sct.builder.nature.ToggleSCTNatureAction"
+               menubarPath="org.eclipse.ui.projectConfigure/additions"
+               enablesFor="+"
+               id="org.yakindu.sct.builder.addRemoveNatureAction">
+         </action>
+           <visibility>
+	            <objectState
+    	              name="nature"
+        	          value="org.yakindu.sct.builder.SCTNature">
+            	</objectState>
+         </visibility>
+      </objectContribution>
+   </extension>
 
 </plugin>

+ 233 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/builder/SCTBuilder.java

@@ -0,0 +1,233 @@
+/**
+ * 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.builder;
+
+import java.util.Map;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+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.ecore.resource.impl.ResourceSetImpl;
+import org.yakindu.sct.generator.core.GeneratorActivator;
+import org.yakindu.sct.generator.core.GeneratorExecutor;
+import org.yakindu.sct.model.sgen.GeneratorEntry;
+import org.yakindu.sct.model.sgen.GeneratorModel;
+import org.yakindu.sct.model.sgraph.Statechart;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class SCTBuilder extends IncrementalProjectBuilder {
+
+	private static final String SCT_FILE_EXTENSION = "sct";
+	private static final String SGEN_FILE_EXTENSION = "sgen";
+	public static final String BUILDER_ID = "org.yakindu.sct.builder.SCTBuilder";
+
+	private final class GeneratorForStatechart implements
+			Predicate<GeneratorEntry> {
+		private final Statechart statechart;
+
+		private GeneratorForStatechart(Statechart statechart) {
+			this.statechart = statechart;
+		}
+
+		public boolean apply(GeneratorEntry input) {
+			// return input.getStatechart().equals(statechart);
+			return statechart != null
+					&& input.getStatechart().getName()
+							.equals(statechart.getName());
+		}
+	}
+
+	class DeltaVisitor implements IResourceDeltaVisitor {
+		public boolean visit(IResourceDelta delta) throws CoreException {
+			IResource resource = delta.getResource();
+			switch (delta.getKind()) {
+			case IResourceDelta.ADDED:
+				// handle added resource
+				doIt(resource);
+				break;
+			case IResourceDelta.REMOVED:
+				// handle removed resource
+				break;
+			case IResourceDelta.CHANGED:
+				// handle changed resource
+				doIt(resource);
+				break;
+			}
+			// return true to continue visiting children.
+			return true;
+		}
+	}
+
+	class SimpleResourceVisitor implements IResourceVisitor {
+		public boolean visit(IResource resource) {
+			doIt(resource);
+			// return true to continue visiting children.
+			return true;
+		}
+	}
+
+	@Override
+	protected IProject[] build(int kind,
+			@SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor)
+			throws CoreException {
+		if (kind == FULL_BUILD) {
+			fullBuild(monitor);
+		} else {
+			IResourceDelta delta = getDelta(getProject());
+			if (delta == null) {
+				fullBuild(monitor);
+			} else {
+				incrementalBuild(delta, monitor);
+			}
+		}
+		return null;
+	}
+
+	protected void fullBuild(final IProgressMonitor monitor)
+			throws CoreException {
+		try {
+			getProject().accept(new SimpleResourceVisitor());
+		} catch (CoreException e) {
+		}
+	}
+
+	protected void incrementalBuild(IResourceDelta delta,
+			IProgressMonitor monitor) throws CoreException {
+		delta.accept(new DeltaVisitor());
+	}
+
+	public void doIt(final IResource changedResource) {
+		if (changedResource.getType() != IResource.FILE) {
+			return;
+		}
+		if (SGEN_FILE_EXTENSION.equals(changedResource.getFileExtension())) {
+			if (hasError(changedResource)) {
+				logGenmodelError(changedResource.getFullPath().toString());
+			} else {
+				executeGenmodelGenerator(changedResource);
+			}
+		} else if (SCT_FILE_EXTENSION
+				.equals(changedResource.getFileExtension())) {
+			final Statechart statechart = loadFromResource(changedResource);
+			try {
+				changedResource.getProject().accept(new IResourceVisitor() {
+
+					public boolean visit(IResource resource)
+							throws CoreException {
+						if (IResource.FILE == resource.getType()
+								&& SGEN_FILE_EXTENSION.equals(resource
+										.getFileExtension())
+								&& isGenmodelForStatechart(resource, statechart)) {
+							// TODO: would be good to filter the config for the
+							// statechart so only the sct that changed is
+							// build
+							if (hasError(changedResource)) {
+								logStatechartError(changedResource
+										.getFullPath().toString());
+							} else {
+								if (hasError(resource)) {
+									logGenmodelError(resource.getFullPath()
+											.toString());
+								} else {
+									executeGenmodelGenerator(resource);
+								}
+							}
+						}
+						return true;
+					}
+				});
+			} catch (CoreException e) {
+				e.printStackTrace();
+			}
+
+		}
+	}
+
+	private boolean hasError(IResource resource) {
+		IMarker[] findMarkers = null;
+		try {
+			findMarkers = resource.findMarkers(IMarker.PROBLEM, true,
+					IResource.DEPTH_INFINITE);
+			for (IMarker iMarker : findMarkers) {
+				Integer attribute = (Integer) iMarker
+						.getAttribute(IMarker.SEVERITY);
+				if (attribute.intValue() == IMarker.SEVERITY_ERROR) {
+					return true;
+				}
+			}
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+		return false;
+	}
+
+	protected void executeGenmodelGenerator(IResource resource) {
+		new GeneratorExecutor().executeGenerator(resource.getProject().getFile(
+				resource.getProjectRelativePath()));
+	}
+
+	protected void logGenmodelError(String resource) {
+		Status status = new Status(Status.ERROR, BUILDER_ID, String.format(
+				"Cannot execute Genmodel %s. The file contains errors.",
+				resource));
+		Platform.getLog(GeneratorActivator.getDefault().getBundle())
+				.log(status);
+	}
+
+	protected void logStatechartError(final String resource) {
+		Status status = new Status(
+				Status.ERROR,
+				BUILDER_ID,
+				String.format(
+						"Cannot generate Code for Statechart %s. The file contains errors.",
+						resource));
+		Platform.getLog(GeneratorActivator.getDefault().getBundle())
+				.log(status);
+	}
+
+	private boolean isGenmodelForStatechart(IResource genmodelResource,
+			final Statechart statechart) {
+		GeneratorModel genModel = loadFromResource(genmodelResource);
+		return genModel != null
+				&& !genModel.getEntries().isEmpty()
+				&& Iterables.any(genModel.getEntries(),
+						new GeneratorForStatechart(statechart));
+	}
+
+	@SuppressWarnings("unchecked")
+	private <TYPE extends EObject> TYPE loadFromResource(IResource res) {
+		URI uri = URI.createPlatformResourceURI(res.getFullPath().toString(),
+				true);
+		ResourceSet set = new ResourceSetImpl();
+		Resource emfResource = set.getResource(uri, true);
+		return (TYPE) emfResource.getContents().get(0);
+	}
+
+}

+ 72 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/builder/nature/SCTNature.java

@@ -0,0 +1,72 @@
+/**
+ * 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.builder.nature;
+
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IProjectNature;
+import org.eclipse.core.runtime.CoreException;
+import org.yakindu.sct.builder.SCTBuilder;
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ *
+ */
+public class SCTNature implements IProjectNature {
+
+	public static final String NATURE_ID = "org.yakindu.sct.builder.SCTNature";
+
+	private IProject project;
+
+	public void configure() throws CoreException {
+		IProjectDescription desc = project.getDescription();
+		ICommand[] commands = desc.getBuildSpec();
+		for (int i = 0; i < commands.length; ++i) {
+			if (commands[i].getBuilderName().equals(SCTBuilder.BUILDER_ID)) {
+				return;
+			}
+		}
+
+		ICommand[] newCommands = new ICommand[commands.length + 1];
+		System.arraycopy(commands, 0, newCommands, 0, commands.length);
+		ICommand command = desc.newCommand();
+		command.setBuilderName(SCTBuilder.BUILDER_ID);
+		newCommands[newCommands.length - 1] = command;
+		desc.setBuildSpec(newCommands);
+		project.setDescription(desc, null);
+	}
+
+	public void deconfigure() throws CoreException {
+		IProjectDescription description = getProject().getDescription();
+		ICommand[] commands = description.getBuildSpec();
+		for (int i = 0; i < commands.length; ++i) {
+			if (commands[i].getBuilderName().equals(SCTBuilder.BUILDER_ID)) {
+				ICommand[] newCommands = new ICommand[commands.length - 1];
+				System.arraycopy(commands, 0, newCommands, 0, i);
+				System.arraycopy(commands, i + 1, newCommands, i,
+						commands.length - i - 1);
+				description.setBuildSpec(newCommands);
+				project.setDescription(description, null);			
+				return;
+			}
+		}
+	}
+
+	public IProject getProject() {
+		return project;
+	}
+
+	public void setProject(IProject project) {
+		this.project = project;
+	}
+
+}

+ 96 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/builder/nature/ToggleSCTNatureAction.java

@@ -0,0 +1,96 @@
+/**
+ * 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.builder.nature;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.action.IAction;
+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.commands.IElementUpdater;
+import org.eclipse.ui.menus.UIElement;
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ *
+ */
+public class ToggleSCTNatureAction implements IObjectActionDelegate,
+		IElementUpdater {
+
+	private ISelection selection;
+
+	public void run(IAction action) {
+		if (selection instanceof IStructuredSelection) {
+			for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it
+					.hasNext();) {
+				Object element = it.next();
+				IProject project = null;
+				if (element instanceof IProject) {
+					project = (IProject) element;
+				} else if (element instanceof IAdaptable) {
+					project = (IProject) ((IAdaptable) element)
+							.getAdapter(IProject.class);
+				}
+				if (project != null) {
+					toggleNature(project);
+				}
+			}
+		}
+	}
+
+	public void selectionChanged(IAction action, ISelection selection) {
+		this.selection = selection;
+	}
+
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+	}
+
+	public void toggleNature(IProject project) {
+		try {
+			IProjectDescription description = project.getDescription();
+			String[] natures = description.getNatureIds();
+
+			for (int i = 0; i < natures.length; ++i) {
+				if (SCTNature.NATURE_ID.equals(natures[i])) {
+					// Remove the nature
+					String[] newNatures = new String[natures.length - 1];
+					System.arraycopy(natures, 0, newNatures, 0, i);
+					System.arraycopy(natures, i + 1, newNatures, i,
+							natures.length - i - 1);
+					description.setNatureIds(newNatures);
+					project.setDescription(description, null);
+					return;
+				}
+			}
+
+			// Add the nature
+			String[] newNatures = new String[natures.length + 1];
+			System.arraycopy(natures, 0, newNatures, 0, natures.length);
+			newNatures[natures.length] = SCTNature.NATURE_ID;
+			description.setNatureIds(newNatures);
+			project.setDescription(description, null);
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void updateElement(UIElement element, Map parameters) {
+
+	}
+
+}

+ 74 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/GeneratorExecutor.java

@@ -0,0 +1,74 @@
+/**
+ * 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.core;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.yakindu.sct.generator.core.extensions.GeneratorExtensions;
+import org.yakindu.sct.generator.core.extensions.GeneratorExtensions.GeneratorDescriptor;
+import org.yakindu.sct.model.sgen.GeneratorEntry;
+import org.yakindu.sct.model.sgen.GeneratorModel;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * @author holger willebrandt - refactoring
+ */
+public class GeneratorExecutor {
+
+	// @Inject
+	// private XtextResourceSetProvider provider;
+
+	public void executeGenerator(IFile file) {
+		Resource resource = loadResource(file);
+		GeneratorModel model = (GeneratorModel) resource.getContents().get(0);
+
+		String generatorId = model.getGeneratorId();
+		GeneratorDescriptor description = GeneratorExtensions
+				.getGeneratorDescriptorForId(generatorId);
+		final ISCTGenerator generator = description.createGenerator();
+		final EList<GeneratorEntry> entries = model.getEntries();
+		Job generatorJob = new Job("Execute SCT Genmodel " + file.getName()) {
+			@Override
+			protected IStatus run(IProgressMonitor monitor) {
+				for (GeneratorEntry generatorEntry : entries) {
+					if (monitor.isCanceled()) {
+						break;
+					}
+					generator.generate(generatorEntry);
+				}
+				return Status.OK_STATUS;
+			}
+		};
+		generatorJob.schedule();
+	}
+
+
+	protected Resource loadResource(IFile file) {
+		Resource resource = null;
+		URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(),
+				true);
+		// if (provider != null) {
+		// resource = provider.get(file.getProject()).getResource(uri, true);
+		// } else {
+			resource = new ResourceSetImpl().getResource(uri, true);
+		// }
+		return resource;
+	}
+
+}

+ 38 - 20
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java

@@ -10,7 +10,17 @@
  */
 package org.yakindu.sct.generator.core.impl;
 
-import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.*;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.DEBUG_FEATURE;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.DEBUG_FEATURE_DUMP_SEXEC;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.FUNCTION_INLINING_FEATURE;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.FUNCTION_INLINING_FEATURE_INLINE_CHOICES;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.FUNCTION_INLINING_FEATURE_INLINE_ENTER_SEQUENCES;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.FUNCTION_INLINING_FEATURE_INLINE_ENTRY_ACTIONS;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.FUNCTION_INLINING_FEATURE_INLINE_EXIT_ACTIONS;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.FUNCTION_INLINING_FEATURE_INLINE_EXIT_SEQUENCES;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.FUNCTION_INLINING_FEATURE_INLINE_REACTIONS;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE;
+import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_TARGET_PROJECT;
 
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -27,8 +37,6 @@ 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.swt.SWT;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.console.ConsolePlugin;
 import org.eclipse.ui.console.IConsole;
 import org.eclipse.ui.console.IConsoleManager;
@@ -68,7 +76,6 @@ public abstract class AbstractSExecModelGenerator implements ISCTGenerator {
 		super();
 		info = getConsole().newMessageStream();
 		error = getConsole().newMessageStream();
-		error.setColor(Display.getDefault().getSystemColor(SWT.COLOR_RED));
 		error.setActivateOnWrite(true);
 	}
 
@@ -110,35 +117,45 @@ public abstract class AbstractSExecModelGenerator implements ISCTGenerator {
 	/**
 	 * Transforms the {@link Statechart} model to a {@link ExecutionFlow} model
 	 */
-	protected ExecutionFlow createExecutionFlow(Statechart statechart, GeneratorEntry entry) {
+	protected ExecutionFlow createExecutionFlow(Statechart statechart,
+			GeneratorEntry entry) {
 		Injector injector = Guice.createInjector(new SequencerModule());
 		ModelSequencer sequencer = injector.getInstance(ModelSequencer.class);
 		ExecutionFlow flow = sequencer.transform(statechart);
 		Assert.isNotNull(flow, "Error creation ExecutionFlow");
 
-		FeatureConfiguration optimizeConfig = entry.getFeatureConfiguration(FUNCTION_INLINING_FEATURE);
-		
+		FeatureConfiguration optimizeConfig = entry
+				.getFeatureConfiguration(FUNCTION_INLINING_FEATURE);
+
 		FlowOptimizer optimizer = injector.getInstance(FlowOptimizer.class);
-		
-		optimizer.inlineReactions( getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_REACTIONS, true) );
-		optimizer.inlineExitActions( getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_EXIT_ACTIONS, true) );
-		optimizer.inlineEntryActions( getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTRY_ACTIONS, true) );
-		optimizer.inlineEnterSequences( getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTER_SEQUENCES, true) );
-		optimizer.inlineExitSequences( getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_EXIT_SEQUENCES, true) );
-		optimizer.inlineChoices( getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_CHOICES, true) );
-		
+
+		optimizer.inlineReactions(getBoolValue(optimizeConfig,
+				FUNCTION_INLINING_FEATURE_INLINE_REACTIONS, true));
+		optimizer.inlineExitActions(getBoolValue(optimizeConfig,
+				FUNCTION_INLINING_FEATURE_INLINE_EXIT_ACTIONS, true));
+		optimizer.inlineEntryActions(getBoolValue(optimizeConfig,
+				FUNCTION_INLINING_FEATURE_INLINE_ENTRY_ACTIONS, true));
+		optimizer.inlineEnterSequences(getBoolValue(optimizeConfig,
+				FUNCTION_INLINING_FEATURE_INLINE_ENTER_SEQUENCES, true));
+		optimizer.inlineExitSequences(getBoolValue(optimizeConfig,
+				FUNCTION_INLINING_FEATURE_INLINE_EXIT_SEQUENCES, true));
+		optimizer.inlineChoices(getBoolValue(optimizeConfig,
+				FUNCTION_INLINING_FEATURE_INLINE_CHOICES, true));
+
 		flow = optimizer.transform(flow);
 
 		return flow;
 	}
 
-	boolean getBoolValue(FeatureConfiguration conf, String param, boolean defaultValue) {
-		if ( conf != null && conf.getParameterValue(param) != null ) 
+	boolean getBoolValue(FeatureConfiguration conf, String param,
+			boolean defaultValue) {
+		if (conf != null && conf.getParameterValue(param) != null) {
 			return conf.getParameterValue(param).getBooleanValue();
-		
+		}
+
 		return defaultValue;
 	}
-	
+
 	protected final void writeToConsole(Throwable t) {
 		PrintWriter printWriter = new PrintWriter(error);
 		t.printStackTrace(printWriter);
@@ -211,8 +228,9 @@ public abstract class AbstractSExecModelGenerator implements ISCTGenerator {
 	protected boolean isDumpSexec(GeneratorEntry entry) {
 		FeatureParameterValue dumpSexec = getFeatureParameter(entry,
 				DEBUG_FEATURE, DEBUG_FEATURE_DUMP_SEXEC);
-		if (dumpSexec == null)
+		if (dumpSexec == null) {
 			return false;
+		}
 		return dumpSexec.getBooleanValue();
 	}
 

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

@@ -228,7 +228,7 @@
             class="org.yakindu.sct.generator.genmodel.ui.SGenExecutableExtensionFactory:org.yakindu.sct.generator.genmodel.ui.wizard.WorkspaceGeneratorProjectWizard"
             icon="icons/GenModel-16.png"
             id="org.yakindu.sct.generator.genmodel.ui.WorkspaceGeneratorProjectWizard"
-            name="YAKINDU Workspace Generator Project"
+            name="YAKINDU Xtend2/Java Generator Project"
             project="true">
       </wizard>
    </extension>

+ 4 - 43
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/action/GenerateModelAction.java

@@ -14,14 +14,8 @@ import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.viewers.ISelection;
@@ -30,13 +24,8 @@ import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
-import org.eclipse.xtext.ui.resource.XtextResourceSetProvider;
 import org.yakindu.sct.generator.core.GeneratorActivator;
-import org.yakindu.sct.generator.core.ISCTGenerator;
-import org.yakindu.sct.generator.core.extensions.GeneratorExtensions;
-import org.yakindu.sct.generator.core.extensions.GeneratorExtensions.GeneratorDescriptor;
-import org.yakindu.sct.model.sgen.GeneratorEntry;
-import org.yakindu.sct.model.sgen.GeneratorModel;
+import org.yakindu.sct.generator.core.GeneratorExecutor;
 
 import com.google.inject.Inject;
 
@@ -50,7 +39,7 @@ public class GenerateModelAction implements IObjectActionDelegate {
 	private ISelection selection;
 
 	@Inject
-	private XtextResourceSetProvider provider;
+	private GeneratorExecutor generatorExecutor;
 
 	public void run(IAction action) {
 		IFile file = unwrap();
@@ -64,33 +53,10 @@ public class GenerateModelAction implements IObjectActionDelegate {
 							"The file contains errors"));
 			return;
 		}
-		
-		URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(),
-				true);
-		Resource resource = loadResource(uri);
-		GeneratorModel model = (GeneratorModel) resource.getContents().get(0);
-
-		String generatorId = model.getGeneratorId();
-		GeneratorDescriptor description = GeneratorExtensions
-				.getGeneratorDescriptorForId(generatorId);
-		final ISCTGenerator generator = description.createGenerator();
-		final EList<GeneratorEntry> entries = model.getEntries();
-		Job generatorJob = new Job("Execute SCT Genmodel " + file.getName()) {
-			@Override
-			protected IStatus run(IProgressMonitor monitor) {
-				for (GeneratorEntry generatorEntry : entries) {
-					if (monitor.isCanceled()) {
-						break;
-					}
-					generator.generate(generatorEntry);
-				}
-				return Status.OK_STATUS;
-			}
-		};
-		generatorJob.schedule();
-
+		generatorExecutor.executeGenerator(file);
 	}
 
+
 	private boolean hasError(IFile file) {
 		IMarker[] findMarkers = null;
 		try {
@@ -109,11 +75,6 @@ public class GenerateModelAction implements IObjectActionDelegate {
 		return false;
 	}
 
-	protected Resource loadResource(URI uri) {
-		ResourceSet resourceSet = provider.get(unwrap().getProject());
-		Resource resource = resourceSet.getResource(uri, true);
-		return resource;
-	}
 
 	private IFile unwrap() {
 		if (selection instanceof StructuredSelection) {

+ 20 - 0
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/wizard/SGenNewFileWizard.java

@@ -14,7 +14,10 @@ import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
 
+import org.eclipse.core.resources.IProject;
+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.emf.common.util.URI;
 import org.eclipse.emf.ecore.resource.Resource;
@@ -25,6 +28,8 @@ import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.yakindu.sct.builder.nature.SCTNature;
+import org.yakindu.sct.builder.nature.ToggleSCTNatureAction;
 import org.yakindu.sct.model.sgen.GeneratorModel;
 import org.yakindu.sct.model.sgraph.Statechart;
 
@@ -77,6 +82,7 @@ public class SGenNewFileWizard extends Wizard implements INewWizard {
 			@Override
 			protected void execute(IProgressMonitor monitor)
 					throws CoreException, InterruptedException {
+				ensureSCTNature(getProject(modelFilePage.getContainerFullPath()));
 				createDefaultModel(modelFilePage.getURI());
 			}
 		};
@@ -89,6 +95,20 @@ public class SGenNewFileWizard extends Wizard implements INewWizard {
 		return true;
 	}
 
+	protected void ensureSCTNature(IProject project) throws CoreException {
+		if (project.getNature(SCTNature.NATURE_ID) == null) {
+			new ToggleSCTNatureAction().toggleNature(project);
+		}
+	}
+
+	protected IProject getProject(IPath containerFullPath) {
+		if (containerFullPath.segmentCount() == 1) {
+			return ResourcesPlugin.getWorkspace().getRoot().getProject(containerFullPath.lastSegment());
+		}
+		return ResourcesPlugin.getWorkspace().getRoot()
+				.getFolder(containerFullPath).getProject();
+	}
+
 	private void createDefaultModel(URI uri) {
 		List<Statechart> statecharts = generatorConfigPage.getStatecharts();
 		String generatorId = generatorConfigPage.getGeneratorId();