1 package org.simantics.district.network.ui.ontology;
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;
11 public class DistrictNetworkUIResource {
13 public final Resource NetworkProperties;
14 public final Resource SelectionTab;
15 public final Resource SelectionTabContribution;
17 public static class URIs {
18 public static final String NetworkProperties = "http://www.simantics.org/DistrictNetworkUI-1.0/NetworkProperties";
19 public static final String SelectionTab = "http://www.simantics.org/DistrictNetworkUI-1.0/SelectionTab";
20 public static final String SelectionTabContribution = "http://www.simantics.org/DistrictNetworkUI-1.0/SelectionTabContribution";
23 public static Resource getResourceOrNull(ReadGraph graph, String uri) {
25 return graph.getResource(uri);
26 } catch(DatabaseException e) {
27 System.err.println(e.getMessage());
32 public DistrictNetworkUIResource(ReadGraph graph) {
33 NetworkProperties = getResourceOrNull(graph, URIs.NetworkProperties);
34 SelectionTab = getResourceOrNull(graph, URIs.SelectionTab);
35 SelectionTabContribution = getResourceOrNull(graph, URIs.SelectionTabContribution);
38 public static DistrictNetworkUIResource getInstance(ReadGraph graph) {
39 Session session = graph.getSession();
40 DistrictNetworkUIResource ret = session.peekService(DistrictNetworkUIResource.class);
42 QueryControl qc = graph.getService(QueryControl.class);
43 ret = new DistrictNetworkUIResource(qc.getIndependentGraph(graph));
44 session.registerService(DistrictNetworkUIResource.class, ret);
49 public static DistrictNetworkUIResource getInstance(RequestProcessor session) throws DatabaseException {
50 DistrictNetworkUIResource ret = session.peekService(DistrictNetworkUIResource.class);
52 ret = session.syncRequest(new Read<DistrictNetworkUIResource>() {
53 public DistrictNetworkUIResource perform(ReadGraph graph) throws DatabaseException {
54 QueryControl qc = graph.getService(QueryControl.class);
55 return new DistrictNetworkUIResource(qc.getIndependentGraph(graph));
58 session.registerService(DistrictNetworkUIResource.class, ret);