Getting Node Objects

I have the evaluation version of JGo and I’m currently creating an application, but now running into a problem. What I have left to do is allow a user to click a node and have all the nodes that aren’t a parent or child of the selected node removed. The nodes have a 1:1 relationship…just like a JTree. The problem I’m having is that I can’t traverse parent/child relationship. At least that’s what I’m running into now. I basically edited the FamilyTree program and now I’m lost. It seems like each node have around 5 objects on it…when I use methods like getPreviousObjPos, it just returns position of the object within that node. Thanks!

Yes, you are iterating over the structure of the nodes, instead of looking at the links that are connected to any port(s) of that node.
Normally, given a node, you can find all the nodes directly connected to that node by looking at the links that are connected to each of its ports. If you are using a JGoTextNode, you should examine each of its (up to) 4 ports.
For each port, iterate over all of its links. FamilyTreeDoc in the FamilyTree example does this in a number of places for various purposes. For example, given a port (here as the variable MP):
// now look at each child
JGoListPosition childpos = mp.getFirstLinkPos();
while (childpos != null) {
JGoLink childlink = mp.getLinkAtPos(childpos);
childpos = mp.getNextLinkPos(childpos);
JGoPort childp = childlink.getOtherPort(mp);
PersonNode childnode = (PersonNode)childp.getParent();
// do something with the childnode
}

You might decide to keep a collection of nodes that you find at the other ends of all the links you look at, so that you can remove all other nodes from the document.