From 7ea7cfb78eadcd5749b5886a0c1317fbf22a0060 Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 3 May 2013 10:13:01 +0000 Subject: [PATCH] A simple trick for saving experiment configuration values before running simulations if experiment configuration tab is open. The whole tab is wrapped in RemoveFocusBeforeExperimentComposite. HandlerUtil notices this and removes focus from the widget that has focus. This triggers saving the widget's value before simulation is run. (fixes #4242) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27305 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/handlers/DisposeExperiment.java | 2 +- .../ui/handlers/RunBasicExperiment.java | 4 +-- .../ui/handlers/SaveResultsHandler.java | 2 +- .../sysdyn/ui/handlers/ToggleSimulation.java | 2 +- .../sysdyn/ui/handlers/game/StepHandler.java | 2 +- .../RunSensitivityAnalysisExperiment.java | 2 +- .../SaveResultsHandler.java | 2 +- .../sensitivityAnalysis/ToggleSimulation.java | 5 ++-- .../PlaybackReloadHandler.java | 2 +- .../ui/properties/GameExperimentTab.java | 2 +- .../RemoveFocusBeforeExperimentComposite.java | 29 +++++++++++++++++++ .../SensitivityAnalysisExperimentTab.java | 2 +- .../sysdyn/ui/utils/HandlerUtils.java | 6 +++- 13 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/RemoveFocusBeforeExperimentComposite.java diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java index 558fd1ab..83ef73bb 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java @@ -24,7 +24,7 @@ public class DisposeExperiment extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - HandlerUtils.saveEquation(event); + HandlerUtils.saveBeforeExperimentRun(event); IProject project = SimanticsUI.getProject(); IExperimentManager manager = diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java index 2503adf7..1eba038f 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java @@ -33,8 +33,8 @@ public class RunBasicExperiment extends AbstractHandler implements IElementUpdat @Override public Object execute(ExecutionEvent event) throws ExecutionException { - HandlerUtils.saveEquation(event); - + HandlerUtils.saveBeforeExperimentRun(event); + IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); IExperiment experiment = manager.getActiveExperiment(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java index 480a1f6d..616f835c 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/SaveResultsHandler.java @@ -24,7 +24,7 @@ public class SaveResultsHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - HandlerUtils.saveEquation(event); + HandlerUtils.saveBeforeExperimentRun(event); IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java index dafb75ea..79fa0ffd 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java @@ -55,7 +55,7 @@ public class ToggleSimulation extends AbstractHandler implements IElementUpdater } } - HandlerUtils.saveEquation(event); + HandlerUtils.saveBeforeExperimentRun(event); return null; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java index 835004bf..6164c97a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/game/StepHandler.java @@ -56,7 +56,7 @@ public class StepHandler extends AbstractHandler implements IElementUpdater { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - HandlerUtils.saveEquation(event); + HandlerUtils.saveBeforeExperimentRun(event); SysdynGameExperiment game = getGameExperiment(); if(game != null) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/RunSensitivityAnalysisExperiment.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/RunSensitivityAnalysisExperiment.java index 9702a8e2..a6602763 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/RunSensitivityAnalysisExperiment.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/RunSensitivityAnalysisExperiment.java @@ -40,7 +40,7 @@ public class RunSensitivityAnalysisExperiment extends AbstractHandler implements public Object execute(ExecutionEvent event) throws ExecutionException { // Current functionality is normal run experiment - HandlerUtils.saveEquation(event); + HandlerUtils.saveBeforeExperimentRun(event); IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/SaveResultsHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/SaveResultsHandler.java index e0bc013b..dab71d2b 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/SaveResultsHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/SaveResultsHandler.java @@ -31,7 +31,7 @@ public class SaveResultsHandler extends AbstractHandler { public Object execute(ExecutionEvent event) throws ExecutionException { // Current functionality is normal run experiment - HandlerUtils.saveEquation(event); + HandlerUtils.saveBeforeExperimentRun(event); IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/ToggleSimulation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/ToggleSimulation.java index 291f936f..f90605c4 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/ToggleSimulation.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/sensitivityAnalysis/ToggleSimulation.java @@ -43,7 +43,8 @@ public class ToggleSimulation extends AbstractHandler implements IElementUpdater @Override public Object execute(ExecutionEvent event) throws ExecutionException { // Current functionality is normal run experiment - + HandlerUtils.saveBeforeExperimentRun(event); + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); Command command = service.getCommand(COMMAND); State state = command.getState(STATE); @@ -63,8 +64,6 @@ public class ToggleSimulation extends AbstractHandler implements IElementUpdater } } - HandlerUtils.saveEquation(event); - return null; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java index d22d21df..75cc05ac 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/simulationPlayback/PlaybackReloadHandler.java @@ -13,7 +13,7 @@ public class PlaybackReloadHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - HandlerUtils.saveEquation(event); + HandlerUtils.saveBeforeExperimentRun(event); IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); IExperiment experiment = manager.getActiveExperiment(); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/GameExperimentTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/GameExperimentTab.java index d4517158..e77b9f86 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/GameExperimentTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/GameExperimentTab.java @@ -36,7 +36,7 @@ public class GameExperimentTab extends LabelPropertyTabContributor { GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); GridLayoutFactory.fillDefaults().applyTo(sc); - Composite composite = new Composite(sc, SWT.NONE); + Composite composite = new RemoveFocusBeforeExperimentComposite(sc, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/RemoveFocusBeforeExperimentComposite.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/RemoveFocusBeforeExperimentComposite.java new file mode 100644 index 00000000..1966eccf --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/RemoveFocusBeforeExperimentComposite.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.properties; + +import org.eclipse.swt.widgets.Composite; +import org.simantics.sysdyn.ui.utils.HandlerUtils; + +/** + * Composite for providing info for {@link HandlerUtils}.saveBeforeExperimentRun to force focus + * of text and other widgets before simulation. Forcing focus off makes the widget to save its value. + * @author Teemu Lempinen + * + */ +public class RemoveFocusBeforeExperimentComposite extends Composite { + + public RemoveFocusBeforeExperimentComposite(Composite parent, int style) { + super(parent, style); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java index f3caa587..b334ec2e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java @@ -39,7 +39,7 @@ public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributo GridDataFactory.fillDefaults().grab(true, true).applyTo(sc); GridLayoutFactory.fillDefaults().applyTo(sc); - Composite composite = new Composite(sc, SWT.NONE); + Composite composite = new RemoveFocusBeforeExperimentComposite(sc, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).applyTo(composite); GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/HandlerUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/HandlerUtils.java index 05771fbe..cfc88559 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/HandlerUtils.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/HandlerUtils.java @@ -4,6 +4,7 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; +import org.simantics.sysdyn.ui.properties.RemoveFocusBeforeExperimentComposite; import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionComposite; /** @@ -18,7 +19,7 @@ public class HandlerUtils { * * @param event ExecutionEvent of which triggering event is used to determine who has focus. */ - public static void saveEquation(ExecutionEvent event) { + public static void saveBeforeExperimentRun(ExecutionEvent event) { if (event.getTrigger() instanceof Event) { Event trigger = (Event)event.getTrigger(); Control focusControl = trigger.display.getFocusControl(); @@ -37,6 +38,9 @@ public class HandlerUtils { ExpressionComposite expressionComposite = (ExpressionComposite)parent; expressionComposite.saveExpression(); break; + } else if(parent instanceof RemoveFocusBeforeExperimentComposite) { + focusControl.getParent().forceFocus(); + break; } parent = parent.getParent(); } -- 2.47.1