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

Fixed tutorial step status display.

refs 2567
parent ee289a2a
No related branches found
No related tags found
No related merge requests found
......@@ -54,17 +54,13 @@ public class TutorialDefinitionModelElementLabelProvider extends ModelElementLab
/** Returns the image for the tutorial step. */
private Image getTutorialStepImage(TutorialStepBase element) {
if(element.getParent() == null) {
// root element of a tutorial definition
return ESharedImages.TUTORIAL.getImage();
}
ITutorialService s = ITutorialService.INSTANCE;
if(s.isEarlierThanActiveStep(element)) {
if(s.isCompletedStep(element)) {
return ESharedImages.OK.getImage();
}
if(s.isLaterThanActiveStep(element)) {
return ESharedImages.TUTORIAL_TODO.getImage();
if(s.getActiveTutorialStep() == element) {
return ESharedImages.TUTORIAL.getImage();
}
return ESharedImages.TUTORIAL.getImage();
return ESharedImages.TUTORIAL_TODO.getImage();
}
}
......@@ -33,7 +33,6 @@ import org.eclipse.emf.common.command.CommandStackListener;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.ToolingKernelActivator;
import org.fortiss.tooling.kernel.extension.ITutorialProvider;
import org.fortiss.tooling.kernel.extension.ITutorialStepCompletionChecker;
import org.fortiss.tooling.kernel.extension.ITutorialWhitelistProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.extension.data.Prototype;
......@@ -62,6 +61,8 @@ public final class TutorialService implements ITutorialService, CommandStackList
new LinkedList<ITutorialServiceListener>();
/** The list of atomic steps. */
private List<TutorialAtomicStep> atomicStepList = new ArrayList<TutorialAtomicStep>();
/** The last element of the atomic step list, i.e., the final step. */
private TutorialAtomicStep finalAtomicStep;
/** The active tutorial. */
private ITutorialProvider activeTutorial = null;
......@@ -128,6 +129,7 @@ public final class TutorialService implements ITutorialService, CommandStackList
collectAtomicSteps(step);
}
activeStep = atomicStepList.get(0);
finalAtomicStep = atomicStepList.get(atomicStepList.size() - 1);
EObject root = activeTutorial.getRootElement();
activeTopElement = IPersistencyService.INSTANCE.addDummyEObjectAsTopLevelElement(root);
ICommandStackService.INSTANCE.addCommandStackListener(activeTopElement, this);
......@@ -195,69 +197,52 @@ public final class TutorialService implements ITutorialService, CommandStackList
/** {@inheritDoc} */
@Override
public boolean isEarlierThanActiveStep(TutorialStepBase step) {
if(activeStep == TUTORIAL_COMPLETED_STEP) {
return true;
}
public boolean isCompletedStep(TutorialStepBase step) {
if(step instanceof TutorialCompositeStep) {
TutorialCompositeStep cmp = (TutorialCompositeStep)step;
TutorialStepBase inner = cmp.getSteps().get(cmp.getSteps().size() - 1);
return isEarlierThanActiveStep(inner);
return isCompletedStep(inner);
}
// TutorialStepAtomic
int current = atomicStepList.indexOf(activeStep);
int test = atomicStepList.indexOf(step);
return test < current;
if(step == activeStep) {
return activeStep.getCompletionChecker().isTutorialStepComplete(
activeTutorial.getRootElement());
}
if(isEarlierThanActiveStep(step)) {
return true;
}
return false;
}
/** {@inheritDoc} */
@Override
public boolean isLaterThanActiveStep(TutorialStepBase step) {
if(activeStep == TUTORIAL_COMPLETED_STEP) {
return false;
}
/** Returns whether the given step is an earlier step than the current one. */
private boolean isEarlierThanActiveStep(TutorialStepBase step) {
if(step instanceof TutorialCompositeStep) {
TutorialCompositeStep cmp = (TutorialCompositeStep)step;
TutorialStepBase inner = cmp.getSteps().get(cmp.getSteps().size() - 1);
return isLaterThanActiveStep(inner);
return isEarlierThanActiveStep(inner);
}
// TutorialStepAtomic
int current = atomicStepList.indexOf(activeStep);
int test = atomicStepList.indexOf(step);
return test > current;
return test < current;
}
/** {@inheritDoc} */
@Override
public void commandStackChanged(EventObject event) {
TutorialAtomicStep old = activeStep;
activeStep = TUTORIAL_COMPLETED_STEP;
activeStep = finalAtomicStep;
for(TutorialAtomicStep step : atomicStepList) {
if(!step.getCompletionChecker().isTutorialStepComplete(activeTutorial.getRootElement())) {
activeStep = step;
break;
}
}
if(activeStep != old) {
if(activeStep != old || activeStep == finalAtomicStep) {
fireTutorialStepChanged();
}
}
/** The shared hidden final state of all tutorials. */
private static TutorialAtomicStep TUTORIAL_COMPLETED_STEP = new TutorialAtomicStep(
"Tutorial complete.") {
@Override
public ITutorialStepCompletionChecker getCompletionChecker() {
return new ITutorialStepCompletionChecker() {
@Override
public boolean isTutorialStepComplete(EObject model) {
// This step can never be completed.
return false;
}
};
}
};
/** {@inheritDoc} */
@Override
public List<TutorialAtomicStep> getAtomicTutorialSteps() {
......
......@@ -68,11 +68,8 @@ public interface ITutorialService extends ITutorialWhitelistProvider {
/** Returns the active tutorial step. */
public TutorialStepBase getActiveTutorialStep();
/** Returns whether the given step is an earlier step than the current one. */
public boolean isEarlierThanActiveStep(TutorialStepBase step);
/** Returns whether the given step is a later step than the current one. */
public boolean isLaterThanActiveStep(TutorialStepBase step);
/** Returns whether the given step is completed. */
public boolean isCompletedStep(TutorialStepBase step);
/** Returns all registered tutorial providers for the given category. */
public Map<String, Class<? extends ITutorialProvider>> getAllTutorialProviders(String category);
......
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