]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/Node.java
6d122930a3e2be155771d4b99d0e313cbf39d7c9
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / scenegraph / base / Node.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * 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.g3d.scenegraph.base;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import org.eclipse.core.runtime.ListenerList;
18
19
20 public abstract class Node implements INode {
21         public transient static long               IDCOUNTER              = 1;
22         protected transient ParentNode<?>          parent                 = null;
23         protected transient String                                 parentName                     = null; 
24         protected Long                             id                     = IDCOUNTER++;
25         
26
27         public Long getId() {
28                 return id;
29         }
30
31
32         public ParentNode<?> getParent() {
33                 return parent;
34         }
35
36         
37         @Override
38         public String getParentRel() {
39                 return parentName;
40         }
41         
42         public void setParent(ParentNode<?> parent, String name) {
43                 this.parent = parent;
44                 this.parentName = name;
45         }
46         
47         public ParentNode<?> getRootNode() {
48                 return parent != null ? parent.getRootNode() : null;
49         }
50         
51         public void remove() {
52                 if (parent != null) {
53                         parent.removeNode(parentName, this);
54                 }
55         }
56         
57         public void deattach() {
58                 if (parent != null) {
59                         parent.deattachNode(parentName, this);
60                 }
61         }
62         
63         public void init() {
64         }
65         
66         public void cleanup() {
67                 if (parent != null) {
68                         parent.removeNode(parentName, this);
69                 }
70         }
71         
72         @Override
73         public String toString() {
74                 return getClass().getSimpleName();
75         }
76         
77         protected ListenerList<NodeListener> listeners = new ListenerList<NodeListener>();
78         
79         @Override
80         public void addListener(NodeListener listener) {
81                 listeners.add(listener);
82         }
83         
84         @Override
85         public void removeListener(NodeListener listener) {
86                 listeners.remove(listener);
87         }
88         
89         @Override
90         public ListenerList<NodeListener> getListeners() {
91                 return listeners;
92         }
93         
94         protected void firePropertyChanged(String id) {
95                 for (NodeListener listener : listeners) {
96                         listener.propertyChanged(this, id);
97                 }
98         }
99         
100 }