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