1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.simulation.ui.handlers.e4;
14 import javax.annotation.PostConstruct;
15 import javax.inject.Inject;
17 import org.eclipse.e4.core.di.annotations.CanExecute;
18 import org.eclipse.e4.core.di.annotations.Execute;
19 import org.eclipse.e4.core.di.annotations.Optional;
20 import org.eclipse.e4.ui.di.UIEventTopic;
21 import org.eclipse.e4.ui.model.application.MApplication;
22 import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
23 import org.eclipse.e4.ui.workbench.modeling.EModelService;
24 import org.simantics.Simantics;
25 import org.simantics.simulation.SimulationEvents;
26 import org.simantics.simulation.experiment.ExperimentUtil;
27 import org.simantics.simulation.experiment.IExperiment;
28 import org.simantics.simulation.project.IExperimentManager;
29 import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;
30 import org.simantics.simulation.ui.preferences.SimulationPreferences;
34 private static final String HANDLED_ITEM_ID = "org.simantics.simulation.ui.handledtoolitem.step";
37 EModelService modelService;
40 public void updateToolTip(MApplication application) {
41 MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application);
42 if (handledItem != null) {
43 SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
44 handledItem.setTooltip("Step " + prefs.stepDuration + "s");
49 public boolean canExecute() {
50 IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
53 IExperiment experiment = manager.getActiveExperiment();
54 if (experiment == null)
60 public void execute() {
61 SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();
62 ExperimentUtil.step(prefs.stepDuration);
67 public void updateElement(@UIEventTopic(SimulationEvents.TOPIC_STEP_DURATION) double duration, MApplication application) {
68 MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application);
69 if (handledItem != null) {
70 handledItem.setTooltip("Step " + duration + "s");