浏览代码

Share project "org.yakindu.sct.generator.ui" into "https://svn.codespot.com/a/eclipselabs.org/yakindu"

Andreas Mülder 13 年之前
父节点
当前提交
132cf2f131

+ 7 - 0
plugins/org.yakindu.sct.generator.ui/.classpath

@@ -0,0 +1,7 @@
+<?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>

+ 28 - 0
plugins/org.yakindu.sct.generator.ui/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.yakindu.sct.generator.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>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 8 - 0
plugins/org.yakindu.sct.generator.ui/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,8 @@
+#Wed Nov 09 15:17:14 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

+ 15 - 0
plugins/org.yakindu.sct.generator.ui/META-INF/MANIFEST.MF

@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Generator UI Plugin
+Bundle-SymbolicName: org.yakindu.sct.generator.ui;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.yakindu.sct.generator.ui.GeneratorUIActivator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.7.100",
+ org.eclipse.emf;bundle-version="2.6.0",
+ org.eclipse.emf.ecore;bundle-version="2.7.0",
+ org.yakindu.sct.model.sgen;bundle-version="1.0.0",
+ org.yakindu.sct.generator.core;bundle-version="1.0.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5

+ 5 - 0
plugins/org.yakindu.sct.generator.ui/build.properties

@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml

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

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+<extension point = "org.eclipse.ui.popupMenus">
+     <objectContribution
+        id="org.yakindu.sct.generator.ui"
+        objectClass="org.eclipse.core.resources.IFile"
+	    nameFilter="*.sgen">
+	    <action
+           class="org.yakindu.sct.generator.ui.action.GenerateModelAction"
+           enablesFor="1"
+           id="org.yakindu.sct.generator.ui.generateaction"
+           label="Generate Model"
+           menubarPath="additions">
+	    </action>
+	 </objectContribution>
+	</extension>
+</plugin>

+ 50 - 0
plugins/org.yakindu.sct.generator.ui/src/org/yakindu/sct/generator/ui/GeneratorUIActivator.java

@@ -0,0 +1,50 @@
+package org.yakindu.sct.generator.ui;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class GeneratorUIActivator extends AbstractUIPlugin {
+
+	// The plug-in ID
+	public static final String PLUGIN_ID = "org.yakindu.sct.generator.ui"; //$NON-NLS-1$
+
+	// The shared instance
+	private static GeneratorUIActivator plugin;
+	
+	/**
+	 * The constructor
+	 */
+	public GeneratorUIActivator() {
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+		plugin = this;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext context) throws Exception {
+		plugin = null;
+		super.stop(context);
+	}
+
+	/**
+	 * Returns the shared instance
+	 *
+	 * @return the shared instance
+	 */
+	public static GeneratorUIActivator getDefault() {
+		return plugin;
+	}
+
+}

+ 83 - 0
plugins/org.yakindu.sct.generator.ui/src/org/yakindu/sct/generator/ui/action/GenerateModelAction.java

@@ -0,0 +1,83 @@
+package org.yakindu.sct.generator.ui.action;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import org.eclipse.core.resources.IFile;
+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.Resource.Factory;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+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;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class GenerateModelAction implements IObjectActionDelegate {
+
+	private ISelection selection;
+
+	public void run(IAction action) {
+		IFile file = unwrap();
+		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);
+		ISCTGenerator generator = description.createGenerator();
+		EList<GeneratorEntry> entries = model.getEntries();
+		for (GeneratorEntry generatorEntry : entries) {
+			generator.generate(generatorEntry);
+		}
+
+	}
+
+	protected static Resource loadResource(URI uri) {
+		Factory factory = ResourceFactoryRegistryImpl.INSTANCE.getFactory(uri);
+		ResourceSet resourceSet = new ResourceSetImpl();
+		Resource resource = factory.createResource(uri);
+		resourceSet.getResources().add(resource);
+		try {
+			resource.load(Collections.emptyMap());
+		} catch (IOException e) {
+			e.printStackTrace();
+			return null;
+		}
+		return resource;
+	}
+
+	private IFile unwrap() {
+		if (selection instanceof StructuredSelection) {
+			Object firstElement = ((StructuredSelection) selection)
+					.getFirstElement();
+			if (firstElement instanceof IFile) {
+				return (IFile) firstElement;
+			}
+		}
+		return null;
+	}
+
+	public void selectionChanged(IAction action, ISelection selection) {
+		this.selection = selection;
+	}
+
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+	}
+
+}