]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java
White space clean-up
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / scenegraph / base / ParentNode.java
index 63a1924dcaad8621a9f9968e478fbe05b7909c70..7da387d7fa5866ae6a5e6117000ee6b48837c044 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g3d.scenegraph.base;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.List;\r
-\r
-import org.simantics.utils.datastructures.MapList;\r
-\r
-public abstract class ParentNode<T extends INode> extends Node {\r
-\r
-       private MapList<String, T> children = new MapList<String, T>();\r
-\r
-       public synchronized void addNode(String relName, T child) {\r
-               if (child.getParent() != null)\r
-                       child.getParent().removeNode(child.getParentRel(), child);\r
-\r
-               child.setParent(this, relName);\r
-               children.add(relName, (T) child);\r
-\r
-               childrenChanged();\r
-               fireNodeAdded(child, relName);\r
-       }\r
-\r
-       /**\r
-        * Removes child node and it's hierarchy.\r
-        * @param relName\r
-        * @param child\r
-        * @return\r
-        */\r
-       @SuppressWarnings("unchecked")\r
-       public synchronized final boolean removeNode(String relName, INode child) {\r
-               if (children.remove(relName, (T) child)) {\r
-                       fireNodeRemoved(child, relName);\r
-                   child.remove();\r
-                       child.setParent(null, null);\r
-                       return true;\r
-               }\r
-               return false;\r
-       }\r
-       \r
-       /**\r
-        * Removes child node. The child nodes hierarchy is left intact.\r
-        * @param relName\r
-        * @param child\r
-        * @return\r
-        */\r
-       @SuppressWarnings("unchecked")\r
-       public synchronized final boolean deattachNode(String relName, INode child) {\r
-               if (children.remove(relName, (T) child)) {\r
-                       fireNodeRemoved(child, relName);\r
-                       child.setParent(null, null);\r
-                       return true;\r
-               }\r
-               return false;\r
-       }\r
-       \r
-       public synchronized final boolean removeNodes(String relName) {\r
-               List<T> nodes = children.getValues(relName);\r
-               for (T child : nodes) {\r
-                       if (children.remove(relName, (T) child)) {\r
-                               fireNodeRemoved(child, relName);\r
-                           child.remove();\r
-                               child.setParent(null, null);\r
-                               \r
-                       }\r
-               }\r
-               return nodes.size() > 0;\r
-       }\r
-\r
-       public synchronized final void removeNodes() {\r
-               synchronized (children) {\r
-                       boolean changed = false;\r
-                       for (String key : children.getKeys()) {\r
-                               for (T child : children.getValues(key)) {\r
-                                       if (child != null) {\r
-                                               changed = true;\r
-                                               if (child instanceof ParentNode<?>) {\r
-                                                       ((ParentNode<?>) child).removeNodes();\r
-                                               }\r
-                                               child.cleanup();\r
-                                               child.setParent(null, null);\r
-                                               // if (propertyChangeListener != null) {\r
-                                               // propertyChangeListener.propertyChange(new\r
-                                               // PropertyChangeEvent(this,\r
-                                               // "children["+child.getId()+"]", child.getClass(),\r
-                                               // NULL)); // "children" is a special field name\r
-                                               // }\r
-                                       }\r
-                               }\r
-                       }\r
-                       children.clear();\r
-                       if (changed)\r
-                               childrenChanged();\r
-               }\r
-       }\r
-\r
-       public synchronized List<T> getNodes(String rel) {\r
-               return children.getValues(rel);\r
-       }\r
-\r
-       public synchronized List<T> getNodes() {\r
-               List<T> result = new ArrayList<T>();\r
-               for (String s : children.getKeys())\r
-                       result.addAll(children.getValues(s));\r
-               return result;\r
-       }\r
-\r
-       protected void childrenChanged() {\r
-       }\r
-\r
-\r
-       @Override\r
-       public void remove() {\r
-               synchronized (children) {\r
-                       List<T> toRemove = new ArrayList<T>();\r
-               \r
-                       for (String key : children.getKeys()) {\r
-               \r
-                               for (T child : children.getValues(key)) {\r
-                                       if (child != null) {\r
-                                               toRemove.add(child);\r
-                                       }\r
-                               }\r
-                       }\r
-\r
-                       for (T n : toRemove) {\r
-                               n.remove();\r
-                       }\r
-                       \r
-                       children.clear();\r
-                       if (toRemove.size() > 0)\r
-                               childrenChanged();\r
-                       super.remove();\r
-                       \r
-               }\r
-       }\r
-       \r
-       \r
-       \r
-       \r
-       protected void fireNodeAdded(INode node, String rel) {\r
-               for (NodeListener listener : listeners) {\r
-                       listener.nodeAdded(this, node, rel);\r
-               }\r
-       }\r
-       \r
-       protected void fireNodeRemoved(INode node, String rel) {\r
-               for (NodeListener listener : listeners) {\r
-                       listener.nodeRemoved(this, node, rel);\r
-               }\r
-       }\r
-       \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g3d.scenegraph.base;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.simantics.utils.datastructures.MapList;
+
+public abstract class ParentNode<T extends INode> extends Node {
+
+       private MapList<String, T> children = new MapList<String, T>();
+
+       public synchronized void addNode(String relName, T child) {
+               if (child.getParent() != null)
+                       child.getParent().deattachNode(child.getParentRel(), child);
+
+               child.setParent(this, relName);
+               children.add(relName, (T) child);
+
+               childrenChanged();
+               fireNodeAdded(child, relName);
+       }
+
+       /**
+        * Removes child node and it's hierarchy.
+        * @param relName
+        * @param child
+        * @return
+        */
+       @SuppressWarnings("unchecked")
+       public synchronized final boolean removeNode(String relName, INode child) {
+               if (children.remove(relName, (T) child)) {
+                       fireNodeRemoved(child, relName);
+                       child.remove();
+                       child.setParent(null, null);
+                       return true;
+               }
+               return false;
+       }
+       
+       /**
+        * Removes child node. The child nodes hierarchy is left intact.
+        * @param relName
+        * @param child
+        * @return
+        */
+       @SuppressWarnings("unchecked")
+       public synchronized final boolean deattachNode(String relName, INode child) {
+               if (children.remove(relName, (T) child)) {
+                       fireNodeRemoved(child, relName);
+                       child.setParent(null, null);
+                       return true;
+               }
+               return false;
+       }
+       
+       public synchronized final boolean removeNodes(String relName) {
+               List<T> nodes = children.getValues(relName);
+               for (T child : nodes) {
+                       if (children.remove(relName, (T) child)) {
+                               fireNodeRemoved(child, relName);
+                               child.remove();
+                               child.setParent(null, null);
+                               
+                       }
+               }
+               return nodes.size() > 0;
+       }
+
+       public synchronized final void removeNodes() {
+               synchronized (children) {
+                       boolean changed = false;
+                       for (String key : children.getKeys()) {
+                               for (T child : children.getValues(key)) {
+                                       if (child != null) {
+                                               changed = true;
+                                               if (child instanceof ParentNode<?>) {
+                                                       ((ParentNode<?>) child).removeNodes();
+                                               }
+                                               child.cleanup();
+                                               child.setParent(null, null);
+                                               // if (propertyChangeListener != null) {
+                                               // propertyChangeListener.propertyChange(new
+                                               // PropertyChangeEvent(this,
+                                               // "children["+child.getId()+"]", child.getClass(),
+                                               // NULL)); // "children" is a special field name
+                                               // }
+                                       }
+                               }
+                       }
+                       children.clear();
+                       if (changed)
+                               childrenChanged();
+               }
+       }
+
+       public synchronized List<T> getNodes(String rel) {
+               return children.getValues(rel);
+       }
+
+       public synchronized List<T> getNodes() {
+               List<T> result = new ArrayList<T>();
+               for (String s : children.getKeys())
+                       result.addAll(children.getValues(s));
+               return result;
+       }
+
+       protected void childrenChanged() {
+       }
+
+
+       @Override
+       public void remove() {
+               synchronized (children) {
+                       List<T> toRemove = new ArrayList<T>();
+               
+                       for (String key : children.getKeys()) {
+               
+                               for (T child : children.getValues(key)) {
+                                       if (child != null) {
+                                               toRemove.add(child);
+                                       }
+                               }
+                       }
+
+                       for (T n : toRemove) {
+                               n.remove();
+                       }
+                       
+                       children.clear();
+                       if (toRemove.size() > 0)
+                               childrenChanged();
+                       super.remove();
+                       
+               }
+       }
+       
+       
+       
+       
+       protected void fireNodeAdded(INode node, String rel) {
+               for (NodeListener listener : listeners) {
+                       listener.nodeAdded(this, node, rel);
+               }
+       }
+       
+       protected void fireNodeRemoved(INode node, String rel) {
+               for (NodeListener listener : listeners) {
+                       listener.nodeRemoved(this, node, rel);
+               }
+       }
+       
+}