Bläddra i källkod

Removed Stackframes
Removed RefreshAdapter for viewer, added Thread that updated the
Simulation view within a fixed interval

Andreas Muelder 9 år sedan
förälder
incheckning
53d12037a0

+ 18 - 20
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTDebugTarget.java

@@ -96,36 +96,34 @@ public class SCTDebugTarget extends SCTDebugElement implements IDebugTarget, ISt
 		engine.getExecutionControl().stepForward();
 	}
 
-	public IThread[] getThreads() throws DebugException {
+	public synchronized IThread[] getThreads() throws DebugException {
 		// Collect all active regions
 		List<RegularState> activeLeafStates = engine.getExecutionContext().getActiveStates();
 		List<Region> activeRegions = new ArrayList<Region>();
 		for (RegularState vertex : activeLeafStates) {
 			activeRegions.add(vertex.getParentRegion());
 		}
-		synchronized (threads) {
-			// Remove orphaned debug threads
-			Iterator<SCTDebugThread> iterator = threads.iterator();
-			while (iterator.hasNext()) {
-				SCTDebugThread next = iterator.next();
-				if (!activeRegions.contains(next.getElement())) {
-					iterator.remove();
-				}
+		// Remove orphaned debug threads
+		Iterator<SCTDebugThread> iterator = threads.iterator();
+		while (iterator.hasNext()) {
+			SCTDebugThread next = iterator.next();
+			if (!activeRegions.contains(next.getElement())) {
+				iterator.remove();
 			}
-			// Add new debug threads
-			for (Region region : activeRegions) {
-				boolean found = false;
-				for (SCTDebugThread thread : threads) {
-					if (thread.getElement() == region) {
-						found = true;
-					}
-				}
-				if (!found) {
-					threads.add(new SCTDebugThread(this, engine, getResourceString(), region));
+		}
+		// Add new debug threads
+		for (Region region : activeRegions) {
+			boolean found = false;
+			for (SCTDebugThread thread : threads) {
+				if (thread.getElement() == region) {
+					found = true;
 				}
 			}
-			return threads.toArray(new IThread[] {});
+			if (!found) {
+				threads.add(new SCTDebugThread(this, engine, getResourceString(), region));
+			}
 		}
+		return threads.toArray(new IThread[] {});
 	}
 
 	public boolean hasThreads() throws DebugException {

+ 6 - 34
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTDebugThread.java

@@ -10,9 +10,6 @@
  */
 package org.yakindu.sct.simulation.core.debugmodel;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.model.IBreakpoint;
@@ -20,8 +17,6 @@ import org.eclipse.debug.core.model.IStackFrame;
 import org.eclipse.debug.core.model.IThread;
 import org.eclipse.emf.ecore.EObject;
 import org.yakindu.base.base.NamedElement;
-import org.yakindu.sct.model.sgraph.RegularState;
-import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
 
 /**
@@ -32,8 +27,6 @@ import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
 public class SCTDebugThread extends SCTDebugElement implements IThread {
 
 	private final NamedElement element;
-	protected List<SCTStackFrame> stateStack;
-	private Vertex lastActiveState;
 	private ISimulationEngine container;
 
 	public SCTDebugThread(SCTDebugTarget target, ISimulationEngine container, String resourceString,
@@ -42,40 +35,19 @@ public class SCTDebugThread extends SCTDebugElement implements IThread {
 		Assert.isNotNull(element);
 		this.container = container;
 		this.element = element;
-		stateStack = new ArrayList<SCTStackFrame>();
 	}
 
-	public int getPriority() throws DebugException {
-		return 0;
+	@Override
+	public IStackFrame[] getStackFrames() throws DebugException {
+		return null;
 	}
 
-	public IStackFrame[] getStackFrames() throws DebugException {
-		List<RegularState> activeLeafStates = container.getExecutionContext().getActiveStates();
-		Vertex activeState = null;
-		for (Vertex vertex : activeLeafStates) {
-			if (vertex.getParentRegion() == element) {
-				activeState = vertex;
-				break;
-			}
-		}
-		synchronized (stateStack) {
-			if (activeState != null && lastActiveState != activeState) {
-				lastActiveState = activeState;
-				EObject container = activeState;
-				stateStack = new ArrayList<SCTStackFrame>();
-				while (container != null) {
-					if (container instanceof RegularState) {
-						stateStack.add(new SCTStackFrame(this, (RegularState) container, getResourceString()));
-					}
-					container = container.eContainer();
-				}
-			}
-			return stateStack.toArray(new IStackFrame[] {});
-		}
+	public int getPriority() throws DebugException {
+		return 0;
 	}
 
 	public boolean hasStackFrames() throws DebugException {
-		return true;
+		return false;
 	}
 
 	public String getName() throws DebugException {

+ 0 - 166
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/debugmodel/SCTStackFrame.java

@@ -1,166 +0,0 @@
-/**
- * Copyright (c) 2011 committers of YAKINDU and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     committers of YAKINDU - initial API and implementation
- */
-package org.yakindu.sct.simulation.core.debugmodel;
-
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.model.IRegisterGroup;
-import org.eclipse.debug.core.model.IStackFrame;
-import org.eclipse.debug.core.model.IVariable;
-import org.eclipse.emf.ecore.EObject;
-import org.yakindu.base.base.NamedElement;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class SCTStackFrame extends SCTDebugElement implements IStackFrame {
-
-	private final SCTDebugThread thread;
-	private final NamedElement element;
-
-	public SCTStackFrame(SCTDebugThread thread, NamedElement element, String resourceString) {
-		super(thread.getDebugTarget(), resourceString);
-		this.thread = thread;
-		this.element = element;
-	}
-
-	public String getModelIdentifier() {
-		return IDebugConstants.ID_DEBUG_MODEL;
-	}
-
-	public boolean canStepInto() {
-		return thread.canStepInto();
-	}
-
-	public boolean canStepOver() {
-		return thread.canStepOver();
-	}
-
-	public boolean canStepReturn() {
-		return thread.canStepReturn();
-	}
-
-	public boolean isStepping() {
-		return thread.isStepping();
-	}
-
-	public void stepInto() throws DebugException {
-		thread.stepInto();
-	}
-
-	public void stepOver() throws DebugException {
-		thread.stepOver();
-	}
-
-	public void stepReturn() throws DebugException {
-		thread.stepReturn();
-	}
-
-	public boolean canResume() {
-		return thread.canResume();
-	}
-
-	public boolean canSuspend() {
-		return thread.canSuspend();
-	}
-
-	public boolean isSuspended() {
-		return thread.isSuspended();
-	}
-
-	public void resume() throws DebugException {
-		thread.resume();
-		fireEvent(new DebugEvent(this, DebugEvent.RESUME));
-
-	}
-
-	public void suspend() throws DebugException {
-		thread.suspend();
-		fireEvent(new DebugEvent(this, DebugEvent.SUSPEND));
-	}
-
-	public boolean canTerminate() {
-		return thread.canTerminate();
-	}
-
-	public boolean isTerminated() {
-		return thread.isTerminated();
-	}
-
-	public void terminate() throws DebugException {
-		thread.terminate();
-		fireEvent(new DebugEvent(this, DebugEvent.TERMINATE));
-	}
-
-	public SCTDebugThread getThread() {
-		return thread;
-	}
-
-	public IVariable[] getVariables() throws DebugException {
-		return new IVariable[] {};
-	}
-
-	public boolean hasVariables() throws DebugException {
-		return false;
-	}
-
-	public int getLineNumber() throws DebugException {
-		return -1;
-	}
-
-	public int getCharStart() throws DebugException {
-		return -1;
-	}
-
-	public int getCharEnd() throws DebugException {
-		return -1;
-	}
-
-	public String getName() throws DebugException {
-		return fullQfn(element);
-
-	}
-
-	public IRegisterGroup[] getRegisterGroups() throws DebugException {
-		return new IRegisterGroup[] {};
-	}
-
-	public boolean hasRegisterGroups() throws DebugException {
-		return false;
-	}
-
-	public SCTDebugTarget getDebugTarget() {
-		return (SCTDebugTarget) thread.getDebugTarget();
-	}
-
-	public ILaunch getLaunch() {
-		return thread.getLaunch();
-	}
-
-	public String getResourceString() {
-		return element.eResource().getURI().toPlatformString(true);
-	}
-
-	@SuppressWarnings("unchecked")
-	public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
-		if (adapter == EObject.class)
-			return element;
-		return super.getAdapter(adapter);
-	}
-
-	public NamedElement getElement() {
-		return element;
-	}
-
-}

+ 43 - 32
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/ExecutionContextContentProvider.java

@@ -10,8 +10,6 @@
  */
 package org.yakindu.sct.simulation.ui.view;
 
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.util.EContentAdapter;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.util.IPropertyChangeListener;
 import org.eclipse.jface.util.PropertyChangeEvent;
@@ -20,7 +18,6 @@ import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.widgets.Display;
 import org.yakindu.sct.simulation.core.sruntime.CompositeSlot;
 import org.yakindu.sct.simulation.core.sruntime.ExecutionContext;
-import org.yakindu.sct.simulation.core.sruntime.SRuntimePackage;
 import org.yakindu.sct.simulation.ui.SimulationActivator;
 import org.yakindu.sct.simulation.ui.view.actions.HideTimeEventsAction;
 
@@ -31,12 +28,49 @@ import org.yakindu.sct.simulation.ui.view.actions.HideTimeEventsAction;
  */
 public class ExecutionContextContentProvider implements ITreeContentProvider, IPropertyChangeListener {
 
+	protected class ViewerRefresher implements Runnable {
+
+		private static final int UPDATE_INTERVAL = 500;
+
+		private boolean cancel = false;
+
+		@Override
+		public void run() {
+			while (!cancel && viewer.getInput() != null) {
+				try {
+					Thread.sleep(UPDATE_INTERVAL);
+					Display.getDefault().asyncExec(new Runnable() {
+						public void run() {
+							System.out.println("running update threade");
+							if (viewer != null && !viewer.getControl().isDisposed() && shouldUpdate)
+								viewer.refresh();
+						}
+					});
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+			}
+
+		}
+
+		public boolean isCancel() {
+			return cancel;
+		}
+
+		public void setCancel(boolean cancel) {
+			this.cancel = cancel;
+		}
+
+	}
+
+	private boolean shouldUpdate = true;
+	private ViewerRefresher refresher;
 	private Viewer viewer;
-	protected RefreshAdapter refreshAdapter = new RefreshAdapter();
-	protected boolean shouldUpdate = true;
 
 	public void dispose() {
 		getStore().removePropertyChangeListener(this);
+		if (refresher != null)
+			refresher.cancel = true;
 	}
 
 	public ExecutionContextContentProvider() {
@@ -45,13 +79,11 @@ public class ExecutionContextContentProvider implements ITreeContentProvider, IP
 
 	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
 		this.viewer = viewer;
-		if (oldInput != null) {
-			ExecutionContext oldContext = (ExecutionContext) oldInput;
-			oldContext.eAdapters().remove(refreshAdapter);
-		}
+		refresher = new ViewerRefresher();
 		if (newInput != null) {
-			ExecutionContext newContext = (ExecutionContext) newInput;
-			newContext.eAdapters().add(refreshAdapter);
+			new Thread(refresher).start();
+		} else {
+			refresher.cancel = true;
 		}
 	}
 
@@ -94,8 +126,6 @@ public class ExecutionContextContentProvider implements ITreeContentProvider, IP
 				viewer.refresh();
 		}
 	}
-	
-	
 
 	public boolean isShouldUpdate() {
 		return shouldUpdate;
@@ -105,23 +135,4 @@ public class ExecutionContextContentProvider implements ITreeContentProvider, IP
 		this.shouldUpdate = shouldUpdate;
 	}
 
-
-
-	protected final class RefreshAdapter extends EContentAdapter {
-		@Override
-		public void notifyChanged(final Notification notification) {
-			if (notification.getFeature() == SRuntimePackage.Literals.EXECUTION_SLOT__VALUE
-					|| notification.getFeature() == SRuntimePackage.Literals.EXECUTION_EVENT__RAISED
-					|| notification.getFeature() == SRuntimePackage.Literals.EXECUTION_EVENT__SCHEDULED
-					|| notification.getFeature() == SRuntimePackage.Literals.COMPOSITE_SLOT__SLOTS)
-				Display.getDefault().asyncExec(new Runnable() {
-					public void run() {
-						if (viewer != null && !viewer.getControl().isDisposed() && shouldUpdate)
-							viewer.refresh();
-					}
-				});
-
-			super.notifyChanged(notification);
-		}
-	}
 }

+ 2 - 4
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/ExecutionContextViewerFactory.java

@@ -61,14 +61,12 @@ public class ExecutionContextViewerFactory {
 				.addEditorActivationListener(new ColumnViewerEditorActivationListener() {
 					@Override
 					public void afterEditorDeactivated(ColumnViewerEditorDeactivationEvent event) {
-						contentProvider.shouldUpdate = true;
+						contentProvider.setShouldUpdate(true);
 						viewer.refresh();
-
 					}
-
 					@Override
 					public void afterEditorActivated(ColumnViewerEditorActivationEvent event) {
-						contentProvider.shouldUpdate = false;
+						contentProvider.setShouldUpdate(false);
 
 					}