]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
simulation toggle button in sysdyn perspective
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 23 Feb 2010 14:56:35 +0000 (14:56 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 23 Feb 2010 14:56:35 +0000 (14:56 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@14355 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/icons/control_play.png [new file with mode: 0644]
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/simulation/SimulationJob.java

diff --git a/org.simantics.sysdyn.ui/icons/control_play.png b/org.simantics.sysdyn.ui/icons/control_play.png
new file mode 100644 (file)
index 0000000..0846555
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/control_play.png differ
index 2aa1e0290989d052471eaa27c662ab1167c12240..e6a6675416d79347ce6b29f49f039dcf0b913cdf 100644 (file)
             </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
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java
new file mode 100644 (file)
index 0000000..23f4e1d
--- /dev/null
@@ -0,0 +1,34 @@
+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
index 3a80ebab55cf788e00896442147cef775049b6d3..5a3789db4599ebc6bfcee3f18f616b7975942af5 100644 (file)
@@ -11,6 +11,7 @@ import org.eclipse.ui.console.MessageConsole;
 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
@@ -28,7 +29,8 @@ public class SimulationJob extends Job {
         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
@@ -62,7 +64,7 @@ public class SimulationJob extends Job {
             MessageConsoleStream out = this.console.newMessageStream();\r
             out.println(message);\r
         }\r
-        \r
+\r
         public void clearConsole() {\r
             this.console.clearConsole();\r
         }\r