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