You can use the ToggleState() method of the show/hide subtree decorator to achieve this:
showHideSubTreeDecorator.ToggleState();
document.SmartRefreshAllViews();
Note, that if you want to check if the decorator is currently expanded or not you can use its GetState() method.
Best Regards,
Nevron Support Team