Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.tests.modelled.ui / src / org / simantics / tests / modelled / ui / TestsUIUtils.java
1 package org.simantics.tests.modelled.ui;
2
3 import java.io.IOException;
4
5 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
6 import org.simantics.Simantics;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.db.Resource;
9 import org.simantics.db.WriteGraph;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.request.Write;
12 import org.simantics.tests.modelled.ontology.TestsResource;
13 import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
14
15 public class TestsUIUtils {
16
17     private TestsUIUtils() {
18     }
19
20     public static void runSTSTestAction(Resource test) throws DatabaseException, IOException {
21         MPart part = E4WorkbenchUtils.getMPartById(STSTestRunnerView.ID);
22         E4WorkbenchUtils.openAndShowPart(part);
23         Object obj = part.getObject();
24         STSTestRunnerView view = (STSTestRunnerView) obj;
25         view.currentTest(test);
26         view.execute();
27     }
28     
29     public static void ignoreSTSTestAction(Resource test) throws DatabaseException {
30         Simantics.getSession().syncRequest(new Write() {
31             
32             @Override
33             public void perform(WriteGraph graph) throws DatabaseException {
34                 TestsResource TESTS = TestsResource.getInstance(graph);
35                 graph.claimLiteral(test, TESTS.ignore, true, Bindings.BOOLEAN);
36             }
37         });
38     }
39 }