Module[] () { final TreePath[] paths = myTree.getSelectionPaths(); Set<Module> modules = new LinkedHashSet<>(); if (paths != null) { for (TreePath path : paths) { MyNode node = (MyNode)path.getLastPathComponent(); final NamedConfigurable<?> configurable = node.getConfigurable(); LOG.assertTrue(configurable != null, "already disposed"); final Object o = configurable.getEditableObject(); if (o instanceof Module) { modules.add((Module)o); } else if (node instanceof ModuleGroupNode && ((ModuleGroupNode)node).getModuleGroup() != null) { TreeUtil.treeNodeTraverser(node).forEach(descendant -> { if (descendant instanceof MyNode) { Object object = ((MyNode)descendant).getConfigurable().getEditableObject(); if (object instanceof Module) { modules.add((Module)object); } } }); } } } return !modules.isEmpty() ? modules.toArray(Module.EMPTY_ARRAY) : null; }