]> gerrit.simantics Code Review - simantics/platform.git/blob
4aa14a70a5bce5dfe949e64e9cad4cc8e2b4f524
[simantics/platform.git] /
1 package org.simantics.tests.modelled.ui.ontology;\r
2 \r
3 import org.simantics.db.RequestProcessor;\r
4 import org.simantics.db.Resource;\r
5 import org.simantics.db.ReadGraph;\r
6 import org.simantics.db.request.Read;\r
7 import org.simantics.db.Session;\r
8 import org.simantics.db.exception.DatabaseException;\r
9 import org.simantics.db.service.QueryControl;\r
10 \r
11 public class TestsUIResource {\r
12     \r
13     public final Resource BrowseContext;\r
14     public final Resource Contributions;\r
15     public final Resource Contributions_ModuleImage;\r
16     public final Resource Contributions_NewSTSSuite;\r
17     public final Resource Contributions_NewSTSTest;\r
18     public final Resource Contributions_STSSuites;\r
19     public final Resource Contributions_STSTests;\r
20     public final Resource ModelingActionContext;\r
21     public final Resource ModelingActionContext_Actions;\r
22     public final Resource ModelingActionContext_Actions_NewSTSSuite;\r
23     public final Resource ModelingActionContext_Actions_NewSTSTest;\r
24     public final Resource ModelingActionContext_Actions_RunSTSTest;\r
25     public final Resource SCLMain;\r
26     public final Resource testImage;\r
27     public final Resource testSuiteImage;\r
28         \r
29     public static class URIs {\r
30         public static final String BrowseContext = "http://www.simantics.org/TestsUI-1.0/BrowseContext";\r
31         public static final String Contributions = "http://www.simantics.org/TestsUI-1.0/Contributions";\r
32         public static final String Contributions_ModuleImage = "http://www.simantics.org/TestsUI-1.0/Contributions/ModuleImage";\r
33         public static final String Contributions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSSuite";\r
34         public static final String Contributions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/Contributions/NewSTSTest";\r
35         public static final String Contributions_STSSuites = "http://www.simantics.org/TestsUI-1.0/Contributions/STSSuites";\r
36         public static final String Contributions_STSTests = "http://www.simantics.org/TestsUI-1.0/Contributions/STSTests";\r
37         public static final String ModelingActionContext = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext";\r
38         public static final String ModelingActionContext_Actions = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions";\r
39         public static final String ModelingActionContext_Actions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/NewSTSSuite";\r
40         public static final String ModelingActionContext_Actions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/NewSTSTest";\r
41         public static final String ModelingActionContext_Actions_RunSTSTest = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/RunSTSTest";\r
42         public static final String SCLMain = "http://www.simantics.org/TestsUI-1.0/SCLMain";\r
43         public static final String testImage = "http://www.simantics.org/TestsUI-1.0/testImage";\r
44         public static final String testSuiteImage = "http://www.simantics.org/TestsUI-1.0/testSuiteImage";\r
45     }\r
46     \r
47     public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
48         try {\r
49             return graph.getResource(uri);\r
50         } catch(DatabaseException e) {\r
51             System.err.println(e.getMessage());\r
52             return null;\r
53         }\r
54     }\r
55     \r
56     public TestsUIResource(ReadGraph graph) {\r
57         BrowseContext = getResourceOrNull(graph, URIs.BrowseContext);\r
58         Contributions = getResourceOrNull(graph, URIs.Contributions);\r
59         Contributions_ModuleImage = getResourceOrNull(graph, URIs.Contributions_ModuleImage);\r
60         Contributions_NewSTSSuite = getResourceOrNull(graph, URIs.Contributions_NewSTSSuite);\r
61         Contributions_NewSTSTest = getResourceOrNull(graph, URIs.Contributions_NewSTSTest);\r
62         Contributions_STSSuites = getResourceOrNull(graph, URIs.Contributions_STSSuites);\r
63         Contributions_STSTests = getResourceOrNull(graph, URIs.Contributions_STSTests);\r
64         ModelingActionContext = getResourceOrNull(graph, URIs.ModelingActionContext);\r
65         ModelingActionContext_Actions = getResourceOrNull(graph, URIs.ModelingActionContext_Actions);\r
66         ModelingActionContext_Actions_NewSTSSuite = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_NewSTSSuite);\r
67         ModelingActionContext_Actions_NewSTSTest = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_NewSTSTest);\r
68         ModelingActionContext_Actions_RunSTSTest = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_RunSTSTest);\r
69         SCLMain = getResourceOrNull(graph, URIs.SCLMain);\r
70         testImage = getResourceOrNull(graph, URIs.testImage);\r
71         testSuiteImage = getResourceOrNull(graph, URIs.testSuiteImage);\r
72     }\r
73     \r
74     public static TestsUIResource getInstance(ReadGraph graph) {\r
75         Session session = graph.getSession();\r
76         TestsUIResource ret = session.peekService(TestsUIResource.class);\r
77         if(ret == null) {\r
78             QueryControl qc = graph.getService(QueryControl.class);\r
79             ret = new TestsUIResource(qc.getIndependentGraph(graph));\r
80             session.registerService(TestsUIResource.class, ret);\r
81         }\r
82         return ret;\r
83     }\r
84     \r
85     public static TestsUIResource getInstance(RequestProcessor session) throws DatabaseException {\r
86         TestsUIResource ret = session.peekService(TestsUIResource.class);\r
87         if(ret == null) {\r
88             ret = session.syncRequest(new Read<TestsUIResource>() {\r
89                 public TestsUIResource perform(ReadGraph graph) throws DatabaseException {\r
90                     QueryControl qc = graph.getService(QueryControl.class);\r
91                     return new TestsUIResource(qc.getIndependentGraph(graph));\r
92                 }\r
93             });\r
94             session.registerService(TestsUIResource.class, ret);\r
95         }\r
96         return ret;\r
97     }\r
98     \r
99 }\r
100 \r