diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/Animation.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/Animation.java index ad68cfe4d3f7e4b24b01553a5876f849079aeeb3..c8b4fff170e4f36f9724c0f6eb33c68309e9eac8 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/Animation.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/Animation.java @@ -14,9 +14,12 @@ import java.util.Map; import org.eclipse.swt.widgets.Display; import de.bmotionstudio.gef.editor.model.BControl; +import de.bmotionstudio.gef.editor.model.Simulation; import de.bmotionstudio.gef.editor.model.Visualization; +import de.bmotionstudio.gef.editor.model.VisualizationView; import de.prob.core.Animator; import de.prob.core.IAnimationListener; +import de.prob.core.ILifecycleListener; import de.prob.core.command.EvaluationGetValuesCommand; import de.prob.core.command.EvaluationInsertFormulaCommand; import de.prob.core.command.EvaluationInsertFormulaCommand.FormulaType; @@ -26,7 +29,7 @@ import de.prob.core.domainobjects.State; import de.prob.exceptions.ProBException; import de.prob.parserbase.ProBParseException; -public class Animation implements IAnimationListener { +public class Animation implements IAnimationListener, ILifecycleListener { private Animator animator; @@ -36,16 +39,16 @@ public class Animation implements IAnimationListener { private State currentState; - private Visualization visualization; - private Boolean observerCallBack = true; - public Animation(Animator anim, Visualization visualization) { + private Simulation simulation; + + public Animation(Animator anim, Simulation simulation) { StaticListenerRegistry.registerListener((IAnimationListener) this); + StaticListenerRegistry.registerListener((ILifecycleListener) this); this.currentStateOperations = new HashMap<String, Operation>(); this.animator = anim; - this.visualization = visualization; - this.visualization.setAnimation(this); + this.simulation = simulation; } private void setNewState(State state) { @@ -103,18 +106,31 @@ public class Animation implements IAnimationListener { } public void checkObserver() { - // if (visualization.isRunning()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { + + Display.getDefault().asyncExec(new Runnable() { + + @Override + public void run() { + + System.out.println("CHECK OBSERVER OF " + + simulation.getProjectFile().getName()); + + for (VisualizationView visView : simulation + .getVisualizationViews().values()) { + + Visualization visualization = visView.getVisualization(); List<BControl> allBControls = new ArrayList<BControl>(); allBControls.add(visualization); collectAllBControls(allBControls, visualization); for (BControl c : allBControls) c.checkObserver(Animation.this); + } - }); - // } + + } + + }); + } public State getState() { @@ -129,12 +145,9 @@ public class Animation implements IAnimationListener { return currentStateOperations.get(operation); } - public Visualization getVisualization() { - return this.visualization; - } - public void unregister() { StaticListenerRegistry.unregisterListener((IAnimationListener) this); + // StaticListenerRegistry.unregisterListener((ILifecycleListener) this); } public void setObserverCallBack(Boolean observerCallBack) { @@ -174,5 +187,14 @@ public class Animation implements IAnimationListener { public Map<String, Operation> getCurrentStateOperations() { return currentStateOperations; } + + @Override + public void reset() { + if (simulation.isRunning()) { + System.out.println("STOP SIMULATION " + + simulation.getProjectFile().getName()); + simulation.stop(); + } + } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditor.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditor.java index c4f848996118b6116ac9667e3894f2c1462f6371..eb39a2f53092e0ecafe0922a3a41bf76a20b27d0 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditor.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditor.java @@ -283,7 +283,7 @@ public class BMotionStudioEditor extends EditorPart implements if (obj instanceof Visualization) { - simulation = new Simulation(); + simulation = new Simulation("MLift.bum"); Visualization visualization = (Visualization) obj; visualization.setProjectFile(file); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioImage.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioImage.java index eabeb2389370646f2fdaf49da35fec14613e4c00..64580d4bf8c9383f127db356f04819aa34682fb4 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioImage.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioImage.java @@ -29,6 +29,8 @@ public class BMotionStudioImage { public static final String IMG_ICON_MOTION = "icon_motion"; public static final String IMG_ICON_MOTION_WIZ = "icon_motion_wiz"; + public static final String IMG_ICON_BMOTION_RUN = "icon_bmotion_run"; + public static ImageDescriptor getImageDescriptor(final String path) { return getImageDescriptor(BMotionEditorPlugin.PLUGIN_ID, path); } @@ -68,6 +70,7 @@ public class BMotionStudioImage { registerImage(IMG_LOGO_BMOTION64, "icons/logo_bmotion_64.png"); registerImage(IMG_ICON_MOTION, "icons/icon_motion.gif"); registerImage(IMG_ICON_MOTION_WIZ, "icons/icon_motion_wiz.gif"); + registerImage(IMG_ICON_BMOTION_RUN, "icons/icon_run.png"); registerBControlImages(); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioLauncher.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioLauncher.java index 91029f221ce918d41d93d4c8d41317ac4b892da6..ac3c6f4740da25689bc2b848add29e7cdf657b4f 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioLauncher.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioLauncher.java @@ -37,35 +37,10 @@ public class BMotionStudioLauncher implements IEditorLauncher { Simulation simulation = BMotionEditorPlugin.getOpenSimulations().get( file.getName()); - // final String perspectiveId = PerspectiveUtil - // .getPerspectiveIdFromFile(file); - // The simulation is already open if (simulation != null) { - PerspectiveUtil.openPerspective(simulation); initViews(simulation); -// -// IPerspectiveDescriptor perspective = PlatformUI.getWorkbench() -// .getPerspectiveRegistry() -// .findPerspectiveWithId(perspectiveId); -// -// // Check if a perspective already exists -// if (perspective != null) { -// // If yes, just switch the perspective -// PerspectiveUtil.switchPerspective(perspective); -// } else { -// -// -// } -// -// IFile perspectiveFile = file.getProject().getFile( -// getPerspectiveFileName()); -// if (perspectiveFile.exists()) { -// -// } - -// PerspectiveUtil.openPerspective(simulation); return; } @@ -97,11 +72,11 @@ public class BMotionStudioLauncher implements IEditorLauncher { if (obj instanceof Visualization) { - simulation = new Simulation(); - Visualization visualization = (Visualization) obj; visualization.setProjectFile(file); + simulation = new Simulation(visualization.getMachineName()); + String secId = UUID.randomUUID().toString(); VisualizationView visualizationView = new VisualizationView( @@ -158,8 +133,6 @@ public class BMotionStudioLauncher implements IEditorLauncher { if (viewReference != null) { visualizationViewPart = (VisualizationViewPart) viewReference .getPart(true); - System.out.println(" ===> Visualization found: " - + visualizationViewPart); } else { // If not, create a new one try { @@ -169,13 +142,10 @@ public class BMotionStudioLauncher implements IEditorLauncher { // TODO Auto-generated catch block e.printStackTrace(); } - System.out.println(" ===> Visualization created: " - + visualizationViewPart); } if (visualizationViewPart != null && !visualizationViewPart.isInitialized()) { - System.out.println(" ===> Visualization initialized"); visualizationViewPart.init(simulation, visView); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/VisualizationViewPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/VisualizationViewPart.java index 5e2c37fada187616d6dffd8cb2438dd990794666..31e08865e9e54ba9d6666e3afa307d009a57017a 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/VisualizationViewPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/VisualizationViewPart.java @@ -169,6 +169,10 @@ public class VisualizationViewPart extends ViewPart implements return visualizationView; } + public Simulation getSimulation() { + return simulation; + } + private void createActions() { ActionRegistry registry = getActionRegistry(); @@ -327,6 +331,8 @@ public class VisualizationViewPart extends ViewPart implements setInitialized(false); if (getVisualizationView() != null) getVisualizationView().removePropertyChangeListener(this); + if (getSimulation() != null) + getSimulation().removePropertyChangeListener(this); } @Override @@ -380,6 +386,7 @@ public class VisualizationViewPart extends ViewPart implements public void init(Simulation simulation, VisualizationView visualizationView) { this.simulation = simulation; + this.simulation.addPropertyChangeListener(this); this.visualizationView = visualizationView; this.visualizationView.addPropertyChangeListener(this); this.visualization = visualizationView.getVisualization(); @@ -558,8 +565,33 @@ public class VisualizationViewPart extends ViewPart implements @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("name")) - setPartName(evt.getNewValue().toString()); + + String name = visualizationView.getName(); + Boolean running = simulation.isRunning(); + + String propertyName = evt.getPropertyName(); + + if (propertyName.equals("name")) + name = evt.getNewValue().toString(); + + if (propertyName.equals("running")) + running = Boolean.valueOf(evt.getNewValue().toString()); + + if (propertyName.equals("running") + || propertyName.equals("name")) { + + if (running) { + setPartName("(Running) " + name); + setTitleImage(BMotionStudioImage + .getImage(BMotionStudioImage.IMG_ICON_BMOTION_RUN)); + } else { + setPartName(name); + setTitleImage(BMotionStudioImage + .getImage(BMotionStudioImage.IMG_LOGO_BMOTION)); + } + + } + } } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/CloseSimulationAction.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/CloseSimulationAction.java index f2e072e6ed3e3820859227d04c333525118ed35c..711a7e789a6c62d132d4acb5552d7504c206d8e4 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/CloseSimulationAction.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/CloseSimulationAction.java @@ -49,6 +49,7 @@ public class CloseSimulationAction extends Action { PerspectiveUtil.deletePerspective(perspectiveDescriptor); } + simulation.stop(); BMotionEditorPlugin.closeSimulation(simulation); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/ControlPanel.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/ControlPanel.java index a280e50464d823db48fac6823633196472843a4a..2bd488d8ae18aa04eb8d7459b71c5ca4c9b948f6 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/ControlPanel.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/ControlPanel.java @@ -86,12 +86,6 @@ public class ControlPanel extends ViewPart implements ISimulationListener, ((Simulation) parent).setDirty(true); treeViewer.update(element, null); - // IWorkbenchPage page = PlatformUI.getWorkbench() - // .getActiveWorkbenchWindow().getActivePage(); - // IViewReference viewReference = page.findViewReference( - // VisualizationViewPart.ID, visView.getViewId()); - // IViewPart view = viewReference.getView(true); - } } @@ -121,6 +115,11 @@ public class ControlPanel extends ViewPart implements ISimulationListener, column2.getColumn().setText("Dirty"); column2.getColumn().setWidth(40); + TreeViewerColumn column3 = new TreeViewerColumn(treeViewer, SWT.RIGHT); + column3.getColumn().setAlignment(SWT.LEFT); + column3.getColumn().setText("Running"); + column3.getColumn().setWidth(40); + treeViewer.setContentProvider(new ITreeContentProvider() { @Override @@ -194,6 +193,8 @@ public class ControlPanel extends ViewPart implements ISimulationListener, treeViewer); final SaveSimulationAction saveSimulationAction = new SaveSimulationAction( treeViewer); + final RunSimulationAction runSimulationAction = new RunSimulationAction( + treeViewer); final AddVisualizationViewAction addVisualizationViewAction = new AddVisualizationViewAction( treeViewer); final RemoveVisualizationViewAction deleteVisualizationViewAction = new RemoveVisualizationViewAction( @@ -212,6 +213,8 @@ public class ControlPanel extends ViewPart implements ISimulationListener, manager.add(saveSimulationAction); manager.add(separator); manager.add(addVisualizationViewAction); + manager.add(separator); + manager.add(runSimulationAction); } else if (firstElement instanceof VisualizationView) { manager.add(deleteVisualizationViewAction); } @@ -301,6 +304,15 @@ public class ControlPanel extends ViewPart implements ISimulationListener, else return ColorConstants.green; + } + case 2: + if (element instanceof Simulation) { + Simulation simulation = (Simulation) element; + if (simulation.isRunning()) + return ColorConstants.green; + else + return ColorConstants.red; + } } return null; @@ -308,7 +320,6 @@ public class ControlPanel extends ViewPart implements ISimulationListener, @Override public Image getColumnImage(Object element, int columnIndex) { - // TODO Auto-generated method stub return null; } @@ -333,7 +344,8 @@ public class ControlPanel extends ViewPart implements ISimulationListener, @Override public void propertyChange(PropertyChangeEvent evt) { - if (evt.getPropertyName().equals("dirty")) + if (evt.getPropertyName().equals("dirty") + || evt.getPropertyName().equals("running")) treeViewer.refresh(); } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/RunSimulationAction.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/RunSimulationAction.java new file mode 100644 index 0000000000000000000000000000000000000000..ceb3bdedfef4d27cc2aa7f64c9bfc503dc4d26ed --- /dev/null +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/controlpanel/RunSimulationAction.java @@ -0,0 +1,56 @@ +/** + * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, + * Heinrich Heine Universitaet Duesseldorf + * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) + * */ + +package de.bmotionstudio.gef.editor.controlpanel; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.ui.IPerspectiveDescriptor; +import org.eclipse.ui.IPerspectiveRegistry; +import org.eclipse.ui.PlatformUI; + +import de.bmotionstudio.gef.editor.BMotionStudioImage; +import de.bmotionstudio.gef.editor.model.Simulation; +import de.bmotionstudio.gef.editor.util.PerspectiveUtil; + +public class RunSimulationAction extends Action { + + private TreeViewer viewer; + + public RunSimulationAction(TreeViewer viewer) { + this.viewer = viewer; + setText("Run Simulation"); + setImageDescriptor(BMotionStudioImage + .getImageDescriptor("icons/icon_run.png")); + } + + @Override + public void run() { + + IStructuredSelection sel = (IStructuredSelection) viewer.getSelection(); + Object firstElement = sel.getFirstElement(); + if (firstElement instanceof Simulation) { + + Simulation simulation = (Simulation) firstElement; + + IPerspectiveRegistry perspectiveRegistry = PlatformUI + .getWorkbench().getPerspectiveRegistry(); + + String perspectiveId = PerspectiveUtil + .getPerspectiveIdFromFile(simulation.getProjectFile()); + IPerspectiveDescriptor perspectiveDescriptor = perspectiveRegistry + .findPerspectiveWithId(perspectiveId); + if (perspectiveDescriptor != null) + PerspectiveUtil.switchPerspective(perspectiveDescriptor); + + simulation.start(); + + } + + } + +} diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java index 057a97d7201deedbe02a4bad4bc3f3d154e09ffb..12b3905f2d07e1ca368b19d4cd88ad6ba364c14c 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/internal/VisualizationProgressBar.java @@ -155,7 +155,7 @@ public class VisualizationProgressBar extends ProgressBarDialog { } private void startProbAnimator() { - animation = new Animation(animator, visualization); + animation = new Animation(animator, null); ILanguageService langService = getGenericLoadMachine(visualization .getLanguage()); if (langService != null) { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Simulation.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Simulation.java index bb59e02e24127f876ccce29fc6f3a82d4d8209c9..c7e6056dd906b8af3d75def553c42e96df604726 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Simulation.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/model/Simulation.java @@ -6,6 +6,15 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.core.resources.IFile; +import org.eventb.core.IEventBRoot; +import org.rodinp.core.IRodinFile; +import org.rodinp.core.IRodinProject; +import org.rodinp.core.RodinCore; + +import de.bmotionstudio.gef.editor.Animation; +import de.prob.core.Animator; +import de.prob.core.command.LoadEventBModelCommand; +import de.prob.exceptions.ProBException; public class Simulation { @@ -17,8 +26,15 @@ public class Simulation { private transient boolean dirty; - public Simulation() { + private transient Animation animation; + + private transient boolean running; + + private String model; + + public Simulation(String model) { this.views = new HashMap<String, VisualizationView>(); + this.model = model; } public Map<String, VisualizationView> getVisualizationViews() { @@ -42,12 +58,22 @@ public class Simulation { return dirty; } + public boolean isRunning() { + return running; + } + public void setDirty(boolean dirty) { boolean oldVal = this.dirty; this.dirty = dirty; listeners.firePropertyChange("dirty", oldVal, dirty); } + public void setRunning(boolean running) { + boolean oldVal = this.running; + this.running = running; + listeners.firePropertyChange("running", oldVal, running); + } + public void addPropertyChangeListener(PropertyChangeListener listener) { getListeners().addPropertyChangeListener(listener); } @@ -62,4 +88,31 @@ public class Simulation { getListeners().removePropertyChangeListener(listener); } + public void start() { + + Animator animator = Animator.getAnimator(); + animation = new Animation(animator, this); + IEventBRoot modelRoot = getCorrespondingFile(getProjectFile(), model); + try { + LoadEventBModelCommand.load(animator, modelRoot); + setRunning(true); + } catch (ProBException e) { + e.printStackTrace(); + } + + } + + public void stop() { + if (animation != null) + animation.unregister(); + setRunning(false); + } + + private IEventBRoot getCorrespondingFile(IFile file, String machineFileName) { + IRodinProject rProject = RodinCore.valueOf(file.getProject()); + IRodinFile rFile = rProject.getRodinFile(machineFileName); + IEventBRoot eventbRoot = (IEventBRoot) rFile.getRoot(); + return eventbRoot; + } + } diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SimpleValueDisplay.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SimpleValueDisplay.java index 303d92f036fcb6cd29578dfd439c8c91fbdda8ff..b66c674e0f2c9a44d063f907b7e9a7cfa8c60714 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SimpleValueDisplay.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/observer/SimpleValueDisplay.java @@ -25,6 +25,9 @@ public class SimpleValueDisplay extends Observer { public void check(final Animation animation, final BControl bcontrol) { + if (eval == null) + return; + // First evaluate predicate (predicate field) String bolValue = "true"; if (predicate != null && predicate.length() > 0) {