Просмотр исходного кода

Refactoring of default domain module provisioning

Andreas Mülder 11 лет назад
Родитель
Сommit
8f37b18e3f

+ 14 - 14
features/org.yakindu.sct-feature/feature.xml

@@ -116,13 +116,6 @@
          version="0.0.0"
          unpack="false"/>
 
-   <plugin
-         id="org.yakindu.sct.ui.integration.stext"
-         download-size="0"
-         install-size="0"
-         version="0.0.0"
-         unpack="false"/>
-
    <plugin
          id="org.yakindu.sct.simulation.core"
          download-size="0"
@@ -164,13 +157,6 @@
          version="0.0.0"
          unpack="false"/>
 
-   <plugin
-         id="org.yakindu.sct.model.stext.resource"
-         download-size="0"
-         install-size="0"
-         version="0.0.0"
-         unpack="false"/>
-
    <plugin
          id="org.yakindu.sct.model.sgen"
          download-size="0"
@@ -276,4 +262,18 @@
          version="0.0.0"
          unpack="false"/>
 
+   <plugin
+         id="org.yakindu.sct.model.resource"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
+   <plugin
+         id="org.yakindu.sct.domain.default_"
+         download-size="0"
+         install-size="0"
+         version="0.0.0"
+         unpack="false"/>
+
 </feature>

+ 43 - 34
plugins/org.yakindu.sct.domain.default_/src/org/yakindu/sct/domain/default_/extension/DefaultDomainModuleProvider.java

@@ -10,17 +10,26 @@
  */
 package org.yakindu.sct.domain.default_.extension;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.xtext.ui.shared.SharedStateModule;
 import org.yakindu.sct.domain.default_.modules.DefaultSequencerModule;
 import org.yakindu.sct.domain.default_.modules.DefaultSimulationModule;
 import org.yakindu.sct.domain.default_.modules.DefaultTypeSystemModule;
-import org.yakindu.sct.domain.default_.modules.StateExpressionProvider;
-import org.yakindu.sct.domain.default_.modules.StatechartExpressionProvider;
-import org.yakindu.sct.domain.default_.modules.TransitionExpressionProvider;
+import org.yakindu.sct.domain.default_.modules.EntryRuleRuntimeModule;
+import org.yakindu.sct.domain.default_.modules.EntryRuleUIModule;
 import org.yakindu.sct.domain.extension.IDomainModuleProvider;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.Transition;
 import org.yakindu.sct.model.stext.STextRuntimeModule;
+import org.yakindu.sct.model.stext.stext.StateSpecification;
+import org.yakindu.sct.model.stext.stext.StatechartSpecification;
+import org.yakindu.sct.model.stext.stext.TransitionSpecification;
+import org.yakindu.sct.model.stext.ui.STextUiModule;
+import org.yakindu.sct.model.stext.ui.internal.STextActivator;
 
 import com.google.inject.Module;
 import com.google.inject.util.Modules;
