/// <summary>
        /// Updates current element properties as well as the properties of all derived elements as well as properties of derived elements of derived elements
        /// </summary>
        /// <param name="element"></param>
        public static void UpdateDerivedElementsSerializationProperties(AttributedDomainElement element)
        {
            if (element is DomainClass)
            {
                UpdateSerializationDomainProperties(element.Store, (element as DomainClass).SerializedDomainClass, element);

                LinkedElementCollection <DomainClass> classes = DomainClassReferencesBaseClass.GetDerivedClasses(element as DomainClass);
                foreach (DomainClass domainClass in classes)
                {
                    UpdateDerivedElementsSerializationProperties(domainClass);
                }
            }
            else if (element is DomainRelationship)
            {
                if (element is ReferenceRelationship)
                {
                    UpdateSerializationDomainProperties(element.Store, (element as ReferenceRelationship).SerializedReferenceRelationship, element);
                }

                if (element is EmbeddingRelationship)
                {
                    UpdateSerializationDomainProperties(element.Store, (element as EmbeddingRelationship).SerializedEmbeddingRelationship, element);
                }

                LinkedElementCollection <DomainRelationship> classes = DomainRelationshipReferencesBaseRelationship.GetDerivedRelationships(element as DomainRelationship);
                foreach (DomainRelationship d in classes)
                {
                    UpdateDerivedElementsSerializationProperties(d);
                }
            }
        }
        /// <summary>
        /// Updates current element roles as well as domain roles of all derived elements as well as roles of derived elements of derived elements
        /// </summary>
        /// <param name="element"></param>
        public static void UpdateDerivedElementsSerializationDomainRoles(AttributedDomainElement element)
        {
            if (element is DomainClass)
            {
                UpdateSerializationDomainRoles(element.Store, (element as DomainClass).SerializedDomainClass, element as DomainClass);

                LinkedElementCollection <DomainClass> classes = DomainClassReferencesBaseClass.GetDerivedClasses(element as DomainClass);
                foreach (DomainClass domainClass in classes)
                {
                    UpdateDerivedElementsSerializationDomainRoles(domainClass);
                }
            }
        }
