Universal Robots Forum

Child node links are broken on load

In my CAP, users create child nodes from a main node. Upon doing this, I also use root = programModel.getRootTreeNode() to pass an instance of this node into the newly created child. The node is then assigned to the “parent” of the new child node. (This allows my child nodes to see my parent node, and thus create sibling nodes by calling parent.addChild() for example).

Everything works well until I try to load a program that has child nodes. It appears that the parent node is loaded before the children. The idea was to run a traverse in the constructor of the parent nodes that re-passes itself down to the children, thus re-establishing the parent/child link. However, when the parent node constructor is called, the .getChildren() method returns an empty list, ie the Children haven’t actually been loaded yet.

What is the correct method for relinking children to the parent when loading a program? My current workaround is to launch a timer thread that keeps checking for children to exist, and when they do, it establishes the link. The problem here is that every time I “copy” or “cut” a parent node, a new instance of this timer is created and never stops haha. Probably multiple issues going on here, but either way a timer/delay seems like a hacky way to re-link these nodes.