Browse Source

Added extension point to generator.core to register custom file extensions for generators

Andreas Mülder 13 years ago
parent
commit
bef5e6cad5

+ 7 - 0
plugins/org.yakindu.sct.generator.c/plugin.xml

@@ -18,5 +18,12 @@
             generatorId="yakindu::c"
             uri="platform:/plugin/org.yakindu.sct.generator.c/library/FeatureTypeLibrary.xmi">
       </FeatureLibrary>
+   </extension>
+   <extension
+         point="org.yakindu.sct.generator.core.extensions">
+      <ExtensionGeneratorMapping
+            fileExtension="sct"
+            generatorId="yakindu::c">
+      </ExtensionGeneratorMapping>
    </extension>
 </plugin>

+ 1 - 0
plugins/org.yakindu.sct.generator.core/plugin.xml

@@ -3,6 +3,7 @@
 <plugin>
  <extension-point id="org.yakindu.sct.generator.core.generator" name="SCT Generator" schema="schema/generator.exsd"/>
   <extension-point id="org.yakindu.sct.generator.core.featuretypes" name="GenModel Feature Types" schema="schema/featuretypes.exsd"/>
+  <extension-point id="org.yakindu.sct.generator.core.extensions" name="File Extension Mapping" schema="schema/extensions.exsd"/>
  <extension
          point="org.yakindu.sct.generator.core.featuretypes">
       <FeatureLibrary

+ 106 - 0
plugins/org.yakindu.sct.generator.core/schema/extensions.exsd

