1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.diagram.synchronization.graph.layer;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.WriteGraph;
\r
16 import org.simantics.db.exception.DatabaseException;
\r
17 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
\r
18 import org.simantics.db.exception.ServiceException;
\r
19 import org.simantics.diagram.stubs.DiagramResource;
\r
20 import org.simantics.layer0.Layer0;
\r
23 * Utilities for manipulating diagram layers in the graph.
\r
25 * @author Tuukka Lehtonen
\r
27 public final class GraphLayerUtil {
\r
31 DiagramResource dia;
\r
33 public GraphLayerUtil(WriteGraph graph) {
\r
35 this.l0 = Layer0.getInstance(graph);
\r
36 this.dia = DiagramResource.getInstance(graph);
\r
39 public GraphLayer createLayer(String layerName, boolean active) throws DatabaseException {
\r
40 Resource layer = graph.newResource();
\r
41 graph.claim(layer, l0.InstanceOf, null, dia.Layer);
\r
43 // Assign tagging relations
\r
44 Resource visibleTag = newTag(dia.IsVisible);
\r
45 Resource focusableTag = newTag(dia.IsFocusable);
\r
46 graph.claim(layer, dia.HasVisibleTag, visibleTag);
\r
47 graph.claim(layer, dia.HasFocusableTag, focusableTag);
\r
49 // Assign shared name property for all, the layer and the tags
\r
50 Resource name = graph.newResource();
\r
51 graph.claim(name, l0.InstanceOf, null, l0.String);
\r
52 graph.claimValue(name, layerName);
\r
54 graph.claim(layer, l0.HasName, name);
\r
55 graph.claim(visibleTag, l0.HasName, name);
\r
56 graph.claim(focusableTag, l0.HasName, name);
\r
58 setLayerActive(layer, active);
\r
60 return new GraphLayer(layerName, layer, visibleTag, focusableTag);
\r
63 public Resource newTag(Resource baseTag) throws DatabaseException {
\r
64 Resource tag = graph.newResource();
\r
65 graph.claim(tag, l0.SubrelationOf, baseTag);
\r
66 graph.claim(tag, l0.InverseOf, tag);
\r
70 public void setLayerActive(Resource layer, boolean active) throws ManyObjectsForFunctionalRelationException, ServiceException {
\r
71 graph.claimLiteral(layer, dia.IsActive, Boolean.valueOf(active));
\r