]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
4fe96910bc2e6d4223d34c5ed3f6d255079bbd38
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.handlers.simulationPlayback;\r
13 \r
14 import org.eclipse.core.commands.AbstractHandler;\r
15 import org.eclipse.ui.PlatformUI;\r
16 import org.eclipse.ui.commands.ICommandService;\r
17 import org.simantics.simulation.experiment.IExperiment;\r
18 import org.simantics.simulation.project.IExperimentManager;\r
19 import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;\r
20 import org.simantics.ui.SimanticsUI;\r
21 \r
22 abstract class SpeedHandler extends AbstractHandler {\r
23     \r
24     protected void setPlaybackSpeed(long duration) {\r
25         \r
26         \r
27         IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
28         IExperiment experiment = manager.getActiveExperiment();\r
29         if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment)) \r
30             return;\r
31         final SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment;\r
32         \r
33         if(spe.getPlaybackDuration() == duration)\r
34             return;\r
35         \r
36         \r
37         spe.setPlaybackDuration(duration);\r
38         \r
39         PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
40 \r
41             @Override\r
42             public void run() {\r
43                 ICommandService commandService =\r
44                     (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);\r
45                 commandService.refreshElements(PlaybackExperimentHandler.COMMAND, null);\r
46             }\r
47         });\r
48     }\r
49 \r
50 }\r