|
|
@@ -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
|
|
|
+ }
|
|
|
+
|
|
|
}
|