@Override
	public boolean isAddToPopup(ActionContext context) {
		if (!(context instanceof DataTypesActionContext)) {
			return false;
		}

		Object contextObject = context.getContextObject();
		GTree gtree = (GTree) contextObject;
		TreePath[] selectionPaths = gtree.getSelectionPaths();

		boolean hasLeaf = isLeafNodeSelection(selectionPaths);
		if (hasLeaf) {
			// don't add to menu when the only item selected has no children
			return selectionPaths.length != 1;
		}

		return true;
	}
This action handles recursively collapsing nodes in the dataTypes tree.  If invoked from the
local toolbar icon, it collapses all nodes in the tree.  If invoked from the popup, it only
collapses the selected nodes.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/CollapseAllArchivesAction.java