boolean (final Module[] modules) { if (myRoot.getChildCount() == 0) return false; //isn't visible List<Pair<MyNode, Module>> nodes = new ArrayList<>(modules.length); Set<MyNode> nodeSet = new HashSet<>(); for (Module module : modules) { MyNode node = findModuleNode(module); LOG.assertTrue(node != null, "Module " + module.getName() + " is not in project."); nodes.add(Pair.create(node, module)); nodeSet.add(node); } ModuleGroupingTreeHelper<Module, MyNode> helper = createGroupingHelper(nodeSet::contains); helper.moveModuleNodesToProperGroup(nodes, myRoot, getTreeModel(), myTree); return true; }