1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in 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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.simulation.ui.handlers.e4;
\r
14 import javax.annotation.PostConstruct;
\r
15 import javax.inject.Inject;
\r
17 import org.eclipse.e4.core.di.annotations.CanExecute;
\r
18 import org.eclipse.e4.core.di.annotations.Execute;
\r
19 import org.eclipse.e4.core.di.annotations.Optional;
\r
20 import org.eclipse.e4.ui.di.UIEventTopic;
\r
21 import org.eclipse.e4.ui.model.application.MApplication;
\r
22 import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
\r
23 import org.eclipse.e4.ui.workbench.modeling.EModelService;
\r
24 import org.simantics.Simantics;
\r
25 import org.simantics.simulation.SimulationEvents;
\r
26 import org.simantics.simulation.experiment.ExperimentUtil;
\r
27 import org.simantics.simulation.experiment.IExperiment;
\r
28 import org.simantics.simulation.project.IExperimentManager;
\r
29 import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
\r
30 import org.simantics.simulation.ui.preferences.SimulationPreferences;
\r
34 private static final String HANDLED_ITEM_ID = "org.simantics.simulation.ui.handledtoolitem.step";
\r
37 EModelService modelService;
\r
40 public void updateToolTip(MApplication application) {
\r
41 MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application);
\r
42 if (handledItem != null) {
\r
43 SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
\r
44 handledItem.setTooltip("Step " + prefs.stepDuration + "s");
\r
49 public boolean canExecute() {
\r
50 IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
\r
51 if (manager == null)
\r
53 IExperiment experiment = manager.getActiveExperiment();
\r
54 if (experiment == null)
\r
60 public void execute() {
\r
61 SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
\r
62 ExperimentUtil.step(prefs.stepDuration);
\r
67 public void updateElement(@UIEventTopic(SimulationEvents.TOPIC_STEP_DURATION) double duration, MApplication application) {
\r
68 MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application);
\r
69 if (handledItem != null) {
\r
70 handledItem.setTooltip("Step " + duration + "s");
\r