From: miettinen Date: Thu, 13 Mar 2014 10:46:49 +0000 (+0000) Subject: Added Activate Experiment under Sysdyn experiment context menu (refs #4748). X-Git-Tag: 1.8.1~121 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=12af2a525616bc4857d8c07675d3ca232bc1d1d0;p=simantics%2Fsysdyn.git Added Activate Experiment under Sysdyn experiment context menu (refs #4748). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29116 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 04104b1c..41967149 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -1173,6 +1173,23 @@ label="Find" style="push"> + + + + + + + + @@ -2099,6 +2116,21 @@ class="org.simantics.sysdyn.ui.handlers.DiagramToolHandler" commandId="org.simantics.sysdyn.ui.diagramTool"> + + + + + + + + + + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java index 7d690601..4b13c46c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SysdynExperimentActivator.java @@ -13,11 +13,16 @@ package org.simantics.sysdyn.ui.handlers; import java.util.concurrent.Semaphore; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.handlers.HandlerUtil; import org.simantics.db.ReadGraph; import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; @@ -33,12 +38,14 @@ import org.simantics.simulation.model.ExperimentLoadingFailed; import org.simantics.simulation.project.IExperimentActivationListener; import org.simantics.simulation.project.IExperimentManager; import org.simantics.sysdyn.ui.listeners.SysdynExperimentManagerListener; +import org.simantics.ui.SimanticsUI; +import org.simantics.ui.utils.ResourceAdaptionUtils; import org.simantics.utils.DataContainer; import org.simantics.utils.ui.ErrorLogger; import org.simantics.utils.ui.ExceptionUtils; import org.simantics.utils.ui.dialogs.ShowMessage; -public class SysdynExperimentActivator { +public class SysdynExperimentActivator extends AbstractHandler { /** * @param project * @param experimentManager @@ -163,4 +170,25 @@ public class SysdynExperimentActivator { } } + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ISelection selection = HandlerUtil.getCurrentSelection(event); + final Resource experiment = ResourceAdaptionUtils.toSingleResource(selection); + if (experiment == null) + return null; + + final IProject project = SimanticsUI.getProject(); + if (project == null) + return null; + + final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); + if (experimentManager == null) { + ErrorLogger.defaultLogWarning("Experiment manager not available.", new Exception()); + return null; + } + + SysdynExperimentActivator.scheduleActivation(SimanticsUI.getSession(), project, experimentManager, experiment); + return null; + } + }