</visibleWhen>\r
</command>\r
</menuContribution>\r
+ <menuContribution\r
+ locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">\r
+ <toolbar\r
+ id="org.simantics.sysdyn.ui.sysdynToolbar">\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.simulate"\r
+ icon="icons/control_play.png"\r
+ label="Simulate"\r
+ style="toggle"\r
+ tooltip="Toggle simulation">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ <with\r
+ variable="activeWorkbenchWindow.activePerspective">\r
+ <equals\r
+ value="org.simantics.sysdyn.ui.perspective">\r
+ </equals>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
+ </toolbar>\r
+ </menuContribution>\r
</extension>\r
<extension\r
point="org.eclipse.ui.commands">\r
id="org.simantics.sysdyn.ui.rename"\r
name="Rename">\r
</command>\r
+ <command\r
+ defaultHandler="org.simantics.sysdyn.ui.actions.ToggleSimulation"\r
+ id="org.simantics.sysdyn.ui.simulate"\r
+ name="Toggle Simulate">\r
+ <state\r
+ class="org.eclipse.jface.commands.ToggleState"\r
+ id="org.simantics.sysdyn.ui.simulate.state">\r
+ </state>\r
+ </command>\r
</extension>\r
<extension\r
point="org.eclipse.ui.handlers">\r
--- /dev/null
+package org.simantics.sysdyn.ui.actions;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.Command;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.core.commands.State;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.commands.ICommandService;\r
+\r
+public class ToggleSimulation extends AbstractHandler {\r
+ \r
+ public static final String COMMAND = "org.simantics.sysdyn.ui.simulate";\r
+ public static final String STATE = "org.simantics.sysdyn.ui.simulate.state";\r
+\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+ Command command = service.getCommand(COMMAND);\r
+ State state = command.getState(STATE);\r
+ Boolean value = (Boolean) state.getValue();\r
+ value = !value;\r
+ state.setValue(value);\r
+ return null;\r
+ }\r
+\r
+ public static Boolean getState() {\r
+ ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
+ Command command = service.getCommand(COMMAND);\r
+ State state = command.getState(STATE);\r
+ return (Boolean)state.getValue();\r
+ }\r
+\r
+}\r
import org.eclipse.ui.console.MessageConsoleStream;\r
import org.simantics.modelica.IModelicaMonitor;\r
import org.simantics.sysdyn.manager.SysdynModel;\r
+import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
\r
public class SimulationJob extends Job {\r
\r
this.monitor.clearConsole();\r
try {\r
model.update();\r
- model.simulate(this.monitor);\r
+ if(ToggleSimulation.getState())\r
+ model.simulate(this.monitor);\r
} catch (Exception e) {\r
e.printStackTrace();\r
return new Status(\r
MessageConsoleStream out = this.console.newMessageStream();\r
out.println(message);\r
}\r
- \r
+\r
public void clearConsole() {\r
this.console.clearConsole();\r
}\r