浏览代码

Expand all action only expands until ReferenceSlots to avoid potential stack overflows when elements are circularly referenced.

tomqc86@googlemail.com 11 年之前
父节点
当前提交
0a34f42fcd

+ 1 - 2
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/SimulationView.java

@@ -99,8 +99,7 @@ public class SimulationView extends AbstractDebugTargetView {
 	protected void activeTargetChanged(final IDebugTarget debugTarget) {
 		ISimulationEngine engine = (ISimulationEngine) debugTarget.getAdapter(ISimulationEngine.class);
 		viewer.setInput(engine.getExecutionContext());
-		viewer.expandAll();
-
+		(new ExpandAllAction(viewer)).run();
 	}
 
 	protected void hookActions() {

+ 15 - 1
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/actions/ExpandAllAction.java

@@ -12,6 +12,9 @@ package org.yakindu.sct.simulation.ui.view.actions;
 
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.viewers.TreeViewer;
+import org.yakindu.sct.simulation.core.sruntime.ExecutionContext;
+import org.yakindu.sct.simulation.core.sruntime.ExecutionSlot;
+import org.yakindu.sct.simulation.core.sruntime.ReferenceSlot;
 import org.yakindu.sct.simulation.ui.SimulationImages;
 
 /**
@@ -32,7 +35,18 @@ public class ExpandAllAction extends Action {
 
 	public void run() {
 		if (fViewer != null) {
-			fViewer.expandAll();
+			// do not expand ReferenceSlot which may cause circular expansions resulting in stack overflows
+			if (fViewer.getInput() instanceof ExecutionContext) {
+				ExecutionContext executionContext = (ExecutionContext) fViewer.getInput();
+				for (ExecutionSlot slot : executionContext.getAllSlots()) {
+					if (!(slot instanceof ReferenceSlot)) {
+						fViewer.expandToLevel(slot, 1);
+					}
+				}
+			}
+			else {
+				fViewer.expandAll();
+			}
 		}
 	}
 }