--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.simulation.ui.handlers.e4;\r
+\r
+import javax.annotation.PostConstruct;\r
+import javax.inject.Inject;\r
+\r
+import org.eclipse.e4.core.di.annotations.CanExecute;\r
+import org.eclipse.e4.core.di.annotations.Execute;\r
+import org.eclipse.e4.core.di.annotations.Optional;\r
+import org.eclipse.e4.ui.di.UIEventTopic;\r
+import org.eclipse.e4.ui.model.application.MApplication;\r
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;\r
+import org.eclipse.e4.ui.workbench.modeling.EModelService;\r
+import org.simantics.Simantics;\r
+import org.simantics.simulation.SimulationEvents;\r
+import org.simantics.simulation.experiment.ExperimentUtil;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil;\r
+import org.simantics.simulation.ui.preferences.SimulationPreferences;\r
+\r
+public class Step {\r
+\r
+ private static final String HANDLED_ITEM_ID = "org.simantics.simulation.ui.handledtoolitem.step";\r
+\r
+ @Inject\r
+ EModelService modelService;\r
+ \r
+ @PostConstruct\r
+ public void updateToolTip(MApplication application) {\r
+ MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application);\r
+ if (handledItem != null) {\r
+ SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();\r
+ handledItem.setTooltip("Step " + prefs.stepDuration + "s");\r
+ }\r
+ }\r
+ \r
+ @CanExecute\r
+ public boolean canExecute() {\r
+ IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ if (manager == null)\r
+ return false;\r
+ IExperiment experiment = manager.getActiveExperiment();\r
+ if (experiment == null)\r
+ return false;\r
+ return true;\r
+ }\r
+ \r
+ @Execute\r
+ public void execute() {\r
+ SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs();\r
+ ExperimentUtil.step(prefs.stepDuration);\r
+ }\r
+\r
+ @Inject\r
+ @Optional\r
+ public void updateElement(@UIEventTopic(SimulationEvents.TOPIC_STEP_DURATION) double duration, MApplication application) {\r
+ MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application);\r
+ if (handledItem != null) {\r
+ handledItem.setTooltip("Step " + duration + "s");\r
+ }\r
+ }\r
+\r
+}\r