1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.handlers.simulationPlayback;
\r
14 import java.util.Map;
\r
16 import org.eclipse.core.commands.AbstractHandler;
\r
17 import org.eclipse.core.commands.ExecutionEvent;
\r
18 import org.eclipse.core.commands.ExecutionException;
\r
19 import org.eclipse.jface.resource.ImageDescriptor;
\r
20 import org.eclipse.ui.commands.IElementUpdater;
\r
21 import org.eclipse.ui.menus.UIElement;
\r
22 import org.simantics.simulation.experiment.ExperimentState;
\r
23 import org.simantics.simulation.experiment.IExperiment;
\r
24 import org.simantics.simulation.project.IExperimentManager;
\r
25 import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;
\r
26 import org.simantics.sysdyn.ui.Activator;
\r
27 import org.simantics.ui.SimanticsUI;
\r
29 public class PlaybackExperimentHandler extends AbstractHandler implements IElementUpdater {
\r
31 public static final String COMMAND = "org.simantics.sysdyn.ui.playback";
\r
34 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
35 IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
\r
36 IExperiment experiment = manager.getActiveExperiment();
\r
37 if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment))
\r
39 SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment;
\r
40 if(!spe.isPlaybackRunning())
\r
41 spe.startPlayback();
\r
47 @SuppressWarnings("rawtypes")
\r
49 public void updateElement(UIElement element, Map parameters) {
\r
50 IExperimentManager manager =
\r
51 SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
\r
52 IExperiment experiment = manager.getActiveExperiment();
\r
53 if(experiment == null || !(experiment instanceof SysdynPlaybackExperiment))
\r
55 SysdynPlaybackExperiment spe = (SysdynPlaybackExperiment)experiment;
\r
57 ExperimentState state = experiment.getState();
\r
58 if(state == ExperimentState.RUNNING && !spe.isPlaybackRunning()) {
\r
59 // RUNNING == simulation, not playback
\r
60 this.setBaseEnabled(false);
\r
62 this.setBaseEnabled(true);
\r
65 if(spe.isPlaybackRunning()) {
\r
66 element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_pause.png")));
\r
67 element.setHoverIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_pause_blue.png")));
\r
69 long duration = spe.getPlaybackDuration();
\r
70 if(duration == SysdynPlaybackExperiment.DURATION_SLOW) {
\r
71 element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_step.png")));
\r
72 element.setHoverIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_step_blue.png")));
\r
73 } else if(duration == SysdynPlaybackExperiment.DURATION_FAST) {
\r
74 element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_fastforward.png")));
\r
75 element.setHoverIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_fastforward_blue.png")));
\r
77 element.setIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_play.png")));
\r
78 element.setHoverIcon(ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/control_play_blue.png")));
\r