protected void collapseNode(GTreeNode node, TaskMonitor monitor) throws CancelledException {
		if (node.isLeaf()) {
			return;
		}
		monitor.checkCancelled();
		List<GTreeNode> allChildren = node.getChildren();
		if (allChildren.size() == 0) {
			return;
		}
		TreePath treePath = node.getTreePath();
		if (jTree.isExpanded(treePath)) {
			collapsePath(treePath, monitor);
		}
		for (GTreeNode child : allChildren) {
			monitor.checkCancelled();
			collapseNode(child, monitor);
		}
		monitor.incrementProgress(1);
	}
A GTree task to fully collapse a tree
Ghidra/Framework/Docking/src/main/java/docking/widgets/tree/tasks/GTreeCollapseAllTask.java