Browse Source

Merge pull request #157 from Yakindu/#Bugfix_44

#44 SCTSourceDisplayDispatcher registers itself as a Workbench
Andreas Mülder 9 years ago
parent
commit
802dbdffed

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

@@ -61,7 +61,7 @@ public class SCTSourceDisplay implements ISourceDisplay {
 		displaySource(editor);
 	}
 
-	private void displaySource(IEditorPart editor) {
+	public void displaySource(IEditorPart editor) {
 		IDynamicNotationHandler notationHandler = handler.get(editor);
 		if (notationHandler == null) {
 			notationHandler = new DefaultDynamicNotationHandler();

+ 56 - 9
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/model/presenter/SCTSourceDisplayDispatcher.java

@@ -19,8 +19,15 @@ import org.eclipse.debug.core.IDebugEventSetListener;
 import org.eclipse.debug.core.model.DebugElement;
 import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.ui.sourcelookup.ISourceDisplay;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPartListener;
 import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
 import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
+import org.yakindu.sct.ui.editor.partitioning.DiagramEditorInput;
 
 /**
  * Creates a {@link SCTSourceDisplay} for each {@link IDebugTarget} and
@@ -30,26 +37,29 @@ import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public class SCTSourceDisplayDispatcher implements ISourceDisplay, IDebugEventSetListener {
+public class SCTSourceDisplayDispatcher implements ISourceDisplay, IDebugEventSetListener, IPartListener {
 
 	private Map<IDebugTarget, SCTSourceDisplay> target2Display;
+	private SCTSourceDisplay activeSourceDisplay;
+	private DebugElement activeDebugTarget;
 
 	public SCTSourceDisplayDispatcher() {
 		target2Display = new HashMap<IDebugTarget, SCTSourceDisplay>();
 		DebugPlugin.getDefault().addDebugEventListener(this);
+		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().addPartListener(this);
 	}
 
 	public void displaySource(Object element, IWorkbenchPage page, boolean forceSourceLookup) {
-		DebugElement debugElement = (DebugElement) element;
-		if (debugElement.getDebugTarget().isTerminated())
+		activeDebugTarget = (DebugElement) element;
+		if (activeDebugTarget.getDebugTarget().isTerminated())
 			return;
-		SCTSourceDisplay sourceDisplay = target2Display.get(debugElement.getDebugTarget());
-		if (sourceDisplay == null) {
-			sourceDisplay = new SCTSourceDisplay(
-					(ISimulationEngine) debugElement.getAdapter(ISimulationEngine.class));
-			target2Display.put(debugElement.getDebugTarget(), sourceDisplay);
+		activeSourceDisplay = target2Display.get(activeDebugTarget.getDebugTarget());
+		if (activeSourceDisplay == null) {
+			activeSourceDisplay = new SCTSourceDisplay(
+					(ISimulationEngine) activeDebugTarget.getAdapter(ISimulationEngine.class));
+			target2Display.put(activeDebugTarget.getDebugTarget(), activeSourceDisplay);
 		}
-		sourceDisplay.displaySource(debugElement, page, forceSourceLookup);
+		activeSourceDisplay.displaySource(activeDebugTarget, page, forceSourceLookup);
 	}
 
 	public void handleDebugEvents(DebugEvent[] events) {
@@ -77,4 +87,41 @@ public class SCTSourceDisplayDispatcher implements ISourceDisplay, IDebugEventSe
 			}
 		}
 	}
+
+	@Override
+	public void partOpened(IWorkbenchPart part) {
+		highlightState(part);
+	}
+
+	@Override
+	public void partActivated(IWorkbenchPart part) {
+		highlightState(part);
+	}
+
+	protected void highlightState(IWorkbenchPart part) {
+		if (part instanceof DiagramEditor) {
+			IEditorInput editorInput = ((DiagramEditor) part).getEditorInput();
+			if (editorInput instanceof DiagramEditorInput) {
+				if (activeSourceDisplay != null && activeDebugTarget != null) {
+					activeSourceDisplay.displaySource((IEditorPart) part);
+				}
+			}
+		}
+	}
+
+	@Override
+	public void partClosed(IWorkbenchPart part) {
+		// Nothing to do
+	}
+
+	@Override
+	public void partBroughtToTop(IWorkbenchPart part) {
+		// Nothing to do
+	}
+
+	@Override
+	public void partDeactivated(IWorkbenchPart part) {
+		//Nothing to do
+	}
+
 }