Explorar el Código

changed simulation session extension point to Session Instance registration

Andreas Mülder hace 14 años
padre
commit
4bb3c0822b

+ 0 - 1
plugins/org.yakindu.sct.core.simulation/plugin.xml

@@ -2,7 +2,6 @@
 <?eclipse version="3.4"?>
 <plugin>
    <extension-point id="org.yakindu.sct.simulation.core.sgraph.executionbuilder" name="SGraphExecutionBuilder" schema="schema/org.yakindu.sct.simulation.core.sgraph.executionbuilder.exsd"/>
-   <extension-point id="org.yakindu.sct.simulation.core.sgraph.sessionlistener" name="SgraphSessionListener" schema="schema/org.yakindu.sct.simulation.core.sgraph.executionlistener.exsd"/>
 
 <extension point="org.eclipse.debug.core.launchConfigurationTypes">
     <launchConfigurationType

+ 0 - 102
plugins/org.yakindu.sct.core.simulation/schema/org.yakindu.sct.simulation.core.sgraph.executionlistener.exsd

@@ -1,102 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.yakindu.sct.simulation.core" xmlns="http://www.w3.org/2001/XMLSchema">
-<annotation>
-      <appinfo>
-         <meta.schema plugin="org.yakindu.sct.simulation.core" id="org.yakindu.sct.simulation.core.sgraph.executionlistener" name="SgraphExecutionListener"/>
-      </appinfo>
-      <documentation>
-         [Enter description of this extension point.]
-      </documentation>
-   </annotation>
-
-   <element name="extension">
-      <annotation>
-         <appinfo>
-            <meta.element />
-         </appinfo>
-      </annotation>
-      <complexType>
-         <sequence minOccurs="1" maxOccurs="unbounded">
-            <element ref="ISimulationSessionListener"/>
-         </sequence>
-         <attribute name="point" type="string" use="required">
-            <annotation>
-               <documentation>
-                  
-               </documentation>
-            </annotation>
-         </attribute>
-         <attribute name="id" type="string">
-            <annotation>
-               <documentation>
-                  
-               </documentation>
-            </annotation>
-         </attribute>
-         <attribute name="name" type="string">
-            <annotation>
-               <documentation>
-                  
-               </documentation>
-               <appinfo>
-                  <meta.attribute translatable="true"/>
-               </appinfo>
-            </annotation>
-         </attribute>
-      </complexType>
-   </element>
-
-   <element name="ISimulationSessionListener">
-      <complexType>
-         <attribute name="class" type="string">
-            <annotation>
-               <documentation>
-                  
-               </documentation>
-               <appinfo>
-                  <meta.attribute kind="java" basedOn=":org.yakindu.sct.core.simulation.builder.ISimulationSessionListener"/>
-               </appinfo>
-            </annotation>
-         </attribute>
-      </complexType>
-   </element>
-
-   <annotation>
-      <appinfo>
-         <meta.section type="since"/>
-      </appinfo>
-      <documentation>
-         [Enter the first release in which this extension point appears.]
-      </documentation>
-   </annotation>
-
-   <annotation>
-      <appinfo>
-         <meta.section type="examples"/>
-      </appinfo>
-      <documentation>
-         [Enter extension point usage example here.]
-      </documentation>
-   </annotation>
-
-   <annotation>
-      <appinfo>
-         <meta.section type="apiinfo"/>
-      </appinfo>
-      <documentation>
-         [Enter API information here.]
-      </documentation>
-   </annotation>
-
-   <annotation>
-      <appinfo>
-         <meta.section type="implementation"/>
-      </appinfo>
-      <documentation>
-         [Enter information about supplied implementation of this extension point.]
-      </documentation>
-   </annotation>
-
-
-</schema>

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

