]> gerrit.simantics Code Review - simantics/platform.git/blob
897d42c9dbc9198c6f5de7299a195a058ba6494d
[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_NewSTSSuite;\r
16     public final Resource Contributions_NewSTSTest;\r
17     public final Resource Contributions_STSSuites;\r
18     public final Resource Contributions_STSTests;\r
19     public final Resource Contributions_SuiteImage;\r
20     public final Resource Contributions_TestImage;\r
21     public final Resource ModelingActionContext;\r
22     public final Resource ModelingActionContext_Actions;\r
23     public final Resource ModelingActionContext_Actions_NewSTSSuite;\r
24     public final Resource ModelingActionContext_Actions_NewSTSTest;\r
25     public final Resource ModelingActionContext_Actions_RunSTSTest;\r
26     public final Resource SCLMain;\r
27     public final Resource testImage;\r
28     public final Resource testSuiteImage;\r
29         \r
30     public static class URIs {\r
31         public static final String BrowseContext = "http://www.simantics.org/TestsUI-1.0/BrowseContext";\r
32         public static final String Contributions = "http://www.simantics.org/TestsUI-1.0/Contributions";\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 Contributions_SuiteImage = "http://www.simantics.org/TestsUI-1.0/Contributions/SuiteImage";\r
38         public static final String Contributions_TestImage = "http://www.simantics.org/TestsUI-1.0/Contributions/TestImage";\r
39         public static final String ModelingActionContext = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext";\r
40         public static final String ModelingActionContext_Actions = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions";\r
41         public static final String ModelingActionContext_Actions_NewSTSSuite = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/NewSTSSuite";\r
42         public static final String ModelingActionContext_Actions_NewSTSTest = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/NewSTSTest";\r
43         public static final String ModelingActionContext_Actions_RunSTSTest = "http://www.simantics.org/TestsUI-1.0/ModelingActionContext/Actions/RunSTSTest";\r
44         public static final String SCLMain = "http://www.simantics.org/TestsUI-1.0/SCLMain";\r
45         public static final String testImage = "http://www.simantics.org/TestsUI-1.0/testImage";\r
46         public static final String testSuiteImage = "http://www.simantics.org/TestsUI-1.0/testSuiteImage";\r
47     }\r
48     \r
49     public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
50         try {\r
51             return graph.getResource(uri);\r
52         } catch(DatabaseException e) {\r
53             System.err.println(e.getMessage());\r
54             return null;\r
55         }\r
56     }\r
57     \r
58     public TestsUIResource(ReadGraph graph) {\r
59         BrowseContext = getResourceOrNull(graph, URIs.BrowseContext);\r
60         Contributions = getResourceOrNull(graph, URIs.Contributions);\r
61         Contributions_NewSTSSuite = getResourceOrNull(graph, URIs.Contributions_NewSTSSuite);\r
62         Contributions_NewSTSTest = getResourceOrNull(graph, URIs.Contributions_NewSTSTest);\r
63         Contributions_STSSuites = getResourceOrNull(graph, URIs.Contributions_STSSuites);\r
64         Contributions_STSTests = getResourceOrNull(graph, URIs.Contributions_STSTests);\r
65         Contributions_SuiteImage = getResourceOrNull(graph, URIs.Contributions_SuiteImage);\r
66         Contributions_TestImage = getResourceOrNull(graph, URIs.Contributions_TestImage);\r
67         ModelingActionContext = getResourceOrNull(graph, URIs.ModelingActionContext);\r
68         ModelingActionContext_Actions = getResourceOrNull(graph, URIs.ModelingActionContext_Actions);\r
69         ModelingActionContext_Actions_NewSTSSuite = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_NewSTSSuite);\r
70         ModelingActionContext_Actions_NewSTSTest = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_NewSTSTest);\r
71         ModelingActionContext_Actions_RunSTSTest = getResourceOrNull(graph, URIs.ModelingActionContext_Actions_RunSTSTest);\r
72         SCLMain = getResourceOrNull(graph, URIs.SCLMain);\r
73         testImage = getResourceOrNull(graph, URIs.testImage);\r
74         testSuiteImage = getResourceOrNull(graph, URIs.testSuiteImage);\r
75     }\r
76     \r
77     public static TestsUIResource getInstance(ReadGraph graph) {\r
78         Session session = graph.getSession();\r
79         TestsUIResource ret = session.peekService(TestsUIResource.class);\r
80         if(ret == null) {\r
81             QueryControl qc = graph.getService(QueryControl.class);\r
82             ret = new TestsUIResource(qc.getIndependentGraph(graph));\r
83             session.registerService(TestsUIResource.class, ret);\r
84         }\r
85         return ret;\r
86     }\r
87     \r
88     public static TestsUIResource getInstance(RequestProcessor session) throws DatabaseException {\r
89         TestsUIResource ret = session.peekService(TestsUIResource.class);\r
90         if(ret == null) {\r
91             ret = session.syncRequest(new Read<TestsUIResource>() {\r
92                 public TestsUIResource perform(ReadGraph graph) throws DatabaseException {\r
93                     QueryControl qc = graph.getService(QueryControl.class);\r
94                     return new TestsUIResource(qc.getIndependentGraph(graph));\r
95                 }\r
96             });\r
97             session.registerService(TestsUIResource.class, ret);\r
98         }\r
99         return ret;\r
100     }\r
101     \r
102 }\r
103 \r