X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.simulation.ui%2Fsrc%2Forg%2Fsimantics%2Fsimulation%2Fui%2Fhandlers%2Fe4%2FStep.java;h=7e2bc034319d45a487543102a4237b6fa2d6d328;hp=0dd71f2e54d798f0785c95bce6c5b40423d09ecf;hb=ca59190923cb45fbcde8d18d78c9c1418c1f0471;hpb=5e340942bc7de041b75c6ba281617eb0c800f30a diff --git a/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/Step.java b/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/Step.java index 0dd71f2e5..7e2bc0343 100644 --- a/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/Step.java +++ b/bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/Step.java @@ -19,32 +19,34 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.e4.ui.model.application.MApplication; +import org.eclipse.e4.ui.model.application.ui.MUILabel; import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem; import org.eclipse.e4.ui.workbench.modeling.EModelService; +import org.eclipse.osgi.util.NLS; import org.simantics.Simantics; import org.simantics.simulation.SimulationEvents; import org.simantics.simulation.experiment.ExperimentUtil; import org.simantics.simulation.experiment.IExperiment; +import org.simantics.simulation.experiment.SimulationTimeUtil; import org.simantics.simulation.project.IExperimentManager; import org.simantics.simulation.ui.preferences.SimulationPreferenceUtil; import org.simantics.simulation.ui.preferences.SimulationPreferences; public class Step { - private static final String HANDLED_ITEM_ID = "org.simantics.simulation.ui.handledtoolitem.step"; + static final String HANDLED_ITEM_ID = "org.simantics.simulation.ui.handledtoolitem.step"; @Inject EModelService modelService; - + @PostConstruct public void updateToolTip(MApplication application) { MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application); if (handledItem != null) { - SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs(); - handledItem.setTooltip("Step " + prefs.stepDuration + "s"); + updateItem(handledItem); } } - + @CanExecute public boolean canExecute() { IExperimentManager manager = Simantics.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER); @@ -55,19 +57,44 @@ public class Step { return false; return true; } - + @Execute public void execute() { SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs(); - ExperimentUtil.step(prefs.stepDuration); + switch (prefs.stepMode) { + case DURATION: + ExperimentUtil.step(prefs.stepDuration); + break; + case END_TIME: + ExperimentUtil.stepUntil(prefs.stepEndTime); + break; + } } @Inject @Optional - public void updateElement(@UIEventTopic(SimulationEvents.TOPIC_STEP_DURATION) double duration, MApplication application) { + public void updateElement(@Optional @UIEventTopic(SimulationEvents.TOPIC_STEP_CHANGE) Object changed, MApplication application) { MHandledItem handledItem = (MHandledItem) modelService.find(HANDLED_ITEM_ID, application); if (handledItem != null) { - handledItem.setTooltip("Step " + duration + "s"); + updateItem(handledItem); + } + } + + private static void updateItem(MUILabel item) { + SimulationPreferences prefs = SimulationPreferenceUtil.getPrefs(); + switch (prefs.stepMode) { + case DURATION: + item.setTooltip( + NLS.bind("Step {0} s ({1})", + SimulationTimeUtil.formatSeconds(prefs.stepDuration), + SimulationTimeUtil.formatHMSS(prefs.stepDuration))); + break; + case END_TIME: + item.setTooltip( + NLS.bind("Step Until Simulation Time Reaches {0} s ({1})", + SimulationTimeUtil.formatSeconds(prefs.stepEndTime), + SimulationTimeUtil.formatHMSS(prefs.stepEndTime))); + break; } }