]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added Activate Experiment under Sysdyn experiment context menu (refs #4748).
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 13 Mar 2014 10:46:49 +0000 (10:46 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 13 Mar 2014 10:46:49 +0000 (10:46 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29116 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java

index 04104b1c178f01ca037f89d72199de8a1bb372d5..419671490ea53d2f4aa2ceb4c72f50314dec8ee7 100644 (file)
                label="Find"\r
                style="push">\r
          </command>\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.activateExperiment"\r
+               icon="platform:/plugin/com.famfamfam.silk/icons/control_play_blue.png"\r
+               id="org.simantics.sysdyn.ui.browser.activateExperiment"\r
+               label="Activate Experiment"\r
+               style="push">\r
+            <visibleWhen\r
+                  checkEnabled="true">\r
+               <with\r
+                     variable="selection">\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </with>\r
+            </visibleWhen>\r
+         </command>\r
       </menuContribution>\r
       <menuContribution\r
             locationURI="popup:#SysdynDiagramPopup?after=wbStart">\r
             class="org.simantics.sysdyn.ui.handlers.DiagramToolHandler"\r
             commandId="org.simantics.sysdyn.ui.diagramTool">\r
       </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.SysdynExperimentActivator"\r
+            commandId="org.simantics.sysdyn.ui.activateExperiment">\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <or>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </or>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.importWizards">\r
index 7d6906019c6bf96ea8b3fcd2cef10fcdc07898ca..4b13c46c582ad79d63773cec51ecec6afbd20d86 100644 (file)
@@ -13,11 +13,16 @@ package org.simantics.sysdyn.ui.handlers;
 \r
 import java.util.concurrent.Semaphore;\r
 \r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
 import org.eclipse.core.runtime.IProgressMonitor;\r
 import org.eclipse.core.runtime.IStatus;\r
 import org.eclipse.core.runtime.Status;\r
 import org.eclipse.core.runtime.SubMonitor;\r
 import org.eclipse.core.runtime.jobs.Job;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.RequestProcessor;\r
 import org.simantics.db.Resource;\r
@@ -33,12 +38,14 @@ import org.simantics.simulation.model.ExperimentLoadingFailed;
 import org.simantics.simulation.project.IExperimentActivationListener;\r
 import org.simantics.simulation.project.IExperimentManager;\r
 import org.simantics.sysdyn.ui.listeners.SysdynExperimentManagerListener;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 import org.simantics.utils.DataContainer;\r
 import org.simantics.utils.ui.ErrorLogger;\r
 import org.simantics.utils.ui.ExceptionUtils;\r
 import org.simantics.utils.ui.dialogs.ShowMessage;\r
 \r
-public class SysdynExperimentActivator {\r
+public class SysdynExperimentActivator extends AbstractHandler {\r
     /**\r
      * @param project\r
      * @param experimentManager\r
@@ -163,4 +170,25 @@ public class SysdynExperimentActivator {
         }\r
     }\r
 \r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+               ISelection selection = HandlerUtil.getCurrentSelection(event);\r
+        final Resource experiment = ResourceAdaptionUtils.toSingleResource(selection);\r
+        if (experiment == null)\r
+            return null;\r
+\r
+        final IProject project = SimanticsUI.getProject();\r
+        if (project == null)\r
+            return null;\r
+        \r
+        final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        if (experimentManager == null) {\r
+            ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception());\r
+            return null;\r
+        }\r
+        \r
+        SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, experiment);\r
+               return null;\r
+       }\r
+\r
 }\r