@@ -25,9 +25,12 @@ public class SGraphSimulationSessionRegistry implements IExtensionPoints {
 
 	public static final SGraphSimulationSessionRegistry INSTANCE = new SGraphSimulationSessionRegistry();
 
+	private List<ISimulationSessionListener> sessionListener;
+
 	private List<SGraphSimulationSession> sessions;
 
 	private SGraphSimulationSessionRegistry() {
+		sessionListener = new ArrayList<ISimulationSessionListener>();
 		sessions = new ArrayList<SGraphSimulationSession>();
 	}
 
@@ -41,14 +44,12 @@ public class SGraphSimulationSessionRegistry implements IExtensionPoints {
 		sessions.remove(session);
 	}
 
-	protected List<ISimulationSessionListener> getListeners() {
-		Extensions<ISimulationSessionListener> extensions = new Extensions<ISimulationSessionListener>(
-				SESSION_LISTENER);
-		return extensions.getExtensions();
+	public List<ISimulationSessionListener> getListeners() {
+		return sessionListener;
 	}
 
 	public SGraphSimulationSession getActiveSession() {
-		//TODO
+		// TODO
 		if (sessions.isEmpty())
 			return null;
 		return sessions.get(0);

+ 0 - 7
plugins/org.yakindu.sct.ui.simulation/plugin.xml

@@ -53,13 +53,6 @@
 	</extension>
 	
 <!-- Session Listener -->
- <extension
-       point="org.yakindu.sct.simulation.core.sgraph.sessionlistener">
-    <ISimulationSessionListener class="org.yakindu.sct.ui.simulation.editor.HighlightingExecutionListener" />
-    <ISimulationSessionListener
-          class="org.yakindu.sct.ui.simulation.view.DeclarationsViewUpdater">
-    </ISimulationSessionListener>
- </extension>
  <extension
        point="org.eclipse.ui.views">
     <view

+ 5 - 0
plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/SimulationActivator.java

@@ -2,6 +2,8 @@ package org.yakindu.sct.ui.simulation;
 
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
+import org.yakindu.sct.core.simulation.SGraphSimulationSessionRegistry;
+import org.yakindu.sct.ui.simulation.editor.HighlightingExecutionListener;
 
 public class SimulationActivator extends AbstractUIPlugin {
 
@@ -15,6 +17,9 @@ public class SimulationActivator extends AbstractUIPlugin {
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
 		plugin = this;
+		
+		SGraphSimulationSessionRegistry.INSTANCE.getListeners().add(
+				new HighlightingExecutionListener());
 	}
 
 	public void stop(BundleContext context) throws Exception {

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

@@ -1,8 +1,12 @@
 package org.yakindu.sct.ui.simulation.view;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
@@ -16,21 +20,30 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.ViewPart;
+import org.yakindu.sct.core.simulation.ISimulationSessionListener;
 import org.yakindu.sct.core.simulation.SGraphSimulationSession;
 import org.yakindu.sct.core.simulation.SGraphSimulationSessionRegistry;
 import org.yakindu.sct.model.sgraph.Declaration;
 import org.yakindu.sct.model.sgraph.Event;
 import org.yakindu.sct.model.sgraph.NamedElement;
+import org.yakindu.sct.model.sgraph.Transition;
 import org.yakindu.sct.model.sgraph.Variable;
+import org.yakindu.sct.model.sgraph.Vertex;
+
+import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorResolver;
 
 /**
  * 
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public class DeclarationView extends ViewPart {
+public class DeclarationView extends ViewPart implements
+		ISimulationSessionListener {
 
 	public static final String ID = "org.yakindu.sct.ui.simulation.declarationview";
 
@@ -40,6 +53,10 @@ public class DeclarationView extends ViewPart {
 
 	private List<Control> controls;
 
+	public DeclarationView() {
+		SGraphSimulationSessionRegistry.INSTANCE.getListeners().add(this);
+	}
+
 	@Override
 	public void createPartControl(Composite parent) {
 		controls = new ArrayList<Control>();
@@ -65,7 +82,13 @@ public class DeclarationView extends ViewPart {
 		GridDataFactory.fillDefaults().grab(true, true)
 				.applyTo(variableViewer.getTable());
 
-		setEventViewerInput(DeclarationsViewUpdater.getViewerInput());
+		setEventViewerInput(getViewerInput());
+	}
+
+	@Override
+	public void dispose() {
+		SGraphSimulationSessionRegistry.INSTANCE.getListeners().remove(this);
+		super.dispose();
 	}
 
 	private void createVariableColumns(TableViewer viewer) {
@@ -123,7 +146,6 @@ public class DeclarationView extends ViewPart {
 	public void setFocus() {
 		eventViewer.getTable().setFocus();
 	}
-	
 
 	public void setEventViewerInput(List<Declaration> events) {
 		eventViewer.setInput(events);
@@ -172,4 +194,89 @@ public class DeclarationView extends ViewPart {
 
 	}
 
+	public static List<Declaration> getViewerInput() {
+		List<Declaration> declarations = new ArrayList<Declaration>();
+		Resource activeEditorResource = ActiveEditorResolver
+				.getActiveEditorResource();
+		if (activeEditorResource == null)
+			return Collections.emptyList();
+		TreeIterator<EObject> allContents = activeEditorResource
+				.getAllContents();
+		while (allContents.hasNext()) {
+			EObject next = allContents.next();
+			if (next instanceof Declaration) {
+				declarations.add((Declaration) next);
+			}
+		}
+		return declarations;
+
+	}
+
+	public void simulationStateChanged(SimulationState oldState,
+			SimulationState newState) {
+		switch (newState) {
+		case STARTED:
+			updateDeclarationView();
+			break;
+		case TERMINATED:
+			clearDeclarationView();
+			break;
+		}
+	}
+
+	public void variableValueChanged(String variableName, Object value) {
+		System.out.println("VARIABLE VALUE CHANGED!!!!! " + variableName
+				+ " value is " + value);
+	}
+
+	protected DeclarationView getDeclarationView() {
+		IViewReference[] viewReferences = PlatformUI.getWorkbench()
+				.getActiveWorkbenchWindow().getActivePage().getViewReferences();
+		for (IViewReference ref : viewReferences) {
+			if (DeclarationView.ID.equals(ref.getId())) {
+				return (DeclarationView) ref.getView(true);
+
+			}
+		}
+		return null;
+	}
+
+	private void clearDeclarationView() {
+		Display.getDefault().asyncExec(new Runnable() {
+			public void run() {
+				DeclarationView eventView = getDeclarationView();
+				if (eventView != null) {
+					eventView.clearViewerInput();
+				}
+			}
+		});
+	}
+
+	private void updateDeclarationView() {
+		Display.getDefault().asyncExec(new Runnable() {
+			public void run() {
+				DeclarationView eventView = getDeclarationView();
+				if (eventView != null) {
+					eventView.setEventViewerInput(getViewerInput());
+				}
+			}
+		});
+	}
+
+	public void stateEntered(Vertex vertex) {
+		// Nothing to do
+	}
+
+	public void stateLeft(Vertex vertex) {
+		// Nothing to do
+	}
+
+	public void transitionFired(Transition transition) {
+		// Nothing to do
+	}
+
+	public void eventRaised(String eventName) {
+		// Nothing to do
+	}
+
 }

+ 0 - 96
plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/view/DeclarationsViewUpdater.java

@@ -1,96 +0,0 @@
-package org.yakindu.sct.ui.simulation.view;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IViewReference;
-import org.eclipse.ui.PlatformUI;
-import org.yakindu.sct.core.simulation.ISimulationSessionListener.SimulationSessionListenerAdapter;
-import org.yakindu.sct.model.sgraph.Declaration;
-
-import de.itemis.xtext.utils.jface.viewers.util.ActiveEditorResolver;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class DeclarationsViewUpdater extends SimulationSessionListenerAdapter {
-
-
-	public static List<Declaration> getViewerInput() {
-		List<Declaration> declarations = new ArrayList<Declaration>();
-		Resource activeEditorResource = ActiveEditorResolver
-				.getActiveEditorResource();
-		if (activeEditorResource == null)
-			return Collections.emptyList();
-		TreeIterator<EObject> allContents = activeEditorResource
-				.getAllContents();
-		while (allContents.hasNext()) {
-			EObject next = allContents.next();
-			if (next instanceof Declaration) {
-				declarations.add((Declaration) next);
-			}
-		}
-		return declarations;
-
-	}
-
-	public void simulationStateChanged(SimulationState oldState,
-			SimulationState newState) {
-		switch (newState) {
-		case STARTED:
-			updateDeclarationView();
-			break;
-		case TERMINATED:
-			clearDeclarationView();
-			break;
-		}
-	}
-
-	@Override
-	public void variableValueChanged(String variableName, Object value) {
-		System.out.println("VARIABLE VALUE CHANGED!!!!! " + variableName
-				+ " value is " + value);
-		super.variableValueChanged(variableName, value);
-	}
-
-	protected DeclarationView getDeclarationView() {
-		IViewReference[] viewReferences = PlatformUI.getWorkbench()
-				.getActiveWorkbenchWindow().getActivePage().getViewReferences();
-		for (IViewReference ref : viewReferences) {
-			if (DeclarationView.ID.equals(ref.getId())) {
-				return (DeclarationView) ref.getView(true);
-
-			}
-		}
-		return null;
-	}
-
-	private void clearDeclarationView() {
-		Display.getDefault().asyncExec(new Runnable() {
-			public void run() {
-				DeclarationView eventView = getDeclarationView();
-				if (eventView != null) {
-					eventView.clearViewerInput();
-				}
-			}
-		});
-	}
-
-	private void updateDeclarationView() {
-		Display.getDefault().asyncExec(new Runnable() {
-			public void run() {
-				DeclarationView eventView = getDeclarationView();
-				if (eventView != null) {
-					eventView.setEventViewerInput(getViewerInput());
-				}
-			}
-		});
-	}
-}