Exemple #3
0
        public override void ModelFinalize(CopyPaste.ModelProtoElement protoElement, CopyPaste.ModelProtoGroupMerger groupMerger)
        {
            base.ModelFinalize(protoElement, groupMerger);

            DomainClass domainClass = this.Store.ElementDirectory.FindElement(groupMerger.GetIdMapping(protoElement.ElementId)) as DomainClass;

            if (domainClass == null)
            {
                return;
            }

            if (domainClass.IsDomainModel)
            {
                domainClass.IsDomainModel = false;
            }

            if (domainClass.BaseClass != null)
            {
                ReadOnlyCollection <DomainClassReferencesBaseClass> col = DomainRoleInfo.GetElementLinks <DomainClassReferencesBaseClass>(domainClass, DomainClassReferencesBaseClass.DerivedClassDomainRoleId);
                if (col.Count != 1)
                {
                    throw new ArgumentNullException("Domain class can only reference one base class");
                }

                DomainClassReferencesBaseClass r = col[0];
                r.InhNodeId = Guid.Empty;     // otherwise node id of the source element would be used
            }

            if (domainClass.DomainModelTreeNodes.Count == 0)
            {
                RootNode node = new RootNode(domainClass.Store);
                node.DomainElement   = domainClass;
                node.IsElementHolder = true;

                // add to the domain model diagram tree
                domainClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(node);
                domainClass.ModelContext.ViewContext.DomainModelTreeView.RootNodes.Add(node);
            }

            SerializationDomainClassAddRule.OnDomainClassAdded(domainClass);
            SerializationHelper.UpdateDerivedElementsSerializationProperties(domainClass);
        }
        /// <summary>
        /// Adds a new inheritance relationship instance. Needs to be called within a modeling transaction.
        /// </summary>
        /// <param name="source">Derived class</param>
        /// <param name="target">Base class</param>
        public static void AddNewInheritanceRelationship(DomainClassReferencesBaseClass con, DomainClass source, DomainClass target, bool bTargetElementHolder)
        {
            if (ImmutabilityExtensionMethods.GetLocks(target) != Locks.None)
            {
                return;
            }

            // tree nodes
            // 1. find the element holder node for source
            // 2. add new InheritanceNode
            TreeNode elementHolderNode = null;

            foreach (TreeNode node in target.DomainModelTreeNodes)
            {
                if (node.IsElementHolder)
                {
                    elementHolderNode = node;
                    break;
                }
            }

            if (elementHolderNode == null)
            {
                throw new ArgumentNullException("elementHolderNode");
            }

            InheritanceNode inhNode = new InheritanceNode(source.Store);

            inhNode.DomainElement   = source;
            inhNode.IsElementHolder = bTargetElementHolder;
            if (!inhNode.IsElementHolder)
            {
                inhNode.IsExpanded = false;
            }
            inhNode.InhRelationshipId = con.Id;
            con.InhNodeId             = inhNode.Id;

            source.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(inhNode);

            elementHolderNode.InheritanceNodes.Add(inhNode);
        }
        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;
            }

            DomainClassReferencesBaseClass inhRelationship = e.ElementLink as DomainClassReferencesBaseClass;

            if (inhRelationship != null)
            {
                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationship.DerivedClass);
                SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(inhRelationship.DerivedClass);
            }

            DomainRelationshipReferencesBaseRelationship inhRelationshipRel = e.ElementLink as DomainRelationshipReferencesBaseRelationship;

            if (inhRelationshipRel != null)
            {
                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationshipRel.DerivedRelationship);
            }
        }
        /// <summary>
        /// Creates the temp model.
        /// </summary>
        /// <returns></returns>
        public MetaModel CreateTempModel(bool bIsTarget)
        {
            // disable undo/redo
            this.MetaModel.Store.UndoManager.UndoState = Microsoft.VisualStudio.Modeling.UndoState.DisabledNoFlush;

            MetaModel           m       = null;
            LibraryModelContext context = null;

            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                m       = new MetaModel(this.MetaModel.Store);
                context = new LibraryModelContext(this.MetaModel.Store);
                m.ModelContexts.Add(context);

                // post process
                SerializationPostProcessor.PostProcessModelLoad(m);

                t.Commit();
            }

            // create copies of domain classes
            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                foreach (DomainClass d in this.InvolvedClasses)
                {
                    DomainClass domainClass = new DomainClass(this.MetaModel.Store);
                    domainClass.Name = d.Name;
                    context.Classes.Add(domainClass);

                    if (!bIsTarget)
                    {
                        this.InvolvedClassesMapping.Add(d.Id, domainClass.Id);
                    }
                    else
                    {
                        this.InvolvedClassesTargetMapping.Add(d.Id, domainClass.Id);
                    }
                }

                t.Commit();
            }

            // create inheritance relationships
            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                foreach (DomainClassReferencesBaseClass con in this.InvolvedInheritancesRelationships)
                {
                    DomainClass source;
                    DomainClass target;
                    if (!bIsTarget)
                    {
                        source = m.Store.ElementDirectory.GetElement(this.InvolvedClassesMapping[con.DerivedClass.Id]) as DomainClass;
                        target = m.Store.ElementDirectory.GetElement(this.InvolvedClassesMapping[con.BaseClass.Id]) as DomainClass;
                    }
                    else
                    {
                        source = m.Store.ElementDirectory.GetElement(this.InvolvedClassesTargetMapping[con.DerivedClass.Id]) as DomainClass;
                        target = m.Store.ElementDirectory.GetElement(this.InvolvedClassesTargetMapping[con.BaseClass.Id]) as DomainClass;
                    }

                    DomainClassReferencesBaseClass conCreated = new DomainClassReferencesBaseClass(source, target);
                    if (!bIsTarget)
                    {
                        this.InvolvedInheritancesRelationshipsMapping.Add(con.Id, conCreated.Id);
                    }
                    else
                    {
                        this.InvolvedInheritancesRelationshipsTargetMapping.Add(con.Id, conCreated.Id);
                    }
                }

                t.Commit();
            }

            // create relationships
            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                foreach (DomainRelationship rel in this.InvolvedRelationships)
                {
                    DomainClass source;
                    DomainClass target;
                    if (!bIsTarget)
                    {
                        source = m.Store.ElementDirectory.GetElement(this.InvolvedClassesMapping[rel.Source.RolePlayer.Id]) as DomainClass;
                        target = m.Store.ElementDirectory.GetElement(this.InvolvedClassesMapping[rel.Target.RolePlayer.Id]) as DomainClass;
                    }
                    else
                    {
                        source = m.Store.ElementDirectory.GetElement(this.InvolvedClassesTargetMapping[rel.Source.RolePlayer.Id]) as DomainClass;
                        target = m.Store.ElementDirectory.GetElement(this.InvolvedClassesTargetMapping[rel.Target.RolePlayer.Id]) as DomainClass;
                    }

                    DomainRelationship relCreated;
                    if (rel is ReferenceRelationship)
                    {
                        relCreated = Tum.PDE.LanguageDSL.ModelTreeHelper.AddNewReferenceRelationship(source, target);
                    }
                    else
                    {
                        relCreated = Tum.PDE.LanguageDSL.ModelTreeHelper.AddNewEmbeddingRS(source, target, false);
                    }

                    if (!bIsTarget)
                    {
                        this.InvolvedRelationshipsMapping.Add(rel.Id, relCreated.Id);
                    }
                    else
                    {
                        this.InvolvedRelationshipsTargetMapping.Add(rel.Id, relCreated.Id);
                    }
                }

                t.Commit();
            }

            this.CreateTempModel(m, bIsTarget);


            // enable undo/redo
            this.MetaModel.Store.UndoManager.UndoState = Microsoft.VisualStudio.Modeling.UndoState.Enabled;

            return(m);
        }
        public override void ElementAdded(ElementAddedEventArgs 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;
            }

            if (e.ModelElement.IsDeleting || e.ModelElement.IsDeleted)
            {
                return;
            }

            ReferenceRelationship referenceRelationship = e.ModelElement as ReferenceRelationship;

            if (referenceRelationship != null)
            {
                if (referenceRelationship.SerializedReferenceRelationship == null)
                {
                    OnReferenceRelationshipAdded(referenceRelationship);
                }
            }

            EmbeddingRelationship embeddingRelationship = e.ModelElement as EmbeddingRelationship;

            if (embeddingRelationship != null)
            {
                if (embeddingRelationship.SerializedEmbeddingRelationship == null)
                {
                    OnEmbeddingRelationshipAdded(embeddingRelationship);
                }
            }

            DomainClassReferencesBaseClass inhRelationship = e.ModelElement as DomainClassReferencesBaseClass;

            if (inhRelationship != null)
            {
                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationship.DerivedClass);
                SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(inhRelationship.DerivedClass);
            }

            DomainRelationshipReferencesBaseRelationship inhRelationshipRel = e.ModelElement as DomainRelationshipReferencesBaseRelationship;

            if (inhRelationshipRel != null)
            {
                // update derived properties
                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationshipRel.DerivedRelationship);
            }
        }
        /// <summary>
        /// Creates the temp model.
        /// </summary>
        /// <returns></returns>
        public MetaModel CreateTempModel(bool bIsTarget)
        {
            // disable undo/redo
            this.MetaModel.Store.UndoManager.UndoState = Microsoft.VisualStudio.Modeling.UndoState.DisabledNoFlush;

            MetaModel m = null;
            LibraryModelContext context = null;
            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                m = new MetaModel(this.MetaModel.Store);
                context = new LibraryModelContext(this.MetaModel.Store);
                m.ModelContexts.Add(context);

                // post process
                SerializationPostProcessor.PostProcessModelLoad(m);

                t.Commit();
            }
            
            // create copies of domain classes
            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                foreach (DomainClass d in this.InvolvedClasses)
                {
                    DomainClass domainClass = new DomainClass(this.MetaModel.Store);
                    domainClass.Name = d.Name;
                    context.Classes.Add(domainClass);

                    if( !bIsTarget )
                        this.InvolvedClassesMapping.Add(d.Id, domainClass.Id);
                    else
                        this.InvolvedClassesTargetMapping.Add(d.Id, domainClass.Id);
                }
                    
                t.Commit();
            }

            // create inheritance relationships
            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                foreach (DomainClassReferencesBaseClass con in this.InvolvedInheritancesRelationships)
                {
                    DomainClass source;
                    DomainClass target;
                    if (!bIsTarget)
                    {
                        source = m.Store.ElementDirectory.GetElement(this.InvolvedClassesMapping[con.DerivedClass.Id]) as DomainClass;
                        target = m.Store.ElementDirectory.GetElement(this.InvolvedClassesMapping[con.BaseClass.Id]) as DomainClass;
                    }
                    else
                    {
                        source = m.Store.ElementDirectory.GetElement(this.InvolvedClassesTargetMapping[con.DerivedClass.Id]) as DomainClass;
                        target = m.Store.ElementDirectory.GetElement(this.InvolvedClassesTargetMapping[con.BaseClass.Id]) as DomainClass;
                    }

                    DomainClassReferencesBaseClass conCreated = new DomainClassReferencesBaseClass(source, target);
                    if( !bIsTarget )
                        this.InvolvedInheritancesRelationshipsMapping.Add(con.Id, conCreated.Id);
                    else
                        this.InvolvedInheritancesRelationshipsTargetMapping.Add(con.Id, conCreated.Id);
                }

                t.Commit();
            }

            // create relationships
            using (Transaction t = this.MetaModel.Store.TransactionManager.BeginTransaction())
            {
                foreach (DomainRelationship rel in this.InvolvedRelationships)
                {
                    DomainClass source;
                    DomainClass target;
                    if (!bIsTarget)
                    {
                        source = m.Store.ElementDirectory.GetElement(this.InvolvedClassesMapping[rel.Source.RolePlayer.Id]) as DomainClass;
                        target = m.Store.ElementDirectory.GetElement(this.InvolvedClassesMapping[rel.Target.RolePlayer.Id]) as DomainClass;
                    }
                    else
                    {
                        source = m.Store.ElementDirectory.GetElement(this.InvolvedClassesTargetMapping[rel.Source.RolePlayer.Id]) as DomainClass;
                        target = m.Store.ElementDirectory.GetElement(this.InvolvedClassesTargetMapping[rel.Target.RolePlayer.Id]) as DomainClass;
                    }

                    DomainRelationship relCreated;
                    if( rel is ReferenceRelationship)
                        relCreated = Tum.PDE.LanguageDSL.ModelTreeHelper.AddNewReferenceRelationship(source, target);
                    else
                        relCreated = Tum.PDE.LanguageDSL.ModelTreeHelper.AddNewEmbeddingRS(source, target, false);

                    if (!bIsTarget)
                        this.InvolvedRelationshipsMapping.Add(rel.Id, relCreated.Id);
                    else
                        this.InvolvedRelationshipsTargetMapping.Add(rel.Id, relCreated.Id);
                }

                t.Commit();
            }

            this.CreateTempModel(m, bIsTarget);


            // enable undo/redo
            this.MetaModel.Store.UndoManager.UndoState = Microsoft.VisualStudio.Modeling.UndoState.Enabled;

            return m;
        }
        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;
            }

            ReferenceRelationship referenceRelationship = e.ModelElement as ReferenceRelationship;

            if (referenceRelationship != null)
            {
                if (referenceRelationship.ReferenceRSNode != null)
                {
                    referenceRelationship.ReferenceRSNode.Delete();
                }
            }

            EmbeddingRelationship embeddingRelationship = e.ModelElement as EmbeddingRelationship;

            if (embeddingRelationship != null)
            {
                if (embeddingRelationship.EmbeddingRSNode != null)
                {
                    embeddingRelationship.EmbeddingRSNode.Delete();
                }
            }

            DomainClassReferencesBaseClass inhRelationship = e.ModelElement as DomainClassReferencesBaseClass;

            if (inhRelationship != null)
            {
                InheritanceNode node = inhRelationship.Store.ElementDirectory.FindElement(inhRelationship.InhNodeId) as InheritanceNode;
                if (node != null)
                {
                    if (node.IsElementHolder)
                    {
                        RootNode rootNode = new RootNode(node.Store);
                        rootNode.DomainElement = node.DomainElement;

                        rootNode.IsElementHolder         = true;
                        rootNode.IsEmbeddingTreeExpanded = node.IsEmbeddingTreeExpanded;
                        rootNode.IsExpanded = true;
                        rootNode.IsInheritanceTreeExpanded  = node.IsInheritanceTreeExpanded;
                        rootNode.IsReferenceTreeExpanded    = node.IsReferenceTreeExpanded;
                        rootNode.IsShapeMappingTreeExpanded = node.IsShapeMappingTreeExpanded;

                        // copy sub tree
                        for (int i = node.EmbeddingRSNodes.Count - 1; i >= 0; i--)
                        {
                            node.EmbeddingRSNodes[i].TreeNode = rootNode;
                        }

                        for (int i = node.ReferenceRSNodes.Count - 1; i >= 0; i--)
                        {
                            node.ReferenceRSNodes[i].TreeNode = rootNode;
                        }

                        for (int i = node.InheritanceNodes.Count - 1; i >= 0; i--)
                        {
                            node.InheritanceNodes[i].TreeNode = rootNode;
                        }

                        for (int i = node.ShapeClassNodes.Count - 1; i >= 0; i--)
                        {
                            node.ShapeClassNodes[i].TreeNode = rootNode;
                        }

                        node.DomainElement.ParentModelContext.ViewContext.DomainModelTreeView.RootNodes.Add(rootNode);
                        node.DomainElement.ParentModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(rootNode);
                    }

                    // connection was deleted using the property window and not the menu item, so delete the rs and the
                    // node here
                    //if (inhNode.IsElementHolder)
                    //    TreeOperations.SplitTree(inhNode);

                    node.Delete();
                }
            }
        }
        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;
            }

            ReferenceRelationship referenceRelationship = e.ModelElement as ReferenceRelationship;

            if (referenceRelationship != null)
            {
                if (referenceRelationship.SerializedReferenceRelationship != null)
                {
                    referenceRelationship.SerializedReferenceRelationship.Delete();
                }

                if (referenceRelationship.Source != null)
                {
                    if (referenceRelationship.Source.RolePlayer != null)
                    {
                        SerializationHelper.UpdateDerivedElementsSerializationProperties(referenceRelationship.Source.RolePlayer);
                        SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(referenceRelationship.Source.RolePlayer);
                    }
                }

                if (referenceRelationship.Target != null)
                {
                    if (referenceRelationship.Target.RolePlayer != null)
                    {
                        SerializationHelper.UpdateDerivedElementsSerializationProperties(referenceRelationship.Target.RolePlayer);
                        SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(referenceRelationship.Target.RolePlayer);
                    }
                }
            }

            EmbeddingRelationship embeddingRelationship = e.ModelElement as EmbeddingRelationship;

            if (embeddingRelationship != null)
            {
                if (embeddingRelationship.SerializedEmbeddingRelationship != null)
                {
                    embeddingRelationship.SerializedEmbeddingRelationship.Delete();
                }

                if (embeddingRelationship.Source != null)
                {
                    if (embeddingRelationship.Source.RolePlayer != null)
                    {
                        SerializationHelper.UpdateDerivedElementsSerializationProperties(embeddingRelationship.Source.RolePlayer);
                        SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(embeddingRelationship.Source.RolePlayer);
                    }
                }

                if (embeddingRelationship.Target != null)
                {
                    if (embeddingRelationship.Target.RolePlayer != null)
                    {
                        SerializationHelper.UpdateDerivedElementsSerializationProperties(embeddingRelationship.Target.RolePlayer);
                        SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(embeddingRelationship.Target.RolePlayer);
                    }
                }
            }

            DomainClassReferencesBaseClass inhRelationship = e.ModelElement as DomainClassReferencesBaseClass;

            if (inhRelationship != null)
            {
                inhRelationship.DerivedClass.BaseClass = null;

                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationship.DerivedClass);
                SerializationHelper.UpdateDerivedElementsSerializationDomainRoles(inhRelationship.DerivedClass);
            }

            DomainRelationshipReferencesBaseRelationship inhRelationshipRel = e.ModelElement as DomainRelationshipReferencesBaseRelationship;

            if (inhRelationshipRel != null)
            {
                inhRelationshipRel.DerivedRelationship.BaseRelationship = null;

                SerializationHelper.UpdateDerivedElementsSerializationProperties(inhRelationshipRel.DerivedRelationship);
            }
        }
        /// <summary>
        /// Adds a new inheritance relationship instance. Needs to be called within a modeling transaction.
        /// </summary>
        /// <param name="source">Derived class</param>
        /// <param name="target">Base class</param>
        public static void AddNewInheritanceRelationship(DomainClass source, DomainClass target, bool bTargetElementHolder)
        {
            DomainClassReferencesBaseClass con = new DomainClassReferencesBaseClass(source, target);

            AddNewInheritanceRelationship(con, source, target, bTargetElementHolder);
        }
