Skip to content
Snippets Groups Projects
Commit 76ad70a8 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

Fixed exception thrown at the second start of the same tutorial. Now tutorial...

Fixed exception thrown at the second start of the same tutorial. Now tutorial provider is instantiated at start of tutorial.
refs 2567
parent a127a49f
No related branches found
No related tags found
No related merge requests found
......@@ -29,9 +29,6 @@ import org.fortiss.tooling.kernel.extension.data.TutorialStep;
* @ConQAT.Rating RED Hash:
*/
public interface ITutorialProvider {
/** Returns the description of the tutorial. */
public String getDescription();
/** Returns the root element of this tutorial. */
public EObject getRootElement();
......
......@@ -17,11 +17,10 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.internal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import org.conqat.lib.commons.collections.UnmodifiableList;
import org.conqat.lib.commons.collections.UnmodifiableMap;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.ITutorialProvider;
import org.fortiss.tooling.kernel.extension.ITutorialWhitelistProvider;
......@@ -40,7 +39,7 @@ import org.fortiss.tooling.kernel.service.ITutorialService;
public final class TutorialService implements ITutorialService, ITutorialWhitelistProvider {
/** The collection of all defined tutorials. */
private List<ITutorialProvider> allTutorials = new ArrayList<>();
private Map<String, Class<? extends ITutorialProvider>> allTutorials = new HashMap<>();
/** The active tutorial. */
private ITutorialProvider activeTutorial = null;
......@@ -67,32 +66,38 @@ public final class TutorialService implements ITutorialService, ITutorialWhiteli
/** {@inheritDoc} */
@Override
public Collection<ITutorialProvider> getAllTutorialProviders() {
return new UnmodifiableList<>(allTutorials);
public Map<String, Class<? extends ITutorialProvider>> getAllTutorialProviders() {
return new UnmodifiableMap<String, Class<? extends ITutorialProvider>>(allTutorials);
}
/** {@inheritDoc} */
@Override
public void registerTutorial(ITutorialProvider provider) {
if(!allTutorials.contains(provider)) {
allTutorials.add(provider);
}
public void registerTutorial(String name, Class<? extends ITutorialProvider> provider) {
allTutorials.put(name, provider);
}
/** {@inheritDoc} */
@Override
public void startTutorial(ITutorialProvider provider) {
activeTutorial = provider;
activeStep = activeTutorial.getInitialStep();
IPersistencyService.INSTANCE.addDummyEObjectAsTopLevelElement(activeTutorial
.getRootElement());
System.out.println("start tutorial for provider: " + activeTutorial.getClass().getName());
public void startTutorial(String name) {
if(!allTutorials.containsKey(name)) {
return;
}
try {
activeTutorial = allTutorials.get(name).newInstance();
activeStep = activeTutorial.getInitialStep();
EObject root = activeTutorial.getRootElement();
IPersistencyService.INSTANCE.addDummyEObjectAsTopLevelElement(root);
} catch(InstantiationException e) {
e.printStackTrace();
} catch(IllegalAccessException e) {
e.printStackTrace();
}
}
/** {@inheritDoc} */
@Override
public void stopTutorial() {
IPersistencyService.INSTANCE.removeDummyTopLevelElement(activeTutorial.getRootElement());
activeStep = null;
activeTutorial = null;
}
......
......@@ -17,7 +17,7 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.service;
import java.util.Collection;
import java.util.Map;
import org.fortiss.tooling.kernel.extension.ITutorialProvider;
import org.fortiss.tooling.kernel.extension.data.TutorialStep;
......@@ -44,7 +44,7 @@ public interface ITutorialService {
public ITutorialProvider getActiveTutorial();
/** Starts the given tutorial. */
public void startTutorial(ITutorialProvider provider);
public void startTutorial(String name);
/** Stops the current tutorial. */
public void stopTutorial();
......@@ -53,8 +53,8 @@ public interface ITutorialService {
public TutorialStep getActiveTutorialStep();
/** Returns all registered tutorial providers. */
public Collection<ITutorialProvider> getAllTutorialProviders();
public Map<String, Class<? extends ITutorialProvider>> getAllTutorialProviders();
/** Programmatically register a tutorial provider. */
public void registerTutorial(ITutorialProvider provider);
public void registerTutorial(String name, Class<? extends ITutorialProvider> provider);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment