PackageNode (final Tree tree) { TreePath[] paths = tree.getSelectionPaths(); if (paths == null || paths.length != 1) return null; PackageDependenciesNode node = (PackageDependenciesNode)paths[0].getLastPathComponent(); if (node.isRoot()) return null; if (node instanceof PackageNode) { return (PackageNode)node; } if (node instanceof FileNode) { return (PackageNode)node.getParent(); } if (node instanceof ModuleNode){ return (PackageNode)node.getChildAt(0); } return null; }