Przeglądaj źródła

Check for errors before launching simulation

Andreas Mülder 14 lat temu
rodzic
commit
44ec0b06e9

+ 8 - 5
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/ISGraphSimulationSession.java

@@ -26,9 +26,12 @@ import org.yakindu.sct.simulation.core.ISimulationSessionListener.SimulationStat
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public class ISGraphSimulationSession implements Runnable,
+public class SGraphSimulationSession implements Runnable,
 		ISGraphExecutionListener {
 
+	// TODO: Add to launch tab config
+	private static final int CYCLE_SLEEP_TIME = 100;
+
 	private List<ISimulationSessionListener> listeners;
 
 	private BlockingQueue<Runnable> taskQueue;
@@ -39,7 +42,7 @@ public class ISGraphSimulationSession implements Runnable,
 
 	private Timer timer;
 
-	public ISGraphSimulationSession(ISGraphExecutionFacade facade) {
+	public SGraphSimulationSession(ISGraphExecutionFacade facade) {
 		this.facade = facade;
 		facade.addExecutionListener(this);
 		listeners = new ArrayList<ISimulationSessionListener>();
@@ -51,7 +54,7 @@ public class ISGraphSimulationSession implements Runnable,
 		taskQueue.add(new Runnable() {
 			public void run() {
 				SGraphSimulationSessionRegistry.INSTANCE
-						.registerSimulationSession(ISGraphSimulationSession.this);
+						.registerSimulationSession(SGraphSimulationSession.this);
 				changeSimulationState(SimulationState.STARTED);
 				facade.enter();
 				changeSimulationState(SimulationState.RUNNING);
@@ -90,7 +93,7 @@ public class ISGraphSimulationSession implements Runnable,
 			public void run() {
 				changeSimulationState(SimulationState.TERMINATED);
 				SGraphSimulationSessionRegistry.INSTANCE
-						.unregisterSimulationSession(ISGraphSimulationSession.this);
+						.unregisterSimulationSession(SGraphSimulationSession.this);
 			}
 		});
 	}
@@ -118,7 +121,7 @@ public class ISGraphSimulationSession implements Runnable,
 					});
 					scheduleCycle();
 				}
-			}, 100);
+			}, CYCLE_SLEEP_TIME);
 
 		}
 	}

+ 5 - 5
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/SGraphSimulationSessionRegistry.java

