X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2Fgraph%2Flayer%2FGraphLayerUtil.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2Fgraph%2Flayer%2FGraphLayerUtil.java;h=198452ed1a2fe7886e480f6facbaa584092bcbcd;hp=e3cf13527469ff7092f128d95f184dca5bd02122;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java index e3cf13527..198452ed1 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java @@ -1,74 +1,74 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.synchronization.graph.layer; - -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; -import org.simantics.db.exception.ServiceException; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.layer0.Layer0; - -/** - * Utilities for manipulating diagram layers in the graph. - * - * @author Tuukka Lehtonen - */ -public final class GraphLayerUtil { - - WriteGraph graph; - Layer0 l0; - DiagramResource dia; - - public GraphLayerUtil(WriteGraph graph) { - this.graph = graph; - this.l0 = Layer0.getInstance(graph); - this.dia = DiagramResource.getInstance(graph); - } - - public GraphLayer createLayer(String layerName, boolean active) throws DatabaseException { - Resource layer = graph.newResource(); - graph.claim(layer, l0.InstanceOf, null, dia.Layer); - - // Assign tagging relations - Resource visibleTag = newTag(dia.IsVisible); - Resource focusableTag = newTag(dia.IsFocusable); - graph.claim(layer, dia.HasVisibleTag, visibleTag); - graph.claim(layer, dia.HasFocusableTag, focusableTag); - - // Assign shared name property for all, the layer and the tags - Resource name = graph.newResource(); - graph.claim(name, l0.InstanceOf, null, l0.String); - graph.claimValue(name, layerName); - - graph.claim(layer, l0.HasName, name); - graph.claim(visibleTag, l0.HasName, name); - graph.claim(focusableTag, l0.HasName, name); - - setLayerActive(layer, active); - - return new GraphLayer(layerName, layer, visibleTag, focusableTag); - } - - public Resource newTag(Resource baseTag) throws DatabaseException { - Resource tag = graph.newResource(); - graph.claim(tag, l0.SubrelationOf, baseTag); - graph.claim(tag, l0.InverseOf, tag); - return tag; - } - - public void setLayerActive(Resource layer, boolean active) throws ManyObjectsForFunctionalRelationException, ServiceException { - graph.claimLiteral(layer, dia.IsActive, Boolean.valueOf(active)); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.synchronization.graph.layer; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.layer0.Layer0; + +/** + * Utilities for manipulating diagram layers in the graph. + * + * @author Tuukka Lehtonen + */ +public final class GraphLayerUtil { + + WriteGraph graph; + Layer0 l0; + DiagramResource dia; + + public GraphLayerUtil(WriteGraph graph) { + this.graph = graph; + this.l0 = Layer0.getInstance(graph); + this.dia = DiagramResource.getInstance(graph); + } + + public GraphLayer createLayer(String layerName, boolean active) throws DatabaseException { + Resource layer = graph.newResource(); + graph.claim(layer, l0.InstanceOf, null, dia.Layer); + + // Assign tagging relations + Resource visibleTag = newTag(dia.IsVisible); + Resource focusableTag = newTag(dia.IsFocusable); + graph.claim(layer, dia.HasVisibleTag, visibleTag); + graph.claim(layer, dia.HasFocusableTag, focusableTag); + + // Assign shared name property for all, the layer and the tags + Resource name = graph.newResource(); + graph.claim(name, l0.InstanceOf, null, l0.String); + graph.claimValue(name, layerName); + + graph.claim(layer, l0.HasName, name); + graph.claim(visibleTag, l0.HasName, name); + graph.claim(focusableTag, l0.HasName, name); + + setLayerActive(layer, active); + + return new GraphLayer(layerName, layer, visibleTag, focusableTag); + } + + public Resource newTag(Resource baseTag) throws DatabaseException { + Resource tag = graph.newResource(); + graph.claim(tag, l0.SubrelationOf, baseTag); + graph.claim(tag, l0.InverseOf, tag); + return tag; + } + + public void setLayerActive(Resource layer, boolean active) throws ManyObjectsForFunctionalRelationException, ServiceException { + graph.claimLiteral(layer, dia.IsActive, Boolean.valueOf(active)); + } + +}