public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            if (e.ModelElement != null)
            {
                if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ModelElement == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None)
            {
                return;
            }

            RelationshipShapeClassReferencesReferenceRelationship con = e.ModelElement as RelationshipShapeClassReferencesReferenceRelationship;

            if (con != null)
            {
                if (con.DomainRelationship is ReferenceRelationship)
                {
                    RelationshipShapeClass shape = con.RelationshipShapeClass;
                    ShapeRelationshipNode  node  = shape.ShapeRelationshipNode;
                    if (node != null)
                    {
                        // delete
                        ReferenceRelationship rel = con.DomainRelationship as ReferenceRelationship;
                        ReferenceRSNode       n   = rel.ReferenceRSNode;
                        if (n != null)
                        {
                            if (n.ShapeRelationshipNodes.Contains(node))
                            {
                                n.ShapeRelationshipNodes.Remove(node);
                            }
                        }
                        node.Delete();
                    }
                }
            }
        }
        public override void RolePlayerChanged(RolePlayerChangedEventArgs e)
        {
            if (e.ElementLink != null)
            {
                if (e.ElementLink.Store.TransactionManager.CurrentTransaction != null)
                {
                    if (e.ElementLink.Store.TransactionManager.CurrentTransaction.IsSerializing)
                    {
                        return;
                    }
                }
            }

            if (e.ElementLink == null)
            {
                return;
            }

            if (ImmutabilityExtensionMethods.GetLocks(e.ElementLink) != Locks.None)
            {
                return;
            }

            RelationshipShapeClassReferencesReferenceRelationship con = e.ElementLink as RelationshipShapeClassReferencesReferenceRelationship;

            if (con != null)
            {
                RelationshipShapeClass shape = con.RelationshipShapeClass;
                ShapeRelationshipNode  node  = shape.ShapeRelationshipNode;

                // delete old
                ReferenceRelationship relOld = e.OldRolePlayer as ReferenceRelationship;
                if (relOld != null)
                {
                    ReferenceRSNode nodeOld = relOld.ReferenceRSNode;
                    if (nodeOld != null)
                    {
                        node.RelationshipShapeClass = null;

                        if (nodeOld.ShapeRelationshipNodes.Contains(node))
                        {
                            nodeOld.ShapeRelationshipNodes.Remove(node);
                        }
                    }
                    node.Delete();
                }

                // create new
                ReferenceRelationship rel = e.NewRolePlayer as ReferenceRelationship;
                if (rel != null)
                {
                    ReferenceRSNode n = rel.ReferenceRSNode;

                    // create new shape relationship node
                    ShapeRelationshipNode shapeNode = new ShapeRelationshipNode(con.Store);
                    shape.ShapeRelationshipNode = shapeNode;

                    n.ShapeRelationshipNodes.Add(shapeNode);
                    rel.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(shapeNode);

                    if (rel.SerializedReferenceRelationship != null)
                    {
                        if (!rel.SerializedReferenceRelationship.IsInFullSerialization)
                        {
                            if (System.Windows.MessageBox.Show("Shape mapping has been defined for the ReferenceRelationship '" +
                                                               rel.Name + "'. The Relationship is not serialized in full form. Would you like to change the serialization of this relationship to full form (strongly adviced)?",
                                                               "Serialization",
                                                               System.Windows.MessageBoxButton.YesNo,
                                                               System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.Yes)
                            {
                                rel.SerializedReferenceRelationship.IsInFullSerialization = true;
                            }
                        }
                    }
                }
            }
        }