@@ -24,19 +24,19 @@ public class SGraphSimulationSessionRegistry {
 
 	private List<ISimulationSessionListener> sessionListener;
 
-	private List<ISGraphSimulationSession> sessions;
+	private List<SGraphSimulationSession> sessions;
 
 	private SGraphSimulationSessionRegistry() {
 		sessionListener = new ArrayList<ISimulationSessionListener>();
-		sessions = new ArrayList<ISGraphSimulationSession>();
+		sessions = new ArrayList<SGraphSimulationSession>();
 	}
 
-	public void registerSimulationSession(ISGraphSimulationSession session) {
+	public void registerSimulationSession(SGraphSimulationSession session) {
 		session.getListeners().addAll(getListeners());
 		sessions.add(session);
 	}
 
-	public void unregisterSimulationSession(ISGraphSimulationSession session) {
+	public void unregisterSimulationSession(SGraphSimulationSession session) {
 		session.getListeners().clear();
 		sessions.remove(session);
 	}
@@ -45,7 +45,7 @@ public class SGraphSimulationSessionRegistry {
 		return sessionListener;
 	}
 
-	public ISGraphSimulationSession getActiveSession() {
+	public SGraphSimulationSession getActiveSession() {
 		// TODO
 		if (sessions.isEmpty())
 			return null;

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

@@ -10,7 +10,7 @@ import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.core.model.IStackFrame;
 import org.eclipse.debug.core.model.IThread;
 import org.yakindu.sct.simulation.core.ISGraphExecutionFacade;
-import org.yakindu.sct.simulation.core.ISGraphSimulationSession;
+import org.yakindu.sct.simulation.core.SGraphSimulationSession;
 
 /**
  * 
@@ -23,12 +23,12 @@ public class SCTDebugThread extends PlatformObject implements IThread {
 	private boolean terminated = false;
 	private boolean suspended = false;
 	private Thread thread;
-	private ISGraphSimulationSession session;
+	private SGraphSimulationSession session;
 	private final SCTDebugTarget target;
 
 	public SCTDebugThread(SCTDebugTarget target, ISGraphExecutionFacade facade) {
 		this.target = target;
-		session = new ISGraphSimulationSession(facade);
+		session = new SGraphSimulationSession(facade);
 		thread = new Thread(session);
 		thread.start();
 		session.start();

+ 28 - 2
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/launch/StatechartLaunchConfigurationDelegate.java

@@ -13,8 +13,14 @@ package org.yakindu.sct.simulation.core.launch;
 import java.io.IOException;
 import java.util.Collections;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunch;
@@ -47,16 +53,36 @@ public class StatechartLaunchConfigurationDelegate implements
 		ILaunchConfigurationDelegate, IExtensionPoints {
 
 	private static final int STATUS_CODE = 200;
+	// TODO: Introduce valdiation plugin
+	public static final String SGRAPH_ERROR_TYPE = "org.yakindu.sct.ui.editor.diagnostic";
+	public static final String STEXT_ERROR_TYPE = "org.yakindu.sct.ui.editor.xtext.diagnostic";
 
 	public void launch(ILaunchConfiguration configuration, String mode,
 			ILaunch launch, IProgressMonitor monitor) throws CoreException {
 		String filename = configuration.getAttribute(
 				IStatechartLaunchParameters.FILE_NAME, "");
+		//check for errors
+		IFile file = ResourcesPlugin.getWorkspace().getRoot()
+				.getFile(new Path(filename));
+		IMarker[] sgraphMarkers = file.findMarkers(SGRAPH_ERROR_TYPE, true,
+				IResource.DEPTH_INFINITE);
+		IMarker[] stextMarkers = file.findMarkers(STEXT_ERROR_TYPE, true,
+				IResource.DEPTH_INFINITE);
+
+		if (sgraphMarkers.length > 0 || stextMarkers.length > 0) {
+			Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, STATUS_CODE,
+					"Simulation could not be started because the selected resource contains errors.",null);
+			IStatusHandler statusHandler = DebugPlugin.getDefault()
+					.getStatusHandler(status);
+			statusHandler.handleStatus(status, this);
+			return;
+		}
+
 		Resource resource = loadResource(filename);
-		
+
 		Statechart statechart = (Statechart) EcoreUtil.getObjectByType(
 				resource.getContents(), SGraphPackage.Literals.STATECHART);
-		
+
 		ISGraphExecutionBuilder builder = getBuilder();
 		ISGraphExecutionFacade executionFacade = builder.build(statechart);
 		IDebugTarget target = new SCTDebugTarget(launch, executionFacade);

+ 3 - 3
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/DeclarationView.java

@@ -38,7 +38,7 @@ import org.yakindu.sct.model.sgraph.NamedElement;
 import org.yakindu.sct.model.sgraph.Transition;
 import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.simulation.core.ISGraphExecutionScope.ScopeVariable;
-import org.yakindu.sct.simulation.core.ISGraphSimulationSession;
+import org.yakindu.sct.simulation.core.SGraphSimulationSession;
 import org.yakindu.sct.simulation.core.ISimulationSessionListener;
 import org.yakindu.sct.simulation.core.SGraphSimulationSessionRegistry;
 import org.yakindu.sct.simulation.ui.view.editing.BooleanEditingSupport;
@@ -162,7 +162,7 @@ public class DeclarationView extends ViewPart implements
 	}
 
 	private void setVariableViewerInput() {
-		ISGraphSimulationSession activeSession = SGraphSimulationSessionRegistry.INSTANCE
+		SGraphSimulationSession activeSession = SGraphSimulationSessionRegistry.INSTANCE
 				.getActiveSession();
 		List<ScopeVariable> variables = activeSession.getExecutionScope()
 				.getVariables();
@@ -260,7 +260,7 @@ public class DeclarationView extends ViewPart implements
 		}
 
 		public void widgetSelected(SelectionEvent e) {
-			ISGraphSimulationSession activeSession = SGraphSimulationSessionRegistry.INSTANCE
+			SGraphSimulationSession activeSession = SGraphSimulationSessionRegistry.INSTANCE
 					.getActiveSession();
 			if (activeSession != null) {
 				activeSession.raiseEvent(eventName);