]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/WaitActiveExperiment.java
Merge "Query control functions into Simantics/DB"
[simantics/platform.git] / bundles / org.simantics.modeling.tests / src / org / simantics / modeling / tests / commands / WaitActiveExperiment.java
1 package org.simantics.modeling.tests.commands;
2
3 import org.simantics.Simantics;
4 import org.simantics.db.exception.DatabaseException;
5 import org.simantics.db.testing.base.CommandSequenceTest;
6 import org.simantics.db.testing.common.WriteCommand;
7 import org.simantics.project.IProject;
8 import org.simantics.simulation.experiment.IExperiment;
9 import org.simantics.simulation.project.IExperimentManager;
10 import org.simantics.simulation.project.IExperimentManagerListener;
11
12 public class WaitActiveExperiment extends WriteCommand<CommandSequenceTest> implements IExperimentManagerListener {
13
14         boolean done = false;
15         
16         @Override
17         public void run(CommandSequenceTest environment) throws DatabaseException {
18                 try {
19                         IProject project = Simantics.getProject(); 
20             final IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);
21             if (experimentManager != null) {
22                 IExperiment experiment = experimentManager.getActiveExperiment();
23                 if(experiment == null) {
24                         experimentManager.addListener(this);
25                         while(!done) {
26                                 Thread.sleep(50);
27                         }
28                         // Cannot because of bean comparison
29                         //experimentManager.removeListener(this);
30                 }
31             }
32                 } catch (Exception e) {
33                         throw new DatabaseException(e);
34                 }
35         }
36
37         @Override
38         public void activeExperimentLoaded(IExperiment experiment) {
39                 done = true;
40         }
41
42         @Override
43         public void activeExperimentUnloaded() {
44         }
45
46         @Override
47         public void managerDisposed() {
48         }
49
50 }