Validation and undo when a user removes part from a group

When user adds part to a group, I can fire custom functions on “memberValidation” and “memberAdded”, basically before and after actual addition of a part. When user tries to take part out of a group, I can only fire my function on “memberRemoved” and it is outside of a transaction.
On page it says:

“You can control whether certain Nodes are added to a Group by CommandHandler.groupSelection or addMembers or CommandHandler.addTopLevelParts by affecting the result of CommandHandler.isValidMember, which is responsible for deciding whether it is OK to add a Node to a Group or to remove a Node from a Group to be a top-level node. You can override that predicate on CommandHandler, but it is easier to set the memberValidation or CommandHandler.memberValidation functional property.”

It is not clear to me how to validation business logic checking if a part can be moved out of a given node to other node or become a top level node and act appropriately. Are there any useful samples for this?

First, given the content of your question, I’ll assume this topic really has nothing to do with undo, despite the title.

Second, are you looking to have a way of preventing a Part from being removed from a Group even though it’s OK (“valid”) to be added to another Group, during an operation which changes group membership? If so, no, sorry, I think all of the validation properties are “adding-oriented”, because a Group.memberValidation is associated with the Group being added to, not the Group being removed from. This is similar to link validation – Node.linkValidation is oriented towards the nodes being connected, not the nodes being disconnected. But the predicate could check the current Part.containingGroup to decide if it should be taken out of that Group.

Furthermore the CommandHandler.memberValidation predicate is at the Diagram level, not associated with any particular Group, so it can handle Parts being removed from a Group whether it’s being proposed to be added to another Group or to become top-level.

There is a general design policy that things can be decided either locally or globally. Locally would mean on a GraphObject or a Part; globally would mean on a Diagram or a CommandHandler or a Tool, for which there is only one instance of each per diagram. That’s why there are validation predicates for both linking and grouping at both the Nodes/Parts level and the Diagram level.