Exemple #12
0
        public override void ElementAdded(ElementAddedEventArgs 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;
            }

            DomainClassReferencesBaseClass con = e.ModelElement as DomainClassReferencesBaseClass;

            if (con != null)
            {
                if (con.BaseClass != null)
                {
                    InheritanceNode inhNode = con.Store.ElementDirectory.FindElement(con.InhNodeId) as InheritanceNode;
                    if (inhNode == null && ImmutabilityExtensionMethods.GetLocks(con.BaseClass) == Locks.None)
                    {
                        // connection was created using the property window and not the menu item, so create a new
                        // inheritance node to display the inheritance relationship
                        TreeNode elementHolderNode = null;
                        foreach (TreeNode node in con.BaseClass.DomainModelTreeNodes)
                        {
                            if (node.IsElementHolder)
                            {
                                elementHolderNode = node;
                                break;
                            }
                        }

                        if (elementHolderNode == null)
                        {
                            throw new ArgumentNullException("elementHolderNode");
                        }

                        // create new inheritance node
                        inhNode = new InheritanceNode(con.Store);
                        inhNode.DomainElement     = con.DerivedClass;
                        inhNode.IsElementHolder   = false;
                        inhNode.IsExpanded        = false;
                        inhNode.InhRelationshipId = con.Id;
                        con.InhNodeId             = inhNode.Id;

                        elementHolderNode.InheritanceNodes.Add(inhNode);
                        con.DerivedClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(inhNode);
                    }
                }
            }

            DomainRelationshipReferencesBaseRelationship conRef = e.ModelElement as DomainRelationshipReferencesBaseRelationship;

            if (conRef != null)
            {
                if (conRef.BaseRelationship is ReferenceRelationship && conRef.DerivedRelationship is ReferenceRelationship)
                {
                    ReferenceRelationship rBase = conRef.BaseRelationship as ReferenceRelationship;
                    ReferenceRelationship rDer  = conRef.DerivedRelationship as ReferenceRelationship;
                    if (rBase.SerializedReferenceRelationship != null && rDer.SerializedReferenceRelationship != null)
                    {
                        if (rBase.SerializedReferenceRelationship.IsInFullSerialization)
                        {
                            if (!rDer.SerializedReferenceRelationship.IsInFullSerialization)
                            {
                                // we have to automatically change the serialization mode of the derived class to full serialization mode
                                rDer.SerializedReferenceRelationship.IsInFullSerialization = true;
                            }
                        }
                    }
                }
                else if (conRef.BaseRelationship is EmbeddingRelationship && conRef.DerivedRelationship is EmbeddingRelationship)
                {
                    EmbeddingRelationship rBase = conRef.BaseRelationship as EmbeddingRelationship;
                    EmbeddingRelationship rDer  = conRef.DerivedRelationship as EmbeddingRelationship;
                    if (rBase.SerializedEmbeddingRelationship != null && rDer.SerializedEmbeddingRelationship != null)
                    {
                        if (rBase.SerializedEmbeddingRelationship.IsInFullSerialization)
                        {
                            if (!rDer.SerializedEmbeddingRelationship.IsInFullSerialization)
                            {
                                // we have to automatically change the serialization mode of the derived class to full serialization mode
                                rDer.SerializedEmbeddingRelationship.IsInFullSerialization = true;
                            }
                        }
                    }
                }
            }
        }
