List<ToolsGroup<T>> () { MutableTreeNode root = (MutableTreeNode)myTree.getModel().getRoot(); List<ToolsGroup<T>> result = new ArrayList<>(root.getChildCount()); for (int i = 0; i < root.getChildCount(); i++) { final CheckedTreeNode node = (CheckedTreeNode)root.getChildAt(i); for (int j = 0; j < node.getChildCount(); j++) { final CheckedTreeNode toolNode = (CheckedTreeNode)node.getChildAt(j); ((Tool)toolNode.getUserObject()).setEnabled(toolNode.isChecked()); } //noinspection unchecked result.add((ToolsGroup)node.getUserObject()); } return result; }