while(e.hasMoreElements())
{
DefaultMutableTreeNode node =(DefaultMutableTreeNode)e.nextElement();
BehaviourTreeNode bNode = (BehaviourTreeNode)node.getUserObject();
BehaviourID b = bNode.getBehaviour();
if (b.getCode() == behaviour.getCode() && b.equals(behaviour))
{
Object[]o=node.getPath();
TreePath tp= new TreePath(o);
tree.setSelectionPath(tp);
description(gui.getBehaviourText(), b);
// Update the blocked status.
/*if ((blocked && !bNode.isBlocked()) ||
(!blocked && bNode.isBlocked())) {
bNode.setBlocked(blocked);
model.nodeChanged(node);
}*/
if (!state.equals(bNode.getState())) {
bNode.setState(state);
model.nodeChanged(node);
}
bFound = true;
break;
}
}
/* If we didn't find the node in the tree, add it now.
if (!bFound)
action = ADD_NODE;
*/
}
if (action == ADD_NODE)
{
//DefaultMutableTreeNode beh = new DefaultMutableTreeNode(new BehaviourTreeNode(behaviour, blocked));
DefaultMutableTreeNode beh = new DefaultMutableTreeNode(new BehaviourTreeNode(behaviour, state));
if (!behaviour.isSimple()) {
createTree(beh, behaviour.getAllChildren());
}
model.insertNodeInto(beh,root,model.getChildCount(root));
}
if (action == REMOVE_NODE)
{
Enumeration e=root.breadthFirstEnumeration();
e.nextElement();
while(e.hasMoreElements())
{
DefaultMutableTreeNode node =(DefaultMutableTreeNode)e.nextElement();
BehaviourTreeNode b = (BehaviourTreeNode)node.getUserObject();
if (b.getBehaviour().equals(behaviour)){
model.removeNodeFromParent(node);
break;
}
}
}