]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayer.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / layer / GraphLayer.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.synchronization.graph.layer;
13
14 import java.util.Collection;
15 import java.util.Map;
16
17 import org.simantics.db.Resource;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.function.DbConsumer;
20 import org.simantics.g2d.layers.ILayer;
21 import org.simantics.g2d.layers.SimpleLayer;
22
23 /**
24  * @author Tuukka Lehtonen
25  */
26 public class GraphLayer {
27
28     public static final String PROP_VISIBLE = "PROP_VISIBLE";
29     public static final String PROP_FOCUSABLE = "PROP_FOCUSABLE";
30
31     private final String   name;
32
33     private final Resource layer;
34     
35     private final Map<String, Resource> tags;
36
37     public GraphLayer(String name, Resource layer, Map<String, Resource> tags) {
38         this.name = name;
39         this.layer = layer;
40         this.tags = tags;
41     }
42
43     public GraphLayer withName(String name) {
44         return new GraphLayer(name, layer, tags);
45     }
46
47     public String getName() {
48         return name;
49     }
50
51     public Resource getLayer() {
52         return layer;
53     }
54
55     public Resource getVisible() {
56         return tags.get(PROP_VISIBLE);
57     }
58
59     public Resource getFocusable() {
60         return tags.get(PROP_FOCUSABLE);
61     }
62
63     public ILayer getILayer() {
64         return new SimpleLayer(name);
65     }
66
67     public Collection<Resource> getTags() {
68         return tags.values();
69     }
70
71     public void forEachTag(DbConsumer<Resource> consumer) throws DatabaseException {
72         for (Resource r : tags.values())
73             consumer.accept(r);
74     }
75
76 }