@@ -32,6 +41,28 @@ import com.google.inject.util.Modules;
  */
 public class DefaultDomainModuleProvider implements IDomainModuleProvider {
 
+	private static final Map<String, Class<? extends EObject>> semanticTargetToRuleMap = new HashMap<String, Class<? extends EObject>>();
+	static {
+		semanticTargetToRuleMap.put(Statechart.class.getName(), StatechartSpecification.class);
+		semanticTargetToRuleMap.put(Transition.class.getName(), TransitionSpecification.class);
+		semanticTargetToRuleMap.put(State.class.getName(), StateSpecification.class);
+	}
+
+	@Override
+	public Module getSharedStateModule() {
+		return new SharedStateModule();
+	}
+
+	@Override
+	public Module getLanguageRuntimeModule() {
+		return new STextRuntimeModule();
+	}
+
+	@Override
+	public Module getLanguageUIModule() {
+		return new STextUiModule(STextActivator.getInstance());
+	}
+
 	protected Module getTypeSystemModule() {
 		return new DefaultTypeSystemModule();
 	}
@@ -41,46 +72,24 @@ public class DefaultDomainModuleProvider implements IDomainModuleProvider {
 		return new DefaultSimulationModule();
 	}
 
-	@Override
-	public Module getResourceModule() {
-		return Modules.combine(new STextRuntimeModule(), getTypeSystemModule());
-	}
-	
 	@Override
 	public Module getSequencerModule() {
 		return new DefaultSequencerModule();
 	}
 
 	@Override
-	public Module getEmbeddedEditorModule(String semanticTarget) {
-		if (Statechart.class.getName().equals(semanticTarget)) {
-			return getEmbeddedStatechartEditorModule();
-		}
-		if (State.class.getName().equals(semanticTarget)) {
-			return getEmbeddedStateEditorModule();
-		}
-		if (Transition.class.getName().equals(semanticTarget)) {
-			return getEmbeddedTransitionEditorModule();
-		}
-		throw new IllegalArgumentException("Illegal semantic target " + semanticTarget);
-	}
-
-	protected Module getEmbeddedTransitionEditorModule() {
-		TransitionExpressionProvider provider = new TransitionExpressionProvider();
-		Module module = provider.getModule();
-		return Modules.combine(module, getTypeSystemModule());
+	public Module getResourceModule() {
+		return Modules.combine(getLanguageRuntimeModule(), getTypeSystemModule());
 	}
 
-	protected Module getEmbeddedStateEditorModule() {
-		StateExpressionProvider provider = new StateExpressionProvider();
-		Module module = provider.getModule();
-		return Modules.combine(module, getTypeSystemModule());
+	@Override
+	public Module getEmbeddedEditorModule(String semanticTarget) {
+		return getEmbeddedEditorModule(semanticTargetToRuleMap.get(semanticTarget));
 	}
 
-	protected Module getEmbeddedStatechartEditorModule() {
-		StatechartExpressionProvider provider = new StatechartExpressionProvider();
-		Module module = provider.getModule();
-		return Modules.combine(module, getTypeSystemModule());
+	protected Module getEmbeddedEditorModule(Class<? extends EObject> rule) {
+		Module runtimeModule = Modules.override(getResourceModule()).with(new EntryRuleRuntimeModule(rule));
+		Module uiModule = Modules.override(getLanguageUIModule()).with(new EntryRuleUIModule(rule));
+		return Modules.override(Modules.override(runtimeModule).with(uiModule)).with(getSharedStateModule());
 	}
-
 }

+ 0 - 34
plugins/org.yakindu.sct.domain.default_/src/org/yakindu/sct/domain/default_/modules/AbstractExpressionsProvider.java

@@ -1,34 +0,0 @@
-/**
- * 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.domain.default_.modules;
-
-import org.eclipse.xtext.ui.shared.SharedStateModule;
-
-import com.google.inject.Module;
-import com.google.inject.util.Modules;
-
-/**
- * Base class for all {@link IExpressionLanguageProvider}s, provides caching of
- * the Injector.
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public abstract class AbstractExpressionsProvider implements IExpressionLanguageProvider {
-
-	protected abstract Module getRuntimeModule();
-
-	protected abstract Module getUIModule();
-
-	public Module getModule() {
-		return Modules.override(Modules.override(getRuntimeModule()).with(getUIModule())).with(new SharedStateModule());
-	}
-}

+ 0 - 30
plugins/org.yakindu.sct.domain.default_/src/org/yakindu/sct/domain/default_/modules/AbstractSTextExpressionProvider.java

@@ -1,30 +0,0 @@
-package org.yakindu.sct.domain.default_.modules;
-
-import org.eclipse.emf.ecore.EObject;
-import org.yakindu.sct.model.stext.STextRuntimeModule;
-import org.yakindu.sct.model.stext.ui.STextUiModule;
-import org.yakindu.sct.model.stext.ui.internal.STextActivator;
-
-import com.google.inject.Module;
-import com.google.inject.util.Modules;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public abstract class AbstractSTextExpressionProvider extends AbstractExpressionsProvider implements
-		IExpressionLanguageProvider {
-
-	@Override
-	protected Module getRuntimeModule() {
-		return Modules.override(new STextRuntimeModule()).with(new EntryRuleRuntimeModule(getRule()));
-	}
-
-	protected abstract Class<? extends EObject> getRule();
-
-	@Override
-	protected Module getUIModule() {
-		return Modules.override(new STextUiModule(STextActivator.getInstance())).with(new EntryRuleUIModule(getRule()));
-	}
-}

+ 0 - 18
plugins/org.yakindu.sct.domain.default_/src/org/yakindu/sct/domain/default_/modules/ExpressionExpressionProvider.java

@@ -1,18 +0,0 @@
-package org.yakindu.sct.domain.default_.modules;
-
-import org.eclipse.emf.ecore.EObject;
-import org.yakindu.sct.model.stext.stext.Guard;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class ExpressionExpressionProvider extends AbstractSTextExpressionProvider {
-
-	@Override
-	protected Class<? extends EObject> getRule() {
-		return Guard.class;
-	}
-
-}

+ 0 - 29
plugins/org.yakindu.sct.domain.default_/src/org/yakindu/sct/domain/default_/modules/IExpressionLanguageProvider.java

@@ -1,29 +0,0 @@
-/**
- * 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.domain.default_.modules;
-
-import com.google.inject.Module;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public interface IExpressionLanguageProvider {
-
-	public Module getModule();
-
-	public static class NullLanguageProvider implements IExpressionLanguageProvider {
-		public Module getModule() {
-			return null;
-		}
-	}
-}

+ 0 - 17
plugins/org.yakindu.sct.domain.default_/src/org/yakindu/sct/domain/default_/modules/StateExpressionProvider.java

@@ -1,17 +0,0 @@
-package org.yakindu.sct.domain.default_.modules;
-
-import org.eclipse.emf.ecore.EObject;
-import org.yakindu.sct.model.stext.stext.StateSpecification;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class StateExpressionProvider extends AbstractSTextExpressionProvider {
-
-	@Override
-	protected Class<? extends EObject> getRule() {
-		return StateSpecification.class;
-	}
-}

+ 0 - 17
plugins/org.yakindu.sct.domain.default_/src/org/yakindu/sct/domain/default_/modules/StatechartExpressionProvider.java

@@ -1,17 +0,0 @@
-package org.yakindu.sct.domain.default_.modules;
-
-import org.eclipse.emf.ecore.EObject;
-import org.yakindu.sct.model.stext.stext.StatechartSpecification;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class StatechartExpressionProvider extends AbstractSTextExpressionProvider {
-
-	@Override
-	protected Class<? extends EObject> getRule() {
-		return StatechartSpecification.class;
-	}
-}

+ 0 - 17
plugins/org.yakindu.sct.domain.default_/src/org/yakindu/sct/domain/default_/modules/TransitionExpressionProvider.java

@@ -1,17 +0,0 @@
-package org.yakindu.sct.domain.default_.modules;
-
-import org.eclipse.emf.ecore.EObject;
-import org.yakindu.sct.model.stext.stext.TransitionSpecification;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class TransitionExpressionProvider extends AbstractSTextExpressionProvider {
-
-	@Override
-	protected Class<? extends EObject> getRule() {
-		return TransitionSpecification.class;
-	}
-}

+ 15 - 0
plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/extension/IDomainModuleProvider.java

@@ -19,6 +19,21 @@ import com.google.inject.Module;
  * 
  */
 public interface IDomainModuleProvider {
+	/**
+	 * Returns the SharedStateModule that is used for in-diagram expression
+	 * language
+	 */
+	public Module getSharedStateModule();
+
+	/**
+	 * Returns the runtime module that is used as in-diagram expression language
+	 */
+	public Module getLanguageRuntimeModule();
+
+	/**
+	 * Returns the ui module that is used as in-diagram expression language
+	 */
+	public Module getLanguageUIModule();
 
 	/**
 	 * Module used to create an instance of {@link AbstractSCTResource}

+ 72 - 0
test-plugins/org.yakindu.sct.test.models/DefaultDomainTest.sct

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:sgraph="http://www.yakindu.org/sct/sgraph/2.0.0">
+  <sgraph:Statechart xmi:id="_2ygK4LKlEeSOQaDmD1fjLA" specification="internal:&#xD;&#xA;" name="DefaultDomainTest">
+    <regions xmi:id="_2yinIrKlEeSOQaDmD1fjLA" name="main region">
+      <vertices xsi:type="sgraph:Entry" xmi:id="_2ym4kbKlEeSOQaDmD1fjLA">
+        <outgoingTransitions xmi:id="_2ypU0bKlEeSOQaDmD1fjLA" target="_2ynfp7KlEeSOQaDmD1fjLA"/>
+      </vertices>
+      <vertices xsi:type="sgraph:State" xmi:id="_2ynfp7KlEeSOQaDmD1fjLA" name="a" incomingTransitions="_2ypU0bKlEeSOQaDmD1fjLA"/>
+    </regions>
+  </sgraph:Statechart>
+  <notation:Diagram xmi:id="_2yinILKlEeSOQaDmD1fjLA" type="org.yakindu.sct.ui.editor.editor.StatechartDiagramEditor" element="_2ygK4LKlEeSOQaDmD1fjLA" measurementUnit="Pixel">
+    <children xmi:id="_2ykcULKlEeSOQaDmD1fjLA" type="Region" element="_2yinIrKlEeSOQaDmD1fjLA">
+      <children xsi:type="notation:DecorationNode" xmi:id="_2ymRgLKlEeSOQaDmD1fjLA" type="RegionName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_2ymRgbKlEeSOQaDmD1fjLA"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_2ymRgrKlEeSOQaDmD1fjLA"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_2ymRg7KlEeSOQaDmD1fjLA" type="RegionCompartment" fontName="Verdana" lineColor="4210752">
+        <children xmi:id="_2ym4krKlEeSOQaDmD1fjLA" type="Entry" element="_2ym4kbKlEeSOQaDmD1fjLA">
+          <children xmi:id="_2ynfoLKlEeSOQaDmD1fjLA" type="BorderItemLabelContainer">
+            <children xsi:type="notation:DecorationNode" xmi:id="_2ynfo7KlEeSOQaDmD1fjLA" type="BorderItemLabel">
+              <styles xsi:type="notation:ShapeStyle" xmi:id="_2ynfpLKlEeSOQaDmD1fjLA"/>
+              <layoutConstraint xsi:type="notation:Location" xmi:id="_2ynfpbKlEeSOQaDmD1fjLA"/>
+            </children>
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_2ynfobKlEeSOQaDmD1fjLA" fontName="Verdana" lineColor="4210752"/>
+            <layoutConstraint xsi:type="notation:Bounds" xmi:id="_2ynforKlEeSOQaDmD1fjLA"/>
+          </children>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_2ym4k7KlEeSOQaDmD1fjLA" fontName="Verdana" lineColor="4210752"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_2ynfprKlEeSOQaDmD1fjLA" x="70" y="20"/>
+        </children>
+        <children xmi:id="_2yoGsrKlEeSOQaDmD1fjLA" type="State" element="_2ynfp7KlEeSOQaDmD1fjLA">
+          <children xsi:type="notation:DecorationNode" xmi:id="_2yoGtrKlEeSOQaDmD1fjLA" type="StateName">
+            <styles xsi:type="notation:ShapeStyle" xmi:id="_2yoGt7KlEeSOQaDmD1fjLA"/>
+            <layoutConstraint xsi:type="notation:Location" xmi:id="_2yoGuLKlEeSOQaDmD1fjLA"/>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_2yotwLKlEeSOQaDmD1fjLA" type="StateTextCompartment">
+            <children xsi:type="notation:Shape" xmi:id="_2yotwbKlEeSOQaDmD1fjLA" type="StateTextCompartmentExpression" fontName="Verdana" lineColor="4210752">
+              <layoutConstraint xsi:type="notation:Bounds" xmi:id="_2yotwrKlEeSOQaDmD1fjLA"/>
+            </children>
+          </children>
+          <children xsi:type="notation:Compartment" xmi:id="_2yotw7KlEeSOQaDmD1fjLA" type="StateFigureCompartment"/>
+          <styles xsi:type="notation:ShapeStyle" xmi:id="_2yoGs7KlEeSOQaDmD1fjLA" fontName="Verdana" fillColor="15981773" lineColor="12632256"/>
+          <styles xsi:type="notation:FontStyle" xmi:id="_2yoGtLKlEeSOQaDmD1fjLA"/>
+          <styles xsi:type="notation:BooleanValueStyle" xmi:id="_2yotxLKlEeSOQaDmD1fjLA" name="isHorizontal" booleanValue="true"/>
+          <layoutConstraint xsi:type="notation:Bounds" xmi:id="_2ypU0LKlEeSOQaDmD1fjLA" x="40" y="80"/>
+        </children>
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_2ymRhLKlEeSOQaDmD1fjLA"/>
+      </children>
+      <styles xsi:type="notation:ShapeStyle" xmi:id="_2ykcUbKlEeSOQaDmD1fjLA" fontName="Verdana" fillColor="15790320" lineColor="12632256"/>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_2ym4kLKlEeSOQaDmD1fjLA" x="220" y="10" width="400" height="400"/>
+    </children>
+    <children xsi:type="notation:Shape" xmi:id="_2yqi87KlEeSOQaDmD1fjLA" type="StatechartText" fontName="Verdana" lineColor="4210752">
+      <children xsi:type="notation:DecorationNode" xmi:id="_2yqi9bKlEeSOQaDmD1fjLA" type="StatechartName">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_2yqi9rKlEeSOQaDmD1fjLA"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_2yqi97KlEeSOQaDmD1fjLA"/>
+      </children>
+      <children xsi:type="notation:Shape" xmi:id="_2yqi-LKlEeSOQaDmD1fjLA" type="StatechartTextExpression" fontName="Verdana" lineColor="4210752">
+        <layoutConstraint xsi:type="notation:Bounds" xmi:id="_2yqi-bKlEeSOQaDmD1fjLA"/>
+      </children>
+      <layoutConstraint xsi:type="notation:Bounds" xmi:id="_2yrKALKlEeSOQaDmD1fjLA" x="10" y="10" width="200" height="400"/>
+    </children>
+    <styles xsi:type="notation:DiagramStyle" xmi:id="_2yinIbKlEeSOQaDmD1fjLA"/>
+    <edges xmi:id="_2yp74LKlEeSOQaDmD1fjLA" type="Transition" element="_2ypU0bKlEeSOQaDmD1fjLA" source="_2ym4krKlEeSOQaDmD1fjLA" target="_2yoGsrKlEeSOQaDmD1fjLA">
+      <children xsi:type="notation:DecorationNode" xmi:id="_2yqi8LKlEeSOQaDmD1fjLA" type="TransitionExpression">
+        <styles xsi:type="notation:ShapeStyle" xmi:id="_2yqi8bKlEeSOQaDmD1fjLA"/>
+        <layoutConstraint xsi:type="notation:Location" xmi:id="_2yqi8rKlEeSOQaDmD1fjLA" y="10"/>
+      </children>
+      <styles xsi:type="notation:ConnectorStyle" xmi:id="_2yp74bKlEeSOQaDmD1fjLA" lineColor="4210752"/>
+      <styles xsi:type="notation:FontStyle" xmi:id="_2yp747KlEeSOQaDmD1fjLA" fontName="Verdana"/>
+      <bendpoints xsi:type="notation:RelativeBendpoints" xmi:id="_2yp74rKlEeSOQaDmD1fjLA" points="[0, 0, 0, 0]$[0, 0, 0, 0]"/>
+    </edges>
+  </notation:Diagram>
+</xmi:XMI>