From 1477611bce9ee7ae9244f74cb72ac8397fd46585 Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Fri, 29 Apr 2016 12:30:39 +0000
Subject: [PATCH] Added first tutorial for data dictionary. refs 2567

---
 .../trunk/model/kernel.ecore                  | 11 -----
 .../trunk/model/kernel.genmodel               |  7 ---
 .../kernel/extension/ITutorialProvider.java   | 47 +++++++++++++++++++
 .../extension/ITutorialWhitelistProvider.java |  7 ++-
 .../kernel/extension/data/TutorialStep.java   | 35 ++++++++++++++
 .../kernel/internal/TutorialService.java      | 43 +++++++++++------
 .../kernel/service/ITutorialService.java      | 16 +++----
 .../utils/TutorialModelElementFactory.java    | 39 +++++++++++++++
 8 files changed, 164 insertions(+), 41 deletions(-)
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/ITutorialProvider.java
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/TutorialStep.java
 create mode 100644 org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TutorialModelElementFactory.java

diff --git a/org.fortiss.tooling.kernel/trunk/model/kernel.ecore b/org.fortiss.tooling.kernel/trunk/model/kernel.ecore
index ce0afb052..736480c48 100644
--- a/org.fortiss.tooling.kernel/trunk/model/kernel.ecore
+++ b/org.fortiss.tooling.kernel/trunk/model/kernel.ecore
@@ -165,17 +165,6 @@
       nsPrefix="org-fortiss-tooling-kernel-tutorial">
     <eClassifiers xsi:type="ecore:EClass" name="TutorialDefinition">
       <eStructuralFeatures xsi:type="ecore:EAttribute" name="title" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
-      <eStructuralFeatures xsi:type="ecore:EAttribute" name="globalWhitelistProviderClassName"
-          eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
-      <eStructuralFeatures xsi:type="ecore:EReference" name="steps" lowerBound="1"
-          upperBound="-1" eType="#//tutorial/TutorialStep" containment="true"/>
-    </eClassifiers>
-    <eClassifiers xsi:type="ecore:EClass" name="TutorialStep">
-      <eStructuralFeatures xsi:type="ecore:EAttribute" name="whitelistProviderClassName"
-          eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
-      <eStructuralFeatures xsi:type="ecore:EAttribute" name="completionCheckerClassName"
-          eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
-      <eStructuralFeatures xsi:type="ecore:EAttribute" name="description" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
     </eClassifiers>
   </eSubpackages>
 </ecore:EPackage>
diff --git a/org.fortiss.tooling.kernel/trunk/model/kernel.genmodel b/org.fortiss.tooling.kernel/trunk/model/kernel.genmodel
index 4310e447b..f02c3c377 100644
--- a/org.fortiss.tooling.kernel/trunk/model/kernel.genmodel
+++ b/org.fortiss.tooling.kernel/trunk/model/kernel.genmodel
@@ -83,13 +83,6 @@
         disposableProviderFactory="true" ecorePackage="kernel.ecore#//tutorial">
       <genClasses ecoreClass="kernel.ecore#//tutorial/TutorialDefinition">
         <genFeatures createChild="false" ecoreFeature="ecore:EAttribute kernel.ecore#//tutorial/TutorialDefinition/title"/>
-        <genFeatures createChild="false" ecoreFeature="ecore:EAttribute kernel.ecore#//tutorial/TutorialDefinition/globalWhitelistProviderClassName"/>
-        <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference kernel.ecore#//tutorial/TutorialDefinition/steps"/>
-      </genClasses>
-      <genClasses ecoreClass="kernel.ecore#//tutorial/TutorialStep">
-        <genFeatures createChild="false" ecoreFeature="ecore:EAttribute kernel.ecore#//tutorial/TutorialStep/whitelistProviderClassName"/>
-        <genFeatures createChild="false" ecoreFeature="ecore:EAttribute kernel.ecore#//tutorial/TutorialStep/completionCheckerClassName"/>
-        <genFeatures createChild="false" ecoreFeature="ecore:EAttribute kernel.ecore#//tutorial/TutorialStep/description"/>
       </genClasses>
     </nestedGenPackages>
   </genPackages>
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/ITutorialProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/ITutorialProvider.java
new file mode 100644
index 000000000..a42a761ef
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/ITutorialProvider.java
@@ -0,0 +1,47 @@
+/*--------------------------------------------------------------------------+
+$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+|                                                                          |
+| Copyright 2016 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.kernel.extension;
+
+import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
+import org.fortiss.tooling.kernel.extension.data.TutorialStep;
+import org.fortiss.tooling.kernel.model.tutorial.TutorialDefinition;
+
+/**
+ * A tutorial provider provides all data about a single tutorial to the kernel infrastructure.
+ * 
+ * @author hoelzl
+ * @author $Author: hoelzl $
+ * @version $Rev: 18709 $
+ * @ConQAT.Rating RED Hash:
+ */
+public interface ITutorialProvider {
+	/** Returns the top-level element of this tutorial. */
+	public ITopLevelElement getTopLevelElement();
+
+	/** Returns the tutorial definition element. */
+	public TutorialDefinition getTutorialDefinition();
+
+	/** Returns the initial step of this tutorial. */
+	public TutorialStep getInitialStep();
+
+	/** Returns the next tutorial step for the given step. */
+	public TutorialStep getNextStep(TutorialStep step);
+
+	/** Returns the global whitelist provider. */
+	public ITutorialWhitelistProvider getGlobalWhitelistProvider();
+}
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/ITutorialWhitelistProvider.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/ITutorialWhitelistProvider.java
index 66e3b02a5..5778975b9 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/ITutorialWhitelistProvider.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/ITutorialWhitelistProvider.java
@@ -17,6 +17,8 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
 +--------------------------------------------------------------------------*/
 package org.fortiss.tooling.kernel.extension;
 
