Pārlūkot izejas kodu

Merge pull request #242 from Yakindu/issue_simulation

Issue simulation
Andreas Mülder 9 gadi atpakaļ
vecāks
revīzija
a6237020c8

+ 7 - 6
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/interpreter/DefaultTimingService.java

@@ -50,7 +50,8 @@ public class DefaultTimingService implements ITimingService {
 		timerTasks = new HashMap<String, TimerTask>();
 	}
 
-	public void scheduleTimeEvent(ExecutionContext context, String eventName, boolean isPeriodical, long duration) {
+	public synchronized void scheduleTimeEvent(ExecutionContext context, String eventName, boolean isPeriodical,
+			long duration) {
 		TimeEventTask timeEventTask = new TimeEventTask(context, eventName);
 		timerTasks.put(eventName, timeEventTask);
 		if (isPeriodical) {
@@ -60,20 +61,20 @@ public class DefaultTimingService implements ITimingService {
 		}
 	}
 
-	public void unscheduleTimeEvent(String eventName) {
+	public synchronized void unscheduleTimeEvent(String eventName) {
 		TimerTask timerTask = timerTasks.get(eventName);
 		timerTask.cancel();
 	}
-
-	public void pause() {
+	
+	public synchronized void pause() {
 		throw new RuntimeException("Implement me");
 	}
 
-	public void resume() {
+	public synchronized void resume() {
 		throw new RuntimeException("Implement me");
 	}
 
-	public void stop() {
+	public synchronized void stop() {
 		Collection<TimerTask> values = timerTasks.values();
 		for (TimerTask timerTask : values) {
 			timerTask.cancel();

+ 0 - 1
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/model/presenter/DefaultDynamicNotationHandler.java

@@ -56,7 +56,6 @@ public class DefaultDynamicNotationHandler extends AbstractDynamicNotationHandle
 		if (this.currentContext != null)
 			this.currentContext.eAdapters().remove(visualizer);
 		visualizer.setHighlightingSupport(NULL_SUPPORT);
-		setHighlightingSupport(NULL_SUPPORT);
 	}
 
 	@Override

+ 12 - 10
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/model/presenter/SCTSourceDisplay.java

@@ -63,29 +63,31 @@ public class SCTSourceDisplay implements ISourceDisplay {
 
 	public void displaySource(IEditorPart editor) {
 		IDynamicNotationHandler notationHandler = handler.get(editor);
+		IHighlightingSupport support = (IHighlightingSupport) editor.getAdapter(IHighlightingSupport.class);
+		if (support == null)
+			return;
 		if (notationHandler == null) {
 			notationHandler = new DefaultDynamicNotationHandler();
-			IHighlightingSupport support = (IHighlightingSupport) editor.getAdapter(IHighlightingSupport.class);
-			if (support == null)
-				return;
-			notationHandler.setHighlightingSupport(support);
 			handler.put(editor, notationHandler);
+		} else {
+			notationHandler.setHighlightingSupport(new IHighlightingSupport.HighlightingSupportNullImpl());
 		}
-		if (notationHandler.getHighlightingSupport().isLocked()) {
-			notationHandler.getHighlightingSupport().releaseEditor();
+		if (support.isLocked()) {
+			support.releaseEditor();
 		}
-		notationHandler.getHighlightingSupport().lockEditor();
+		support.lockEditor();
+		notationHandler.setHighlightingSupport(support);
 		notationHandler.display(container.getExecutionContext());
 	}
 
-	public void terminate() {
+	public void terminate(boolean release) {
 		container = null;
 		debugElement = null;
 		Collection<IDynamicNotationHandler> values = handler.values();
 		for (IDynamicNotationHandler notationHandler : values) {
-			if (notationHandler.getHighlightingSupport().isLocked())
-				notationHandler.getHighlightingSupport().releaseEditor();
 			notationHandler.terminate();
+			if (release && notationHandler.getHighlightingSupport().isLocked())
+				notationHandler.getHighlightingSupport().releaseEditor();
 		}
 		handler.clear();
 	}

+ 3 - 2
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/model/presenter/SCTSourceDisplayDispatcher.java

@@ -52,7 +52,7 @@ public class SCTSourceDisplayDispatcher implements ISourceDisplay, IDebugEventSe
 			return;
 		if (newTarget != null && activeDebugTarget != newTarget){
 			if (activeSourceDisplay != null)
-				activeSourceDisplay.terminate();
+				activeSourceDisplay.terminate(false);
 			activeSourceDisplay = new SCTSourceDisplay(
 					(ISimulationEngine) newTarget.getAdapter(ISimulationEngine.class));
 		}
@@ -91,7 +91,8 @@ public class SCTSourceDisplayDispatcher implements ISourceDisplay, IDebugEventSe
 		if (source instanceof IDebugTarget) {
 			IDebugTarget target = (IDebugTarget) source;
 			if (target == activeDebugTarget) {
-				activeSourceDisplay.terminate();
+				activeSourceDisplay.terminate(true);
+				activeSourceDisplay = null;
 			}
 		}
 	}