1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.scenegraph.base;
\r
14 import java.util.ArrayList;
\r
15 import java.util.List;
\r
18 public abstract class Node implements INode {
\r
19 public transient static long IDCOUNTER = 1;
\r
20 protected transient ParentNode<?> parent = null;
\r
21 protected transient String parentName = null;
\r
22 protected Long id = IDCOUNTER++;
\r
25 public Long getId() {
\r
30 public ParentNode<?> getParent() {
\r
36 public String getParentRel() {
\r
40 public void setParent(ParentNode<?> parent, String name) {
\r
41 this.parent = parent;
\r
42 this.parentName = name;
\r
45 public ParentNode<?> getRootNode() {
\r
46 return parent != null ? parent.getRootNode() : null;
\r
49 public void remove() {
\r
50 if (parent != null) {
\r
51 parent.removeNode(parentName, this);
\r
55 public void deattach() {
\r
56 if (parent != null) {
\r
57 parent.deattachNode(parentName, this);
\r
61 public void init() {
\r
64 public void cleanup() {
\r
65 if (parent != null) {
\r
66 parent.removeNode(parentName, this);
\r
71 public String toString() {
\r
72 return getClass().getSimpleName();
\r
75 protected List<NodeListener> listeners = new ArrayList<NodeListener>();
\r
78 public void addListener(NodeListener listener) {
\r
79 if (!listeners.contains(listener))
\r
80 listeners.add(listener);
\r
84 public void removeListener(NodeListener listener) {
\r
85 listeners.remove(listener);
\r
89 public List<NodeListener> getListeners() {
\r
93 protected void firePropertyChanged(String id) {
\r
94 for (NodeListener listener : listeners) {
\r
95 listener.propertyChanged(this, id);
\r