@Override
	protected void actionPerformed(ProgramLocationActionContext context) {
		ListingPanel listingPanel = provider.getListingPanel();
		ListingModel layoutModel = listingPanel.getListingModel();

		ProgramLocation location = context.getLocation();
		Data cursorData = DataUtilities.getDataAtLocation(location);
		Data actionData = cursorData.getNumComponents() > 0 ? cursorData : cursorData.getParent();
		boolean collapsing = layoutModel.isOpen(actionData);
		if (collapsing && cursorData != actionData) {
			ProgramLocation newLoc = new ProgramLocation(context.getProgram(),
				actionData.getAddress(), actionData.getComponentPath(), null, 0, 0, 0);
			listingPanel.goTo(newLoc);
		}
		layoutModel.toggleOpen(actionData);
	}
Action for toggling the expanded/collapsed state of an single expandable data element.  This
action works for both top level structures and structures inside other structures.  Also,
if invoked on any data element inside a structure, it will collapse the immediate parent
of that element.
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/actions/ToggleExpandCollapseDataAction.java