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