예제 #1
0
        public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            base.ElementDeleting(e);

            ModelClass  element = (ModelClass)e.ModelElement;
            Store       store   = element.Store;
            Transaction current = store.TransactionManager.CurrentTransaction;

            if (current.IsSerializing || ModelRoot.BatchUpdating)
            {
                return;
            }

            foreach (ModelAttribute attribute in element.Attributes)
            {
                attribute.SetLocks(Locks.None);
            }

            List <Generalization> generalizations = store.GetAll <Generalization>().Where(g => g.Superclass == element).ToList();

            if (generalizations.Any())
            {
                string question = generalizations.Count == 1
                                 ? $"Push {element.Name} attributes and associations down its to its subclass?"
                                 : $"Push {element.Name} attributes and associations down its to {generalizations.Count} subclasses?";

                if (BooleanQuestionDisplay.Show(store, question) == true)
                {
                    foreach (ModelClass subclass in generalizations.Select(g => g.Subclass))
                    {
                        element.MoveContents(subclass);
                    }
                }
            }
        }
        /// <inheritdoc />
        public override void ElementDeleting(ElementDeletingEventArgs e)
        {
            base.ElementDeleting(e);

            Generalization element = (Generalization)e.ModelElement;
            Store          store   = element.Store;
            Transaction    current = store.TransactionManager.CurrentTransaction;

            if (current.IsSerializing || ModelRoot.BatchUpdating)
            {
                return;
            }

            if (element.Superclass.IsDeleting)
            {
                return;
            }

            ModelClass subclass   = element.Subclass;
            ModelClass superclass = element.Superclass;

            List <Association> associations = superclass.AllNavigationProperties()
                                              .Select(n => n.AssociationObject)
                                              .Distinct()
                                              .ToList();

            if (!superclass.AllAttributes.Any() && !associations.Any())
            {
                return;
            }

            if (!subclass.IsDeleting && BooleanQuestionDisplay.Show(store, $"Push {superclass.Name} attributes and associations down to {subclass.Name}?") == true)
            {
                superclass.MoveContents(subclass);
            }
        }