Beispiel #1
0
        private void OnModelModified(object sender, EventArgs e)
        {
            //
            // Model has, ViewModel has not
            //
            foreach (var umlClass in Model.Classes)
            {
                if (GetDiagramClass(umlClass) == null)
                {
                    AddClassFromModel(umlClass);
                }
            }
            foreach (var umlRelation in Model.Relations)
            {
                if (GetDiagramRelation(umlRelation) == null)
                {
                    AddRelationFromModel(umlRelation);
                }
            }
            //
            // ViewModel has, Model has not
            //
            List <UmlDiagramClass> classesToRemove = new List <UmlDiagramClass>();

            foreach (var umlDiagramClass in Classes)
            {
                if (!Model.Classes.Contains(umlDiagramClass.Class))
                {
                    classesToRemove.Add(umlDiagramClass);
                }
            }
            foreach (var umlDiagramClass in classesToRemove)
            {
                RemoveDiagramClass(umlDiagramClass);
                // At this point, we know that the umlClass is not present in the Model.
                // Hence, at this point we should remove the name from the class list (autocompletebox).
                if (ClassNames.Contains(umlDiagramClass.Name))
                {
                    ClassNames.Remove(umlDiagramClass.Name);
                }
            }

            List <UmlDiagramRelation> relationsToRemove = new List <UmlDiagramRelation>();

            foreach (var umlDiagramRelation in Relations)
            {
                if (!Model.Relations.Contains(umlDiagramRelation.Relation))
                {
                    relationsToRemove.Add(umlDiagramRelation);
                }
            }
            foreach (var umlDiagramRelation in relationsToRemove)
            {
                RemoveDiagramRelation(umlDiagramRelation);
            }
        }