Collection<AntBuildFileBase> () { if (myTree == null) { return Collections.emptyList(); } final TreePath[] paths = myTree.getSelectionPaths(); if (paths == null) { return Collections.emptyList(); } final Set<AntBuildFileBase> result = new HashSet<>(); for (TreePath path : paths) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); while (node != null) { final Object userObject = node.getUserObject(); if (userObject instanceof AntBuildFileNodeDescriptor) { final AntBuildFileBase file = (AntBuildFileBase)((AntBuildFileNodeDescriptor)userObject).getBuildFile(); if (file != null) { result.add(file); } break; } node = (DefaultMutableTreeNode)node.getParent(); } } return result; }