JTree <--> JDom
hi, i need to make an application that load an xml doc into a jtree. Then the user should be able to edit node content with a jtextarea and finally save changes. To load xml document to jtree i did:
private DefaultMutableTreeNode createTreeNode(Element node){
DefaultMutableTreeNode treeNode =new DefaultMutableTreeNode(node.getName());
List children = node.getChildren();
Element child;
for (int i = 0; i < children.size(); i++){
child = (Element) children.get(i);
if (childinstanceof Element){
treeNode.add(createTreeNode(child));
}
}
return treeNode;
}
public DefaultTreeModel getTreeModel(){
DefaultMutableTreeNode root = createTreeNode(document.getRootElement());
DefaultTreeModel treeModel =new DefaultTreeModel(root);
return treeModel;
}
then i set that treeModel to tree.setModel().
The problem is the following: when i click on a jtree node i wish to show into jtextarea the content of the node represented by the jtree-node clicked. In the treeEvent handler i don't know how to get the right node in the jdom document that correspond to the jtree node clicked.
I thought to set an id to my jdom document nodes, then on treeEvent, check which one is selected, get enumeration by depthFirst() method, and so on....
Is there any clever way to do that?
Thanks