+import org.eclipse.emf.ecore.EObject;
+
 /**
  * Instances of this interface provide white lists for tool functions
  * globally enabled in tutorial or locally enabled in a tutorial step.
@@ -27,5 +29,8 @@ package org.fortiss.tooling.kernel.extension;
  * @ConQAT.Rating RED Hash:
  */
 public interface ITutorialWhitelistProvider {
-	// TODO: define
+	/** Returns whether the given element should be displayed in the navigator tree. */
+	public boolean displayElementInNavigator(EObject element);
+
+	// TODO: define other methods
 }
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/TutorialStep.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/TutorialStep.java
new file mode 100644
index 000000000..ed5e29b87
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/extension/data/TutorialStep.java
@@ -0,0 +1,35 @@
+/*--------------------------------------------------------------------------+
+$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+|                                                                          |
+| Copyright 2016 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.kernel.extension.data;
+
+import org.fortiss.tooling.kernel.extension.ITutorialWhitelistProvider;
+
+/**
+ * Data class for steps of tutorials.
+ * 
+ * @author hoelzl
+ * @author $Author: hoelzl $
+ * @version $Rev: 18709 $
+ * @ConQAT.Rating RED Hash:
+ */
+public abstract class TutorialStep {
+	/** Returns the step-specific whitelist provider. */
+	public ITutorialWhitelistProvider getWhitelistProvider() {
+		return null;
+	}
+}
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/TutorialService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/TutorialService.java
index 232b4bbf5..8bf675b25 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/TutorialService.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/internal/TutorialService.java
@@ -22,8 +22,10 @@ import java.util.Collection;
 import java.util.List;
 
 import org.conqat.lib.commons.collections.UnmodifiableList;
-import org.fortiss.tooling.kernel.model.tutorial.TutorialDefinition;
-import org.fortiss.tooling.kernel.model.tutorial.TutorialStep;
+import org.eclipse.emf.ecore.EObject;
+import org.fortiss.tooling.kernel.extension.ITutorialProvider;
+import org.fortiss.tooling.kernel.extension.ITutorialWhitelistProvider;
+import org.fortiss.tooling.kernel.extension.data.TutorialStep;
 import org.fortiss.tooling.kernel.service.ITutorialService;
 
 /**
@@ -34,13 +36,13 @@ import org.fortiss.tooling.kernel.service.ITutorialService;
  * @version $Rev: 18709 $
  * @ConQAT.Rating RED Hash:
  */
