+
+ public static final String claimFreshElementName(WriteGraph graph, Resource diagram, Resource element) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ DiagramResource DIA = DiagramResource.getInstance(graph);
+ // Get name prefix from diagram
+ String namePrefix = graph.getPossibleRelatedValue2(diagram, Layer0X.getInstance(graph).HasGeneratedNamePrefix);
+ if (namePrefix == null)
+ namePrefix = "";
+ // Give running name to element and increment the counter attached to the diagram.
+ Long l = graph.getPossibleRelatedValue(diagram, DIA.HasModCount, Bindings.LONG);
+ if (l == null)
+ l = Long.valueOf(0L);
+ String name = namePrefix + l.toString();
+ graph.claimLiteral(element, L0.HasName, name, Bindings.STRING);
+ graph.claimLiteral(diagram, DIA.HasModCount, ++l, Bindings.LONG);
+ return name;
+ }
+
+ public static Resource getDiagramElement(ReadGraph graph, Resource component) throws DatabaseException {
+ if (component == null)
+ return null;
+ DiagramResource DIA = DiagramResource.getInstance(graph);
+ if (graph.isInstanceOf(component, DIA.Element))
+ return component;
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ Resource element = graph.getPossibleObject(component, MOD.ComponentToElement);
+ return element != null && graph.isInstanceOf(element, DIA.Element) ? element : null;
+ }
+
+ public static Resource getMappedElement(ReadGraph graph, Resource element) throws DatabaseException {
+ if (element == null)
+ return null;
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ return graph.getPossibleObject(element, DN.MappedComponent);
+ }
+
+ public static Resource getMappedComponent(ReadGraph graph, Resource element) throws DatabaseException {
+ if (element == null)
+ return null;
+ Resource mappedElement = getMappedElement(graph, element);
+ if (mappedElement == null)
+ return null;
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ return graph.getPossibleObject(mappedElement, MOD.ElementToComponent);
+ }
+
+ public static Resource getMappedDNElement(ReadGraph graph, Resource element) throws DatabaseException {
+ if (element == null)
+ return null;
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ return graph.getPossibleObject(element, DN.MappedFromElement);
+ }
+
+ public static Variable toMappedConfigurationModule(ReadGraph graph, Resource input) throws DatabaseException {
+ if (input == null)
+ return null;
+
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ if (graph.isInstanceOf(input, DN.Element)) {
+ Resource mappedElement = getMappedElement(graph, input);
+ if (mappedElement == null)
+ return null;
+
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ Resource mappedComponent = graph.getPossibleObject(mappedElement, MOD.ElementToComponent);
+ if (mappedComponent == null)
+ return null;
+
+ return graph.syncRequest(new PossibleVariable(mappedComponent));
+ }
+ return null;
+ }
+
+ public static void toggleDrawMap(WriteGraph graph, Resource diagram) throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException {
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ Boolean current = graph.getPossibleRelatedValue(diagram, DN.Diagram_drawMapEnabled, Bindings.BOOLEAN);
+ if (current == null)
+ current = true;
+ graph.claimLiteral(diagram, DN.Diagram_drawMapEnabled, !current, Bindings.BOOLEAN);
+ }
+
+ public static Boolean drawMapEnabled(ReadGraph graph, Resource diagram) throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException {
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ Boolean current = graph.getPossibleRelatedValue(diagram, DN.Diagram_drawMapEnabled, Bindings.BOOLEAN);
+ return current != null ? current : true;
+ }
+
+ public static void changeMapBackgroundColor(WriteGraph graph, Resource diagram, Integer integer) throws DatabaseException {
+ DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+ graph.claimLiteral(diagram, DN.Diagram_backgroundColor, integer, Bindings.getBindingUnchecked(RGB.Integer.class));
+ }
+
+ public static Boolean trackChangesEnabled(ReadGraph graph, Resource diagram) throws DatabaseException {
+ if (diagram != null && graph.hasStatement(diagram)) {
+ return Boolean.TRUE.equals(graph.getPossibleRelatedValue(diagram,
+ DistrictNetworkResource.getInstance(graph).Diagram_trackChangesEnabled));
+ } else {
+ return false;
+ }
+ }
+
+ public static RGB.Integer backgroundColor(ReadGraph graph, Resource diagram) throws DatabaseException {
+ return graph.getPossibleRelatedValue(diagram,
+ DistrictNetworkResource.getInstance(graph).Diagram_backgroundColor,
+ Bindings.getBindingUnchecked(RGB.Integer.class));
+ }