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);
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;
}
}