]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayer.java
Bringing layers back to life
[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 boolean active;
36     
37     private final Map<String, Resource> tags;
38
39     public GraphLayer(String name, Resource layer, Map<String, Resource> tags, boolean active) {
40         this.name = name;
41         this.layer = layer;
42         this.tags = tags;
43         this.active = active;
44     }
45
46     public GraphLayer withName(String name) {
47         return new GraphLayer(name, layer, tags, active);
48     }
49
50     public String getName() {
51         return name;
52     }
53
54     public Resource getLayer() {
55         return layer;
56     }
57
58     public Resource getVisible() {
59         return tags.get(PROP_VISIBLE);
60     }
61
62     public Resource getFocusable() {
63         return tags.get(PROP_FOCUSABLE);
64     }
65     
66     public boolean isActive() {
67         return active;
68     }
69
70     public ILayer getILayer() {
71         return new SimpleLayer(name);
72     }
73
74     public Collection<Resource> getTags() {
75         return tags.values();
76     }
77
78     public void forEachTag(DbConsumer<Resource> consumer) throws DatabaseException {
79         for (Resource r : tags.values())
80             consumer.accept(r);
81     }
82
83     @Override
84     public int hashCode() {
85         final int prime = 31;
86         int result = 1;
87         result = prime * result + (active ? 1231 : 1237);
88         result = prime * result + ((layer == null) ? 0 : layer.hashCode());
89         result = prime * result + ((name == null) ? 0 : name.hashCode());
90         result = prime * result + ((tags == null) ? 0 : tags.hashCode());
91         return result;
92     }
93
94     @Override
95     public boolean equals(Object obj) {
96         if (this == obj)
97             return true;
98         if (obj == null)
99             return false;
100         if (getClass() != obj.getClass())
101             return false;
102         GraphLayer other = (GraphLayer) obj;
103         if (active != other.active)
104             return false;
105         if (layer == null) {
106             if (other.layer != null)
107                 return false;
108         } else if (!layer.equals(other.layer))
109             return false;
110         if (name == null) {
111             if (other.name != null)
112                 return false;
113         } else if (!name.equals(other.name))
114             return false;
115         if (tags == null) {
116             if (other.tags != null)
117                 return false;
118         } else if (!tags.equals(other.tags))
119             return false;
120         return true;
121     }
122
123 }