public void ApplyTransformation(IDomVisitor visitor) { if (tree.SelectedNode == tree.Nodes[0]) { unit.AcceptVisitor(visitor, null); UpdateTree(); } else { string name = visitor.GetType().Name; ElementNode elementNode = tree.SelectedNode as ElementNode; CollectionNode collectionNode = tree.SelectedNode as CollectionNode; if (elementNode != null) { if (MessageBox.Show(("Apply " + name + " to selected element '" + elementNode.Text + "'?"), "Apply transformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { elementNode.element.AcceptVisitor(visitor, null); elementNode.Update(); } } else if (collectionNode != null) { if (MessageBox.Show(("Apply " + name + " to all elements in selected collection '" + collectionNode.Text + "'?"), "Apply transformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { foreach (TreeNode subNode in collectionNode.Nodes) { if (subNode is ElementNode) { (subNode as ElementNode).element.AcceptVisitor(visitor, null); } } collectionNode.Update(); } } } }