--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * 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.document.server;\r
+\r
+import org.simantics.document.server.serverResponse.DelayedResponse;\r
+import org.simantics.simulation.experiment.ExperimentState;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.experiment.IExperimentListener;\r
+\r
+/**\r
+ * Listener for listening experiment stopped events. Listener removes itself \r
+ * when experiment has first been run and then stopped and notifies response.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class ExperimentStoppedListener implements IExperimentListener {\r
+\r
+ private boolean hasRun = false;\r
+ private DelayedResponse response;\r
+ private IExperiment experiment;\r
+\r
+ public ExperimentStoppedListener(IExperiment experiment, DelayedResponse response) {\r
+ this.experiment = experiment;\r
+ this.response = response;\r
+ }\r
+\r
+ @Override\r
+ public void stateChanged(ExperimentState state) {\r
+ if(state.equals(ExperimentState.RUNNING))\r
+ hasRun = true;\r
+\r
+ if(state.equals(ExperimentState.STOPPED) && hasRun) {\r
+ response.setHasRun();\r
+ experiment.removeListener(this);\r
+ synchronized(response) {\r
+ response.notify();\r
+ }\r
+ }\r
+ }\r
+}\r