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