]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.selectionview.ui.ontology/src/org/simantics/selectionview/ui/ontology/SelectionViewUIResources.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.selectionview.ui.ontology / src / org / simantics / selectionview / ui / ontology / SelectionViewUIResources.java
1 package org.simantics.selectionview.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 SelectionViewUIResources {\r
12     \r
13     public final Resource CategoryDecorationRule;\r
14     public final Resource CategoryNode;\r
15     public final Resource CategoryNodeLabelRule;\r
16     public final Resource PropertyColumn;\r
17     public final Resource StandardProperties;\r
18     public final Resource StandardPropertiesBase;\r
19     public final Resource StandardPropertiesBase_BrowseContext;\r
20     public final Resource StandardProperties_BrowseContextStandardChildren;\r
21     public final Resource StandardProperties_BrowseContextStandardChildren_Cat;\r
22     public final Resource StandardProperties_BrowseContextStandardChildren_Sorter;\r
23     public final Resource StandardProperties_BrowseContextStandardChildren_Var;\r
24     public final Resource StandardProperties_BrowseContextWithoutChildren;\r
25     public final Resource StandardPropertySorterRule;\r
26     public final Resource StandardPropertySorterRuleType;\r
27     public final Resource UnitColumn;\r
28     public final Resource ValueColumn;\r
29     public final Resource VariableColoringDecorationRule;\r
30     public final Resource VariableDecorationRule;\r
31     public final Resource VariablePropertyCategoryRule;\r
32     public final Resource VariablePropertyLabelRule;\r
33     public final Resource VariablePropertyModifierRule;\r
34         \r
35     public static class URIs {\r
36         public static final String CategoryDecorationRule = "http://www.simantics.org/SelectionViewUI-1.1/CategoryDecorationRule";\r
37         public static final String CategoryNode = "http://www.simantics.org/SelectionViewUI-1.1/CategoryNode";\r
38         public static final String CategoryNodeLabelRule = "http://www.simantics.org/SelectionViewUI-1.1/CategoryNodeLabelRule";\r
39         public static final String PropertyColumn = "http://www.simantics.org/SelectionViewUI-1.1/PropertyColumn";\r
40         public static final String StandardProperties = "http://www.simantics.org/SelectionViewUI-1.1/StandardProperties";\r
41         public static final String StandardPropertiesBase = "http://www.simantics.org/SelectionViewUI-1.1/StandardPropertiesBase";\r
42         public static final String StandardPropertiesBase_BrowseContext = "http://www.simantics.org/SelectionViewUI-1.1/StandardPropertiesBase/BrowseContext";\r
43         public static final String StandardProperties_BrowseContextStandardChildren = "http://www.simantics.org/SelectionViewUI-1.1/StandardProperties/BrowseContextStandardChildren";\r
44         public static final String StandardProperties_BrowseContextStandardChildren_Cat = "http://www.simantics.org/SelectionViewUI-1.1/StandardProperties/BrowseContextStandardChildren/Cat";\r
45         public static final String StandardProperties_BrowseContextStandardChildren_Sorter = "http://www.simantics.org/SelectionViewUI-1.1/StandardProperties/BrowseContextStandardChildren/Sorter";\r
46         public static final String StandardProperties_BrowseContextStandardChildren_Var = "http://www.simantics.org/SelectionViewUI-1.1/StandardProperties/BrowseContextStandardChildren/Var";\r
47         public static final String StandardProperties_BrowseContextWithoutChildren = "http://www.simantics.org/SelectionViewUI-1.1/StandardProperties/BrowseContextWithoutChildren";\r
48         public static final String StandardPropertySorterRule = "http://www.simantics.org/SelectionViewUI-1.1/StandardPropertySorterRule";\r
49         public static final String StandardPropertySorterRuleType = "http://www.simantics.org/SelectionViewUI-1.1/StandardPropertySorterRuleType";\r
50         public static final String UnitColumn = "http://www.simantics.org/SelectionViewUI-1.1/UnitColumn";\r
51         public static final String ValueColumn = "http://www.simantics.org/SelectionViewUI-1.1/ValueColumn";\r
52         public static final String VariableColoringDecorationRule = "http://www.simantics.org/SelectionViewUI-1.1/VariableColoringDecorationRule";\r
53         public static final String VariableDecorationRule = "http://www.simantics.org/SelectionViewUI-1.1/VariableDecorationRule";\r
54         public static final String VariablePropertyCategoryRule = "http://www.simantics.org/SelectionViewUI-1.1/VariablePropertyCategoryRule";\r
55         public static final String VariablePropertyLabelRule = "http://www.simantics.org/SelectionViewUI-1.1/VariablePropertyLabelRule";\r
56         public static final String VariablePropertyModifierRule = "http://www.simantics.org/SelectionViewUI-1.1/VariablePropertyModifierRule";\r
57     }\r
58     \r
59     public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
60         try {\r
61             return graph.getResource(uri);\r
62         } catch(DatabaseException e) {\r
63             System.err.println(e.getMessage());\r
64             return null;\r
65         }\r
66     }\r
67     \r
68     public SelectionViewUIResources(ReadGraph graph) {\r
69         CategoryDecorationRule = getResourceOrNull(graph, URIs.CategoryDecorationRule);\r
70         CategoryNode = getResourceOrNull(graph, URIs.CategoryNode);\r
71         CategoryNodeLabelRule = getResourceOrNull(graph, URIs.CategoryNodeLabelRule);\r
72         PropertyColumn = getResourceOrNull(graph, URIs.PropertyColumn);\r
73         StandardProperties = getResourceOrNull(graph, URIs.StandardProperties);\r
74         StandardPropertiesBase = getResourceOrNull(graph, URIs.StandardPropertiesBase);\r
75         StandardPropertiesBase_BrowseContext = getResourceOrNull(graph, URIs.StandardPropertiesBase_BrowseContext);\r
76         StandardProperties_BrowseContextStandardChildren = getResourceOrNull(graph, URIs.StandardProperties_BrowseContextStandardChildren);\r
77         StandardProperties_BrowseContextStandardChildren_Cat = getResourceOrNull(graph, URIs.StandardProperties_BrowseContextStandardChildren_Cat);\r
78         StandardProperties_BrowseContextStandardChildren_Sorter = getResourceOrNull(graph, URIs.StandardProperties_BrowseContextStandardChildren_Sorter);\r
79         StandardProperties_BrowseContextStandardChildren_Var = getResourceOrNull(graph, URIs.StandardProperties_BrowseContextStandardChildren_Var);\r
80         StandardProperties_BrowseContextWithoutChildren = getResourceOrNull(graph, URIs.StandardProperties_BrowseContextWithoutChildren);\r
81         StandardPropertySorterRule = getResourceOrNull(graph, URIs.StandardPropertySorterRule);\r
82         StandardPropertySorterRuleType = getResourceOrNull(graph, URIs.StandardPropertySorterRuleType);\r
83         UnitColumn = getResourceOrNull(graph, URIs.UnitColumn);\r
84         ValueColumn = getResourceOrNull(graph, URIs.ValueColumn);\r
85         VariableColoringDecorationRule = getResourceOrNull(graph, URIs.VariableColoringDecorationRule);\r
86         VariableDecorationRule = getResourceOrNull(graph, URIs.VariableDecorationRule);\r
87         VariablePropertyCategoryRule = getResourceOrNull(graph, URIs.VariablePropertyCategoryRule);\r
88         VariablePropertyLabelRule = getResourceOrNull(graph, URIs.VariablePropertyLabelRule);\r
89         VariablePropertyModifierRule = getResourceOrNull(graph, URIs.VariablePropertyModifierRule);\r
90     }\r
91     \r
92     public static SelectionViewUIResources getInstance(ReadGraph graph) {\r
93         Session session = graph.getSession();\r
94         SelectionViewUIResources ret = session.peekService(SelectionViewUIResources.class);\r
95         if(ret == null) {\r
96             QueryControl qc = graph.getService(QueryControl.class);\r
97             ret = new SelectionViewUIResources(qc.getIndependentGraph(graph));\r
98             session.registerService(SelectionViewUIResources.class, ret);\r
99         }\r
100         return ret;\r
101     }\r
102     \r
103     public static SelectionViewUIResources getInstance(RequestProcessor session) throws DatabaseException {\r
104         SelectionViewUIResources ret = session.peekService(SelectionViewUIResources.class);\r
105         if(ret == null) {\r
106             ret = session.syncRequest(new Read<SelectionViewUIResources>() {\r
107                 public SelectionViewUIResources perform(ReadGraph graph) throws DatabaseException {\r
108                     QueryControl qc = graph.getService(QueryControl.class);\r
109                     return new SelectionViewUIResources(qc.getIndependentGraph(graph));\r
110                 }\r
111             });\r
112             session.registerService(SelectionViewUIResources.class, ret);\r
113         }\r
114         return ret;\r
115     }\r
116     \r
117 }\r
118 \r