AntBuildFileNodeDescriptor () { final Tree tree = myTree; if (tree == null) { return null; } final TreePath path = tree.getSelectionPath(); if (path == null) { return null; } DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); while (node != null) { final Object userObject = node.getUserObject(); if (userObject instanceof AntBuildFileNodeDescriptor) { return (AntBuildFileNodeDescriptor)userObject; } node = (DefaultMutableTreeNode)node.getParent(); } return null; }