@@ -0,0 +1,106 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.yakindu.sct.generator.core" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+      <appinfo>
+         <meta.schema plugin="org.yakindu.sct.generator.core" id="org.yakindu.sct.generator.core.extensions" name="org.yakindu.sct.generator.core.extensions"/>
+      </appinfo>
+      <documentation>
+         [Enter description of this extension point.]
+      </documentation>
+   </annotation>
+
+   <element name="extension">
+      <annotation>
+         <appinfo>
+            <meta.element />
+         </appinfo>
+      </annotation>
+      <complexType>
+         <sequence minOccurs="1" maxOccurs="unbounded">
+            <element ref="ExtensionGeneratorMapping"/>
+         </sequence>
+         <attribute name="point" type="string" use="required">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="id" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="name" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+               <appinfo>
+                  <meta.attribute translatable="true"/>
+               </appinfo>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <element name="ExtensionGeneratorMapping">
+      <complexType>
+         <attribute name="fileExtension" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+         <attribute name="generatorId" type="string">
+            <annotation>
+               <documentation>
+                  
+               </documentation>
+            </annotation>
+         </attribute>
+      </complexType>
+   </element>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="since"/>
+      </appinfo>
+      <documentation>
+         [Enter the first release in which this extension point appears.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="examples"/>
+      </appinfo>
+      <documentation>
+         [Enter extension point usage example here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="apiinfo"/>
+      </appinfo>
+      <documentation>
+         [Enter API information here.]
+      </documentation>
+   </annotation>
+
+   <annotation>
+      <appinfo>
+         <meta.section type="implementation"/>
+      </appinfo>
+      <documentation>
+         [Enter information about supplied implementation of this extension point.]
+      </documentation>
+   </annotation>
+
+
+</schema>

+ 72 - 0
plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/extensions/FileExtensions.java

@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2012 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.extensions;
+
+import static com.google.common.collect.Iterables.transform;
+import static com.google.common.collect.Lists.newArrayList;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+
+import com.google.common.base.Function;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class FileExtensions {
+
+	private static final String EXTENSION_POINT_ID = "org.yakindu.sct.generator.core.extensions";
+	private static final String FILE_EXTENSION = "fileExtension";
+	private static final String GENERATOR_ID = "generatorId";
+
+	private static Iterable<FileExtensionDescriptor> generatorDescriptors;
+
+	public static class FileExtensionDescriptor {
+		private final IConfigurationElement configElement;
+
+		FileExtensionDescriptor(IConfigurationElement configElement) {
+			this.configElement = configElement;
+		}
+
+		public String getExtension() {
+			return configElement.getAttribute(FILE_EXTENSION);
+		}
+
+		public String getGeneratorId() {
+			return configElement.getAttribute(GENERATOR_ID);
+		}
+
+	}
+
+	public static Iterable<FileExtensionDescriptor> getFileExtensions() {
+		IConfigurationElement[] configurationElements = Platform
+				.getExtensionRegistry().getConfigurationElementsFor(
+						EXTENSION_POINT_ID);
+		if (generatorDescriptors == null) {
+			generatorDescriptors = transform(
+					newArrayList(configurationElements),
+					new CreateFileExtensions());
+		}
+		return generatorDescriptors;
+	}
+
+
+	private static final class CreateFileExtensions implements
+			Function<IConfigurationElement, FileExtensionDescriptor> {
+
+		public FileExtensionDescriptor apply(IConfigurationElement from) {
+			return new FileExtensionDescriptor(from);
+		}
+	}
+
+}

+ 7 - 0
plugins/org.yakindu.sct.generator.cpp/plugin.xml

@@ -18,5 +18,12 @@
             generatorId="yakindu::cpp"
             uri="platform:/plugin/org.yakindu.sct.generator.cpp/library/FeatureTypeLibrary.xmi">
       </FeatureLibrary>
+   </extension>
+   <extension
+         point="org.yakindu.sct.generator.core.extensions">
+      <ExtensionGeneratorMapping
+            fileExtension="sct"
+            generatorId="yakindu::cpp">
+      </ExtensionGeneratorMapping>
    </extension>
 </plugin>

+ 33 - 26
plugins/org.yakindu.sct.generator.genmodel.ui/src/org/yakindu/sct/generator/genmodel/ui/wizard/SGenWizardPage2.java

@@ -11,6 +11,7 @@
 package org.yakindu.sct.generator.genmodel.ui.wizard;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -49,6 +50,8 @@ import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.ISharedImages;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.ide.IDE;
+import org.yakindu.sct.generator.core.extensions.FileExtensions;
+import org.yakindu.sct.generator.core.extensions.FileExtensions.FileExtensionDescriptor;
 import org.yakindu.sct.generator.core.extensions.GeneratorExtensions;
 import org.yakindu.sct.generator.core.extensions.GeneratorExtensions.GeneratorDescriptor;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
@@ -64,10 +67,13 @@ import com.google.common.collect.Lists;
 /**
  * 
  * @author holger willebrandt - Initial contribution and API
+ * @author andreas muelder - extension point for contribution of file extensions
+ *         added
  */
 public class SGenWizardPage2 extends WizardPage {
 
-	protected static final String STATECHART_FILE_EXTENSION = "sct";
+	// protected static final String STATECHART_FILE_EXTENSION = "sct";
+
 	static Map<String, CoreGenerator> natureDefaultGenerators = new TreeMap<String, CoreGenerator>();
 	static {
 		natureDefaultGenerators.put("org.eclipse.cdt.core.cnature",
@@ -81,7 +87,6 @@ public class SGenWizardPage2 extends WizardPage {
 	protected CheckboxTreeViewer stateChartTree;
 	private final SGenWizardPage1 fileSelectionPage;
 
-
 	private static final ITreeContentProvider treeContentProvider = new ITreeContentProvider() {
 
 		public Object[] getElements(Object inputElement) {
@@ -148,12 +153,6 @@ public class SGenWizardPage2 extends WizardPage {
 
 	private final IStructuredSelection selection;
 
-	/**
-	 * @param pageName
-	 * @param selection
-	 * @param resourceDescriptions
-	 * @param selection
-	 */
 	protected SGenWizardPage2(String pageName,
 			SGenWizardPage1 fileSelectionPage, IStructuredSelection selection) {
 		super(pageName);
@@ -165,21 +164,12 @@ public class SGenWizardPage2 extends WizardPage {
 		Composite container = new Composite(parent, SWT.NULL);
 		setControl(container);
 		container.setLayout(new GridLayout(1, false));
+		createGeneratorCombo(container);
+		createStatechartTree(container);
+		checkComplete();
+	}
 
-		Label lblGenerator = new Label(container, SWT.NONE);
-		lblGenerator.setText("Generator");
-
-		generatorCombo = new ComboViewer(container, SWT.READ_ONLY);
-		generatorCombo.getCombo().setLayoutData(
-				new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
-		generatorCombo.setLabelProvider(new GeneratorDescriptorLabelProvider());
-		generatorCombo.setContentProvider(new ArrayContentProvider());
-		List<GeneratorDescriptor> descriptors = Lists
-				.newArrayList(GeneratorExtensions.getGeneratorDescriptors());
-		Collections.sort(descriptors, CoreGenerator.generatorOrder);
-		generatorCombo.setInput(descriptors);
-		generatorCombo.getCombo().select(0);
-
+	private void createStatechartTree(Composite container) {
 		Label lblNewLabel = new Label(container, SWT.NONE);
 		lblNewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true,
 				false, 1, 1));
@@ -204,9 +194,21 @@ public class SGenWizardPage2 extends WizardPage {
 				.addDoubleClickListener(new TreeExpandingDoubleClickListener(
 						stateChartTree, checkStateListener));
 		stateChartTree.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
+	}
 
-		checkComplete();
-
+	private void createGeneratorCombo(Composite container) {
+		Label lblGenerator = new Label(container, SWT.NONE);
+		lblGenerator.setText("Generator");
+		generatorCombo = new ComboViewer(container, SWT.READ_ONLY);
+		generatorCombo.getCombo().setLayoutData(
+				new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+		generatorCombo.setLabelProvider(new GeneratorDescriptorLabelProvider());
+		generatorCombo.setContentProvider(new ArrayContentProvider());
+		List<GeneratorDescriptor> descriptors = Lists
+				.newArrayList(GeneratorExtensions.getGeneratorDescriptors());
+		Collections.sort(descriptors, CoreGenerator.generatorOrder);
+		generatorCombo.setInput(descriptors);
+		generatorCombo.getCombo().select(0);
 	}
 
 	public List<Statechart> getStatecharts() {
@@ -356,9 +358,14 @@ public class SGenWizardPage2 extends WizardPage {
 	}
 
 	protected static boolean isStatechartResource(IResource resource) {
+		List<String> registeredExtensions = new ArrayList<String>();
+		Iterable<FileExtensionDescriptor> fileExtensions = FileExtensions
+				.getFileExtensions();
+		for (FileExtensionDescriptor desc : fileExtensions) {
+			registeredExtensions.add(desc.getExtension());
+		}
 		return resource.getType() == IResource.FILE
-				&& STATECHART_FILE_EXTENSION
-						.equals(resource.getFileExtension());
+				&& registeredExtensions.contains(resource.getFileExtension());
 	}
 
 	private static final Function<IResource, TreeNode> toTreeNode = new Function<IResource, TreeNode>() {

+ 5 - 0
plugins/org.yakindu.sct.generator.java/plugin.xml

@@ -18,5 +18,10 @@
             uri="platform:/plugin/org.yakindu.sct.generator.java/library/FeatureTypeLibrary.xmi">
       </FeatureLibrary>
    </extension>
+   <extension
+         point="org.yakindu.sct.generator.core.extensions">
+      <ExtensionGeneratorMapping
+            fileExtension="sct"></ExtensionGeneratorMapping>
+   </extension>
 
 </plugin>