-public final class TutorialService implements ITutorialService {
+public final class TutorialService implements ITutorialService, ITutorialWhitelistProvider {
 
 	/** The collection of all defined tutorials. */
-	private List<TutorialDefinition> allTutorials = new ArrayList<>();
+	private List<ITutorialProvider> allTutorials = new ArrayList<>();
 
 	/** The active tutorial. */
-	private TutorialDefinition activeTutorial = null;
+	private ITutorialProvider activeTutorial = null;
 	/** The active tutorial step. */
 	private TutorialStep activeStep = null;
 
@@ -52,7 +54,7 @@ public final class TutorialService implements ITutorialService {
 
 	/** {@inheritDoc} */
 	@Override
-	public TutorialDefinition getActiveTutorial() {
+	public ITutorialProvider getActiveTutorial() {
 		return activeTutorial;
 	}
 
@@ -64,24 +66,23 @@ public final class TutorialService implements ITutorialService {
 
 	/** {@inheritDoc} */
 	@Override
-	public Collection<TutorialDefinition> getAllTutorials() {
+	public Collection<ITutorialProvider> getAllTutorialProviders() {
 		return new UnmodifiableList<>(allTutorials);
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public void registerTutorial(TutorialDefinition definition) {
-		if(!allTutorials.contains(definition)) {
-			allTutorials.add(definition);
+	public void registerTutorial(ITutorialProvider provider) {
+		if(!allTutorials.contains(provider)) {
+			allTutorials.add(provider);
 		}
 	}
 
 	/** {@inheritDoc} */
 	@Override
-	public void startTutorial(TutorialDefinition definition) {
-		activeTutorial = definition;
-		// steps relation is 1..* => get(0) always works
-		activeStep = activeTutorial.getSteps().get(0);
+	public void startTutorial(ITutorialProvider provider) {
+		activeTutorial = provider;
+		activeStep = activeTutorial.getInitialStep();
 	}
 
 	/** {@inheritDoc} */
@@ -90,4 +91,18 @@ public final class TutorialService implements ITutorialService {
 		activeStep = null;
 		activeTutorial = null;
 	}
+
+	/** {@inheritDoc} */
+	@Override
+	public boolean displayElementInNavigator(EObject element) {
+		if(activeTutorial == null || activeStep == null) {
+			return false;
+		}
+		ITutorialWhitelistProvider global = activeTutorial.getGlobalWhitelistProvider();
+		if(global != null && global.displayElementInNavigator(element)) {
+			return true;
+		}
+		ITutorialWhitelistProvider local = activeStep.getWhitelistProvider();
+		return local != null && local.displayElementInNavigator(element);
+	}
 }
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/service/ITutorialService.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/service/ITutorialService.java
index c7274ee68..2b90ce4e5 100644
--- a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/service/ITutorialService.java
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/service/ITutorialService.java
@@ -19,9 +19,9 @@ package org.fortiss.tooling.kernel.service;
 
 import java.util.Collection;
 
+import org.fortiss.tooling.kernel.extension.ITutorialProvider;
+import org.fortiss.tooling.kernel.extension.data.TutorialStep;
 import org.fortiss.tooling.kernel.internal.TutorialService;
-import org.fortiss.tooling.kernel.model.tutorial.TutorialDefinition;
-import org.fortiss.tooling.kernel.model.tutorial.TutorialStep;
 
 /**
  * The tutorial service provides pre-defined models with step-wise
@@ -41,10 +41,10 @@ public interface ITutorialService {
 	public boolean isTutorialActive();
 
 	/** Returns the current tutorial definition or <code>null</code> if no tutorial is active. */
-	public TutorialDefinition getActiveTutorial();
+	public ITutorialProvider getActiveTutorial();
 
 	/** Starts the given tutorial. */
-	public void startTutorial(TutorialDefinition definition);
+	public void startTutorial(ITutorialProvider provider);
 
 	/** Stops the current tutorial. */
 	public void stopTutorial();
@@ -52,9 +52,9 @@ public interface ITutorialService {
 	/** Returns the active tutorial step. */
 	public TutorialStep getActiveTutorialStep();
 
-	/** Returns all registered tutorial definitions. */
-	public Collection<TutorialDefinition> getAllTutorials();
+	/** Returns all registered tutorial providers. */
+	public Collection<ITutorialProvider> getAllTutorialProviders();
 
-	/** Programmatically register a tutorial. */
-	public void registerTutorial(TutorialDefinition definition);
+	/** Programmatically register a tutorial provider. */
+	public void registerTutorial(ITutorialProvider provider);
 }
diff --git a/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TutorialModelElementFactory.java b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TutorialModelElementFactory.java
new file mode 100644
index 000000000..7e629f6b2
--- /dev/null
+++ b/org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/TutorialModelElementFactory.java
@@ -0,0 +1,39 @@
+/*--------------------------------------------------------------------------+
+$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+|                                                                          |
+| Copyright 2016 ForTISS GmbH                     |
+|                                                                          |
+| Licensed under the Apache License, Version 2.0 (the "License");          |
+| you may not use this file except in compliance with the License.         |
+| You may obtain a copy of the License at                                  |
+|                                                                          |
+|    http://www.apache.org/licenses/LICENSE-2.0                            |
+|                                                                          |
+| Unless required by applicable law or agreed to in writing, software      |
+| distributed under the License is distributed on an "AS IS" BASIS,        |
+| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+| See the License for the specific language governing permissions and      |
+| limitations under the License.                                           |
++--------------------------------------------------------------------------*/
+package org.fortiss.tooling.kernel.utils;
+
+import org.fortiss.tooling.kernel.model.tutorial.TutorialDefinition;
+import org.fortiss.tooling.kernel.model.tutorial.TutorialFactory;
+
+/**
+ * Model element factory class for creating tutorial elements.
+ * 
+ * @author hoelzl
+ * @author $Author: hoelzl $
+ * @version $Rev: 18709 $
+ * @ConQAT.Rating YELLOW Hash: 02F9DA7746CF3596881BF3775CE80BAB
+ */
+public final class TutorialModelElementFactory {
+
+	/** Creates a {@link TutorialDefinition}. */
+	public static TutorialDefinition createTutorialDefinition(String title) {
+		TutorialDefinition def = TutorialFactory.eINSTANCE.createTutorialDefinition();
+		def.setTitle(title);
+		return def;
+	}
+}
-- 
GitLab