Exemple #13
0
        private static void FixUpDomainModelTreeView(LibraryModelContext model)
        {
            // create root nodes and embedding rs
            foreach (DomainClass domainClass in model.Classes)
            {
                if (!domainClass.HasParent())
                {
                    RootNode node = new RootNode(model.Store);
                    node.DomainElement   = domainClass;
                    node.IsElementHolder = true;
                    domainClass.ModelContext.ViewContext.DomainModelTreeView.RootNodes.Add(node);
                    domainClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(node);

                    node.IsEmbeddingTreeExpanded    = true;
                    node.IsReferenceTreeExpanded    = true;
                    node.IsInheritanceTreeExpanded  = true;
                    node.IsShapeMappingTreeExpanded = true;

                    FixUpDomainClassInTreeView(domainClass);
                }
            }

            // reference relationships + shapes
            foreach (DomainRelationship relationship in model.Relationships)
            {
                if (relationship is ReferenceRelationship)
                {
                    ReferenceRelationship rel = relationship as ReferenceRelationship;
                    ModelTreeHelper.AddNewReferenceRelationship(rel, rel.Source.RolePlayer as DomainClass, rel.Target.RolePlayer);

                    // shape
                    foreach (RelationshipShapeClass s in rel.RelationshipShapeClasses)
                    {
                        ReferenceRSNode node = rel.ReferenceRSNode;

                        // create new shape relationship node
                        ShapeRelationshipNode shapeNode = new ShapeRelationshipNode(rel.Store);
                        shapeNode.RelationshipShapeClass = s;

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

            // inheritance
            foreach (DomainClass domainClass in model.Classes)
            {
                if (domainClass.BaseClass != null)
                {
                    DomainClassReferencesBaseClass refBase = DomainClassReferencesBaseClass.GetLink(domainClass, domainClass.BaseClass);
                    if (refBase != null)
                    {
                        if (domainClass.DomainModelTreeNodes.Count > 0)
                        {
                            ModelTreeHelper.AddNewInheritanceRelationship(refBase, domainClass, domainClass.BaseClass, false);
                        }
                        else
                        {
                            ModelTreeHelper.AddNewInheritanceRelationship(refBase, domainClass, domainClass.BaseClass, true);
                        }
                    }
                }
            }

            // shapes
            foreach (DomainClass domainClass in model.Classes)
            {
                foreach (PresentationDomainClassElement p in domainClass.ShapeClasses)
                {
                    foreach (TreeNode node in domainClass.DomainModelTreeNodes)
                    {
                        if (node.IsElementHolder)
                        {
                            ShapeClassNode shapeNode = new ShapeClassNode(domainClass.Store);
                            shapeNode.ShapeClass = p;

                            node.ShapeClassNodes.Add(shapeNode);
                            domainClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(shapeNode);
                            break;
                        }
                    }
                }
            }
        }
Exemple #14
0
        public static void PostProcessModelLoad(MetaModel model)
        {
            // package and custom editor GUIDs
            if (model.PackageGuid == null || model.PackageGuid == Guid.Empty)
            {
                model.PackageGuid = Guid.NewGuid();
            }
            if (model.CustomExtensionGuid == null || model.CustomExtensionGuid == Guid.Empty)
            {
                model.CustomExtensionGuid = Guid.NewGuid();
            }


            #region relationship targets fixup
            ReadOnlyCollection <DomainRelationship> rels = model.AllRelationships;
            foreach (DomainRelationship rel in rels)
            {
                if (rel.Target.RolePlayer == null)
                {
                    ReferenceRelationship referenceRelationship = rel as ReferenceRelationship;
                    if (referenceRelationship != null)
                    {
                        if (referenceRelationship.ReferenceRSNode != null)
                        {
                            referenceRelationship.ReferenceRSNode.Delete();
                        }

                        if (referenceRelationship.SerializedReferenceRelationship != null)
                        {
                            referenceRelationship.SerializedReferenceRelationship.Delete();
                        }
                    }

                    EmbeddingRelationship embeddingRelationship = rel as EmbeddingRelationship;
                    if (embeddingRelationship != null)
                    {
                        if (embeddingRelationship.EmbeddingRSNode != null)
                        {
                            embeddingRelationship.EmbeddingRSNode.Delete();
                        }

                        if (embeddingRelationship.SerializedEmbeddingRelationship != null)
                        {
                            embeddingRelationship.SerializedEmbeddingRelationship.Delete();
                        }
                    }

                    rel.Delete();
                }
            }
            #endregion

            #region inconsistent serialization elements
            foreach (BaseModelContext context in model.ModelContexts)
            {
                if (context is LibraryModelContext)
                {
                    LibraryModelContext lib = context as LibraryModelContext;
                    if (lib.SerializationModel != null)
                    {
                        for (int i = lib.SerializationModel.Children.Count - 1; i >= 0; i--)
                        {
                            SerializationClass c = lib.SerializationModel.Children[i];
                            if (c is SerializedDomainClass)
                            {
                                SerializedDomainClass s = c as SerializedDomainClass;
                                if (s.DomainClass == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }
                            else if (c is SerializedEmbeddingRelationship)
                            {
                                SerializedEmbeddingRelationship s = c as SerializedEmbeddingRelationship;
                                if (s.EmbeddingRelationship == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }
                            else if (c is SerializedReferenceRelationship)
                            {
                                SerializedReferenceRelationship s = c as SerializedReferenceRelationship;
                                if (s.ReferenceRelationship == null)
                                {
                                    s.Delete();
                                }

                                continue;
                            }

                            // element has not been deleted, see if its properties are ok
                            for (int y = c.Properties.Count - 1; y >= 0; y--)
                            {
                                if (c.Properties[y] == null)
                                {
                                    c.Properties[y].Delete();
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region derived classes serialization items fixup
            if (model.MetaModelLibraries.Count > 0)
            {
                ReadOnlyCollection <ModelElement> elements = model.Store.ElementDirectory.FindElements(DomainClassReferencesBaseClass.DomainClassId);
                foreach (ModelElement m in elements)
                {
                    DomainClassReferencesBaseClass con = m as DomainClassReferencesBaseClass;
                    if (con != null)
                    {
                        if (con.BaseClass != null)
                        {
                            if (con.BaseClass.ModelContext.MetaModel != model)
                            {
                                foreach (DomainClass derivedClass in con.BaseClass.DerivedClasses)
                                {
                                    FixUpDerivedClasses(derivedClass, model);
                                }
                            }
                        }
                    }
                }

                ReadOnlyCollection <ModelElement> elementsCon = model.Store.ElementDirectory.FindElements(DomainRelationshipReferencesBaseRelationship.DomainClassId);
                foreach (ModelElement m in elementsCon)
                {
                    DomainRelationshipReferencesBaseRelationship con = m as DomainRelationshipReferencesBaseRelationship;
                    if (con != null)
                    {
                        if (con.BaseRelationship != null)
                        {
                            if (con.BaseRelationship.ModelContext.MetaModel != model)
                            {
                                foreach (DomainRelationship derivedClass in con.BaseRelationship.DerivedRelationships)
                                {
                                    FixUpDerivedRelationships(derivedClass, model);
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region check if model contains all required elements
            // property grid editors
            if (model.PropertyGridEditors.Count == 0)
            {
                FixUpPropertyGridEditors(model);
            }

            // domain types
            if (model.DomainTypes.Count == 0)
            {
                FixUpDomainTypes(model);
            }

            // model context
            if (model.ModelContexts.Count == 0)
            {
                FixUpModelContext(model);
            }

            // validation
            if (model.Validation == null)
            {
                model.Validation = new Validation(model.Store);
            }

            if (model.View == null)
            {
                model.View = new View(model.Store);
            }

            if (model.View.ModelTree == null)
            {
                model.View.ModelTree = new ModelTree(model.Store);
            }

            foreach (BaseModelContext mContext in model.ModelContexts)
            {
                if (mContext is LibraryModelContext)
                {
                    LibraryModelContext m = mContext as LibraryModelContext;
                    if (m.DiagramClasses.Count == 0 && m is ModelContext)
                    {
                        DesignerDiagramClass ddC = new DesignerDiagramClass(model.Store);
                        ddC.Name  = "DesignerDiagram";
                        ddC.Title = "Designer";

                        m.DiagramClasses.Add(ddC);
                    }

                    if (m.ViewContext == null)
                    {
                        m.ViewContext = new ViewContext(model.Store);
                        m.ViewContext.DomainModelTreeView = new DomainModelTreeView(model.Store);
                        m.ViewContext.DiagramView         = new DiagramView(model.Store);

                        model.View.ViewContexts.Add(m.ViewContext);

                        FixUpDomainModelTreeView(m);
                        FixUpDiagramView(m);
                    }

                    if (m.ViewContext.DiagramView == null || m.ViewContext.DomainModelTreeView == null)
                    {
                        if (m.ViewContext.DomainModelTreeView == null)
                        {
                            m.ViewContext.DomainModelTreeView = new DomainModelTreeView(model.Store);
                            FixUpDomainModelTreeView(m);
                        }

                        if (m.ViewContext.DiagramView == null)
                        {
                            m.ViewContext.DiagramView = new DiagramView(model.Store);
                            FixUpDiagramView(m);
                        }
                    }

                    // diagram class view for designer diagram
                    if (m.ViewContext.DiagramView.DiagramClassViews.Count == 0 && m is ModelContext)
                    {
                        DiagramClassView vm = new DiagramClassView(model.Store);
                        vm.IsExpanded = true;
                        foreach (DiagramClass d in m.DiagramClasses)
                        {
                            if (d is DesignerDiagramClass)
                            {
                                vm.DiagramClass = d;
                                break;
                            }
                        }

                        m.ViewContext.DiagramView.DiagramClassViews.Add(vm);
                    }

                    // serialization
                    if (m.SerializationModel == null)
                    {
                        m.SerializationModel = new SerializationModel(model.Store);
                    }

                    // serialized domain model
                    if (m is ModelContext)
                    {
                        if (m.SerializationModel.SerializedDomainModel == null)
                        {
                            FixUpSerializedDomainModel(m as ModelContext);
                        }
                    }
                }
            }
            #endregion

            // view ids.
            if (model.View != null)
            {
                if (model.View.ModelTreeId == null || model.View.ModelTreeId == Guid.Empty)
                {
                    model.View.ModelTreeId = Guid.NewGuid();
                }

                if (model.View.DependenciesViewId == null || model.View.DependenciesViewId == Guid.Empty)
                {
                    model.View.DependenciesViewId = Guid.NewGuid();
                }

                if (model.View.ErrorListId == null || model.View.ErrorListId == Guid.Empty)
                {
                    model.View.ErrorListId = Guid.NewGuid();
                }

                if (model.View.PropertyGridId == null || model.View.PropertyGridId == Guid.Empty)
                {
                    model.View.PropertyGridId = Guid.NewGuid();
                }

                if (model.View.SearchId == null || model.View.SearchId == Guid.Empty)
                {
                    model.View.SearchId = Guid.NewGuid();
                }

                if (model.View.SearchResultId == null || model.View.SearchResultId == Guid.Empty)
                {
                    model.View.SearchResultId = Guid.NewGuid();
                }

                if (model.View.PluginWindowId == null || model.View.PluginWindowId == Guid.Empty)
                {
                    model.View.PluginWindowId = Guid.NewGuid();
                }
            }
        }
        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;
            }

            DomainClassReferencesBaseClass con = e.ElementLink as DomainClassReferencesBaseClass;

            if (con != null)
            {
                if (con.BaseClass != null)
                {
                    TreeNode elementHolderNode = null;
                    foreach (TreeNode node in con.BaseClass.DomainModelTreeNodes)
                    {
                        if (node.IsElementHolder)
                        {
                            elementHolderNode = node;
                            break;
                        }
                    }

                    if (elementHolderNode == null)
                    {
                        throw new ArgumentNullException("elementHolderNode");
                    }

                    // we need to delte the old inheritance node and add a new one for the changed inheritance relationship
                    InheritanceNode inhNodeOld = con.Store.ElementDirectory.FindElement(con.InhNodeId) as InheritanceNode;
                    if (inhNodeOld == null)
                    {
                        return;
                    }

                    // create new inheritance node
                    InheritanceNode inhNode = new InheritanceNode(con.Store);
                    inhNode.DomainElement              = con.DerivedClass;
                    inhNode.IsElementHolder            = inhNodeOld.IsElementHolder;
                    inhNode.IsExpanded                 = inhNodeOld.IsExpanded;
                    inhNode.InhRelationshipId          = con.Id;
                    inhNode.IsEmbeddingTreeExpanded    = inhNodeOld.IsEmbeddingTreeExpanded;
                    inhNode.IsInheritanceTreeExpanded  = inhNodeOld.IsInheritanceTreeExpanded;
                    inhNode.IsReferenceTreeExpanded    = inhNodeOld.IsReferenceTreeExpanded;
                    inhNode.IsShapeMappingTreeExpanded = inhNodeOld.IsShapeMappingTreeExpanded;
                    con.InhNodeId = inhNode.Id;

                    // copy sub tree
                    for (int i = inhNodeOld.EmbeddingRSNodes.Count - 1; i >= 0; i--)
                    {
                        inhNodeOld.EmbeddingRSNodes[i].TreeNode = inhNode;
                    }

                    for (int i = inhNodeOld.ReferenceRSNodes.Count - 1; i >= 0; i--)
                    {
                        inhNodeOld.ReferenceRSNodes[i].TreeNode = inhNode;
                    }

                    for (int i = inhNodeOld.InheritanceNodes.Count - 1; i >= 0; i--)
                    {
                        inhNodeOld.InheritanceNodes[i].TreeNode = inhNode;
                    }

                    for (int i = inhNodeOld.ShapeClassNodes.Count - 1; i >= 0; i--)
                    {
                        inhNodeOld.ShapeClassNodes[i].TreeNode = inhNode;
                    }

                    elementHolderNode.InheritanceNodes.Add(inhNode);
                    con.DerivedClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(inhNode);

                    inhNodeOld.Delete();
                }
            }
        }