]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.simulation.ui/src/org/simantics/simulation/ui/handlers/e4/Step.java
Added Set End Time command and handler as an alternate stepping mode
[simantics/platform.git] / bundles / org.simantics.simulation.ui / src / org / simantics / simulation / ui / handlers / e4 / Step.java
index 0dd71f2e54d798f0785c95bce6c5b40423d09ecf..7e2bc034319d45a487543102a4237b6fa2d6d328 100644 (file)
@@ -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;
         }
     }