public override void Execute(object parameter)
        {
            IEnumerable <PSMContentModel> selectedContentModels = Current.ActiveDiagramView.GetSelectedComponents()
                                                                  .Where(c => c is PSMContentModel).Cast <PSMContentModel>();

            if (selectedContentModels.Count() > 0)
            {
                MacroCommand macro = new MacroCommand(Current.Controller);
                foreach (PSMContentModel cm in selectedContentModels)
                {
                    macro.Commands.Add(new cmdUpdatePSMContentModel(Current.Controller)
                    {
                        CmodelGuid = cm, Type = Type
                    });
                }
                macro.Execute();
            }
            else
            {
                IEnumerable <PSMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents()
                                                                    .Where(c => c is PSMAssociation).Cast <PSMAssociation>();
                PSMAssociationMember     parent  = selectedAssociations.First().Parent;
                cmdContentToContentModel command = new cmdContentToContentModel(Current.Controller);
                command.Set(parent, selectedAssociations.Select(a => a.ID), Type, Guid.NewGuid(), Guid.NewGuid());
                command.Execute();
            }
        }
        internal override void GenerateSubCommands()
        {
            PSMAssociationMember associationMember = Project.TranslateComponent <PSMAssociationMember>(AssociationMemberGuid);

            if (associationMember is PSMClass)
            {
                cmdDeletePSMClassRecursive dc = new cmdDeletePSMClassRecursive(Controller);
                dc.Set(associationMember);
                Commands.Add(dc);
            }
            else if (associationMember is PSMContentModel)
            {
                cmdDeletePSMContentModelRecursive dcm = new cmdDeletePSMContentModelRecursive(Controller);
                dcm.Set(associationMember);
                Commands.Add(dcm);
            }
            else if (associationMember is PSMSchemaClass)
            {
                //Happens only when deleting PSM Schema. We clear the SchemaClass and let the atomic operation "delete PSM Schema" delete the actual class
                foreach (PSMAssociation a in associationMember.ChildPSMAssociations)
                {
                    cmdDeletePSMAssociationRecursive da = new cmdDeletePSMAssociationRecursive(Controller);
                    da.Set(a);
                    Commands.Add(da);
                }
            }
        }
Ejemplo n.º 3
0
 private void TranslateContent(PSMAssociationMember parentComponent, DataGeneratorContext context)
 {
     foreach (PSMAssociation childAssociation in parentComponent.ChildPSMAssociations)
     {
         TranslateAssociation(childAssociation, context);
     }
 }
Ejemplo n.º 4
0
        private void ConvertPSMAssociation(PSMAssociation psmAssociation, PSMAssociationViewHelper psmAssociationViewHelper)
        {
            EvoX.Model.PSM.PSMAssociation evoxPSMAssociation;
            if (!TranslatedAlready(psmAssociation, out evoxPSMAssociation))
            {
                PSMAssociationMember parent = (PSMAssociationMember)ElementRef(psmAssociation.Parent);
                PSMAssociationMember child  = (PSMAssociationMember)ElementRef(psmAssociation.Child);
                evoxPSMAssociation = new EvoX.Model.PSM.PSMAssociation(evoxProject, parent, child, psmSchema);
                associationOrder[evoxPSMAssociation] = psmAssociation.ComponentIndex();
                translatedElements[psmAssociation]   = evoxPSMAssociation;
            }

            PSMClass childPSMClass = psmAssociation.Child as PSMClass;

            if (childPSMClass != null && childPSMClass.HasElementLabel)
            {
                evoxPSMAssociation.Name = childPSMClass.ElementName;
            }
            else
            {
                evoxPSMAssociation.Name = null;
            }
            PSMClassUnion psmClassUnion = psmAssociation.Child as PSMClassUnion;

            if (psmClassUnion != null)
            {
                evoxPSMAssociation.Name = null;
            }

            evoxPSMAssociation.Lower = ConvertToUint(psmAssociation.Lower);
            evoxPSMAssociation.Upper = ConvertToUnlimitedInt(psmAssociation.Upper);
        }
Ejemplo n.º 5
0
        public override bool CanExecute(object parameter)
        {
            if (!(Current.ActiveDiagram is PSMDiagram))
            {
                return(false);
            }

            if (!Current.ActiveDiagramView.IsSelectedComponentOfType(typeof(PSMAssociationMember)))
            {
                return(false);
            }

            PSMAssociationMember associationMember = Current.ActiveDiagramView.GetSingleSelectedComponentOrNull() as PSMAssociationMember;

            if (associationMember.ParentAssociation != null && associationMember.ParentAssociation.Interpretation != null)
            {
                return(false);
            }
            if (associationMember is PSMClass && (associationMember as PSMClass).Interpretation != null)
            {
                return(false);
            }
            if (associationMember is PSMSchemaClass)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        public override void Execute(object parameter)
        {
            IEnumerable <PSMContentModel> selectedContentModels = Current.ActiveDiagramView.GetSelectedComponents()
                                                                  .Where(c => c is PSMContentModel).Cast <PSMContentModel>();

            if (selectedContentModels.Count() > 0)
            {
                MacroCommand macro = new MacroCommand(Current.Controller);
                foreach (PSMContentModel cm in selectedContentModels)
                {
                    Guid newClassGuid = new Guid();
                    macro.Commands.Add(new cmdContentToPSMClass(Current.Controller)
                    {
                        Associations = cm.ChildPSMAssociations.Select(assoc => assoc.ID).ToList(),
                        ParentAssociationMemberGuid = cm,
                        ClassGuid = newClassGuid
                    });
                    macro.Commands.Add(new cmdLeaveOutUninterpretedAssociationMember(Current.Controller)
                    {
                        AssociationMemberGuid = cm
                    });
                }
                macro.Execute();
            }
            else
            {
                IEnumerable <PSMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents()
                                                                    .Where(c => c is PSMAssociation).Cast <PSMAssociation>();
                PSMAssociationMember parent  = selectedAssociations.First().Parent;
                cmdContentToPSMClass command = new cmdContentToPSMClass(Current.Controller);
                command.Set(parent, selectedAssociations.Select(a => a.ID), Guid.NewGuid(), Guid.NewGuid());
                command.Execute();
            }
        }
Ejemplo n.º 7
0
        private bool TestNodeDefinesAttributes(PSMAssociationMember node)
        {
            if (node is PSMClass)
            {
                PSMClass psmClass = (PSMClass)node;
                if (psmClass.PSMAttributes.Any(a => !a.Element))
                {
                    return(true);
                }

                if (psmClass.IsStructuralRepresentative)
                {
                    if (TestNodeDefinesAttributes(psmClass.RepresentedClass))
                    {
                        return(true);
                    }
                }
            }

            foreach (PSMAssociation childPsmAssociation in node.ChildPSMAssociations)
            {
                if (!childPsmAssociation.IsNamed)
                {
                    if (TestNodeDefinesAttributes(childPsmAssociation.Child))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override bool VerifyConsistency(object superordinateObject, object candidate)
        {
            PSMAssociationMember PSMAssociationMember = (PSMAssociationMember)superordinateObject;
            PSMAssociation       PSMAssociation       = (PSMAssociation)candidate;

            return(PSMAssociationMember.ChildPSMAssociations.Contains(PSMAssociation));
        }
        public override bool CanExecute(object parameter)
        {
            if (!(Current.ActiveDiagram is PSMDiagram))
            {
                return(false);
            }

            IEnumerable <PSMContentModel> selectedContentModels = Current.ActiveDiagramView.GetSelectedComponents()
                                                                  .Where(c => c is PSMContentModel).Cast <PSMContentModel>();

            IEnumerable <PSMAssociation> selectedAssociations = Current.ActiveDiagramView.GetSelectedComponents()
                                                                .Where(c => c is PSMAssociation).Cast <PSMAssociation>();

            if (selectedContentModels.Count() > 0 && selectedAssociations.Count() == 0)
            {
                return(true);
            }
            else if (selectedContentModels.Count() == 0 && selectedAssociations.Count() > 0)
            {
                PSMAssociationMember parent = selectedAssociations.First().Parent;
                if (selectedAssociations.Any(a => a.Parent != parent))
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
        internal override void GenerateSubCommands()
        {
            if (ContentModelGuid == Guid.Empty)
            {
                ContentModelGuid = Guid.NewGuid();
            }
            if (AssociationGuid == Guid.Empty)
            {
                AssociationGuid = Guid.NewGuid();
            }

            PSMAssociationMember         parent       = Project.TranslateComponent <PSMAssociationMember>(ParentAssociationMemberGuid);
            IEnumerable <PSMAssociation> associations = Project.TranslateComponentCollection <PSMAssociation>(Associations);

            Commands.Add(new acmdNewPSMContentModel(Controller, Type, parent.PSMSchema)
            {
                ContentModelGuid = ContentModelGuid
            });
            Commands.Add(new acmdNewPSMAssociation(Controller, parent, ContentModelGuid, parent.PSMSchema)
            {
                AssociationGuid = AssociationGuid
            });
            Commands.Add(new acmdRenameComponent(Controller, AssociationGuid, ""));
            foreach (PSMAssociation a in associations)
            {
                Commands.Add(new acmdReconnectPSMAssociation(Controller, a, ContentModelGuid));
            }
        }
Ejemplo n.º 11
0
        private void ClassifyNodes(DetectedChangeInstancesSet changeInstances, PSMSchema psmSchema)
        {
            FindRedNodes(changeInstances);

            #region blue and green nodes

            Queue <PSMAssociationMember> toDo = new Queue <PSMAssociationMember>();
            foreach (PSMAssociationMember m in ModelIterator.GetLeaves(psmSchema))
            {
                if (changeInstances.RedNodes.Contains(m))
                {
                    toDo.Enqueue(m);
                }
            }

            foreach (PSMAssociationMember redNode in changeInstances.RedNodes.OfType <PSMAssociationMember>())
            {
                toDo.Enqueue(redNode);
            }

            foreach (PSMAttribute psmAttribute in changeInstances.RedNodes.OfType <PSMAttribute>())
            {
                if (!changeInstances.RedNodes.Contains(psmAttribute.PSMClass))
                {
                    changeInstances.BlueNodes.AddIfNotContained(psmAttribute.PSMClass);
                    toDo.Enqueue(psmAttribute.PSMClass);
                }
            }

            while (!toDo.IsEmpty())
            {
                PSMAssociationMember m = toDo.Dequeue();
                if (m.ParentAssociation != null)
                {
                    if (!changeInstances.RedNodes.Contains(m.ParentAssociation.Parent) &&
                        !changeInstances.BlueNodes.Contains(m.ParentAssociation.Parent))
                    {
                        changeInstances.BlueNodes.Add(m.ParentAssociation.Parent);
                        if (!(m.ParentAssociation.Parent is PSMSchemaClass))
                        {
                            toDo.Enqueue(m.ParentAssociation.Parent);
                        }
                    }
                }
            }

            changeInstances.GreenNodes.AddRange(psmSchema.SchemaComponents.Where(c => !(c is PSMAssociation) && !(c is PSMSchemaClass) &&
                                                                                 !changeInstances.RedNodes.Contains(c) && !changeInstances.BlueNodes.Contains(c)).Cast <PSMComponent>());

            foreach (PSMComponent psmComponent in changeInstances.AllNodes)
            {
                if (!psmComponent.ExistsInVersion(changeInstances.OldVersion))
                {
                    changeInstances.AddedNodes.Add(psmComponent);
                }
            }

            #endregion
        }
Ejemplo n.º 12
0
        public override void Execute(object parameter)
        {
            PSMAssociationMember associationMember            = Current.ActiveDiagramView.GetSingleSelectedComponentOrNull() as PSMAssociationMember;
            cmdLeaveOutUninterpretedAssociationMember command = new cmdLeaveOutUninterpretedAssociationMember(Current.Controller);

            command.Set(associationMember);
            command.Execute();
        }
Ejemplo n.º 13
0
        internal override void GenerateSubCommands()
        {
            PSMAssociationMember psmAssociationMember = Project.TranslateComponent <PSMAssociationMember>(AssociationMemberGuid);

            if (psmAssociationMember.ParentAssociation != null)
            {
                foreach (PSMAssociation a in psmAssociationMember.ChildPSMAssociations)
                {
                    Commands.Add(new acmdReconnectPSMAssociation(Controller, a, psmAssociationMember.ParentAssociation.Parent));
                }
                if (psmAssociationMember is PSMClass)
                {
                    PSMClass parent = psmAssociationMember.NearestParentClass();
                    if (parent == null)
                    {
                        foreach (PSMAttribute a in (psmAssociationMember as PSMClass).PSMAttributes)
                        {
                            Commands.Add(new cmdDeletePSMAttribute(Controller)
                            {
                                AttributeGuid = a
                            });
                        }
                    }
                    else
                    {
                        foreach (PSMAttribute a in (psmAssociationMember as PSMClass).PSMAttributes)
                        {
                            Commands.Add(new acmdMovePSMAttribute(Controller, a, parent));
                        }
                    }
                }
                Commands.Add(new cmdDeletePSMAssociation(Controller)
                {
                    AssociationGuid = psmAssociationMember.ParentAssociation
                });
            }
            if (psmAssociationMember is PSMClass)
            {
                Commands.Add(new cmdDeleteRootPSMClass(Controller)
                {
                    ClassGuid = psmAssociationMember
                });
            }
            else if (psmAssociationMember is PSMContentModel)
            {
                Commands.Add(new cmdDeleteRootPSMContentModel(Controller)
                {
                    ContentModelGuid = psmAssociationMember
                });
            }
            else
            {
                Debug.Assert(false, "Unknown Association Member Type");
            }
        }
Ejemplo n.º 14
0
        public override bool CanExecute()
        {
            if (!(schemaGuid != Guid.Empty &&
                  Project.VerifyComponentType <PSMSchema>(schemaGuid) &&
                  associationGuid != Guid.Empty &&
                  Project.VerifyComponentType <PSMAssociation>(associationGuid)))
            {
                ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH;
                return(false);
            }

            PSMAssociation a = Project.TranslateComponent <PSMAssociation>(associationGuid);

            if (a.Interpretation != null)
            {
                return(true);
            }

            if (a.Child != null && a.Child is PSMClass && (a.Child as PSMClass).Interpretation != null)
            {
                return(true);
            }

            PSMAssociationMember c = a.Child; //Uninterpreted child

            IEnumerable <PSMClass> unInterpretedSubClasses = c.UnInterpretedSubClasses(true);

            //PSM attributes within the uninterpreted PSM Class subtree cannot have interpretations
            if (!unInterpretedSubClasses
                .SelectMany <PSMClass, PSMAttribute>(cl => cl.PSMAttributes)
                .All <PSMAttribute>(at => at.Interpretation == null)
                )
            {
                ErrorDescription = CommandErrors.CMDERR_UNINTERPRETED_SUBCLASS_ATTRIBUTES_INTERPRETED;
                return(false);
            }

            //PSM associations within the uninterpreted PSM Class subtree cannot have interpretations
            if (!unInterpretedSubClasses
                .Select <PSMClass, PSMAssociation>(cl => cl.ParentAssociation)
                .All <PSMAssociation>(assoc => assoc.Interpretation == null)
                )
            {
                ErrorDescription = CommandErrors.CMDERR_UNINTERPRETED_SUBCLASS_ASSOCIATIONS_INTERPRETED;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Translates the association child.
 /// </summary>
 /// <param name="associationChild">The association child.</param>
 /// <param name="context">The translation context.</param>
 protected virtual void TranslateAssociationChild(PSMAssociationMember associationChild, TContext context)
 {
     if (associationChild is PSMSchemaClass)
     {
         TranslateSchemaClass((PSMSchemaClass)associationChild, context);
     }
     else if (associationChild is PSMClass)
     {
         TranslateClass((PSMClass)associationChild, context);
     }
     else if (associationChild is PSMContentModel)
     {
         TranslateContentModel((PSMContentModel)associationChild, context);
     }
 }
Ejemplo n.º 16
0
        public override bool CanExecute()
        {
            if (ParentAssociationMemberGuid == Guid.Empty || Associations == null)
            {
                return(false);
            }
            PSMAssociationMember         parent       = Project.TranslateComponent <PSMAssociationMember>(ParentAssociationMemberGuid);
            IEnumerable <PSMAssociation> associations = Project.TranslateComponentCollection <PSMAssociation>(Associations);

            if (associations.Any(a => a.Parent != parent))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 17
0
 public TResult ProcessPSMAssociationMember(PSMAssociationMember psmAssociationMember)
 {
     if (psmAssociationMember is PSMClass)
     {
         return(ProcessPSMClass((PSMClass)psmAssociationMember));
     }
     if (psmAssociationMember is PSMContentModel)
     {
         return(ProcessPSMContentModel((PSMContentModel)psmAssociationMember));
     }
     if (psmAssociationMember is PSMSchemaClass)
     {
         return(ProcessPSMSchemaClass((PSMSchemaClass)psmAssociationMember));
     }
     throw new ArgumentOutOfRangeException("psmAssociationMember", "Unknown component type.");
 }
Ejemplo n.º 18
0
        private EvoX.Model.PSM.PSMAssociation CreateLeadingAssociation(PSMSubordinateComponent subordinate, PSMAssociationMember childAssociationMember)
        {
            if (!(subordinate.Parent is PSMAssociation))
            {
                PSMAssociationMember          parent         = (PSMAssociationMember)translatedElements[subordinate.Parent];
                EvoX.Model.PSM.PSMAssociation psmAssociation = new EvoX.Model.PSM.PSMAssociation(
                    evoxProject, parent, childAssociationMember, psmSchema);
                psmAssociation.Name = null;
                associationOrder[psmAssociation] = subordinate.ComponentIndex();
                return(psmAssociation);
            }

            else
            {
                return(null);
            }
        }
Ejemplo n.º 19
0
        internal override void CommandOperation()
        {
            PSMAssociation       psmAssociation = Project.TranslateComponent <PSMAssociation>(associationGuid);
            PSMAssociationMember oldParent      = psmAssociation.Parent as PSMAssociationMember;

            oldParentGuid = oldParent;
            PSMAssociationMember newParent = Project.TranslateComponent <PSMAssociationMember>(newParentGuid);

            index = oldParent.ChildPSMAssociations.IndexOf(psmAssociation);
            oldParent.ChildPSMAssociations.Remove(psmAssociation);
            if (oldParent.PSMSchema != newParent.PSMSchema)
            {
                schemaIndexes = new List <Tuple <Guid, int> >();
                foreach (PSMComponent c in psmAssociation.GetPSMChildComponentsRecursive(true, true))
                {
                    if (c is PSMClass)
                    {
                        schemaIndexes.Add(Tuple.Create <Guid, int>(c, oldParent.PSMSchema.PSMClasses.Remove(c as PSMClass)));
                        newParent.PSMSchema.PSMClasses.Add(c as PSMClass);
                    }
                    else if (c is PSMAssociation)
                    {
                        schemaIndexes.Add(Tuple.Create <Guid, int>(c, oldParent.PSMSchema.PSMAssociations.Remove(c as PSMAssociation)));
                        newParent.PSMSchema.PSMAssociations.Add(c as PSMAssociation);
                    }
                    else if (c is PSMContentModel)
                    {
                        schemaIndexes.Add(Tuple.Create <Guid, int>(c, oldParent.PSMSchema.PSMContentModels.Remove(c as PSMContentModel)));
                        newParent.PSMSchema.PSMContentModels.Add(c as PSMContentModel);
                    }
                    else if (c is PSMAttribute)
                    {
                        schemaIndexes.Add(Tuple.Create <Guid, int>(c, oldParent.PSMSchema.PSMAttributes.Remove(c as PSMAttribute)));
                        newParent.PSMSchema.PSMAttributes.Add(c as PSMAttribute);
                    }
                    else
                    {
                        Debug.Assert(false, "Unknown type");
                    }
                }
            }
            psmAssociation.Parent = newParent;
            newParent.ChildPSMAssociations.Add(psmAssociation);

            Report = new CommandReport(CommandReports.MOVE_PSM_ASSOCIATION, psmAssociation, oldParent, newParent);
        }
Ejemplo n.º 20
0
        internal override CommandBase.OperationResult UndoOperation()
        {
            PSMAssociationMember root = Project.TranslateComponent <PSMAssociationMember>(associationMemberGuid);
            int index = root.PSMSchema.Roots.IndexOf(root);
            int count = root.PSMSchema.Roots.Count;

            if (left)
            {
                index = (index + 1) % count;
            }
            else
            {
                index = (index - 1) % count;
            }
            root.PSMSchema.Roots.Remove(root);
            root.PSMSchema.Roots.Insert(root, index);
            return(OperationResult.OK);
        }
Ejemplo n.º 21
0
        private EvoX.Model.PSM.PSMAssociation CreateLeadingAssociationForUnionComponents(PSMAssociationChild associationChild, PSMAssociationMember childAssociationMember)
        {
            PSMAssociationMember parent = (PSMAssociationMember)translatedElements[associationChild.ParentUnion];

            EvoX.Model.PSM.PSMAssociation psmAssociation = new EvoX.Model.PSM.PSMAssociation(
                evoxProject, parent, childAssociationMember, psmSchema);
            PSMClass psmClass = associationChild as PSMClass;

            if (psmClass != null && psmClass.HasElementLabel)
            {
                psmAssociation.Name = psmClass.ElementName;
            }
            else
            {
                psmAssociation.Name = null;
            }
            associationOrder[psmAssociation] = associationChild.ComponentIndex();
            return(psmAssociation);
        }
Ejemplo n.º 22
0
        private static void CheckPSMAssociationMember(PSMAssociationMember psmAssociationMember)
        {
            CheckPSMComponent(psmAssociationMember);
            Assert.IsTrue(psmAssociationMember.ParentAssociation == null || !psmAssociationMember.PSMSchema.Roots.Contains(psmAssociationMember));
            Assert.IsFalse(psmAssociationMember.ParentAssociation == null && !psmAssociationMember.PSMSchema.Roots.Contains(psmAssociationMember));
            if (psmAssociationMember.ParentAssociation != null)
            {
                Assert.IsTrue(psmAssociationMember.ParentAssociation.Child == psmAssociationMember);
            }
            foreach (PSMAssociation childPsmAssociation in psmAssociationMember.ChildPSMAssociations)
            {
                Assert.IsTrue(childPsmAssociation.Parent == psmAssociationMember);
            }

            foreach (PSMAssociation childPsmAssociation in psmAssociationMember.ChildPSMAssociations)
            {
                CollectionAssert.Contains(psmAssociationMember.Schema.SchemaComponents, childPsmAssociation);
            }
        }
Ejemplo n.º 23
0
        internal override void CommandOperation()
        {
            PSMAssociationMember root = Project.TranslateComponent <PSMAssociationMember>(associationMemberGuid);
            int index = root.PSMSchema.Roots.IndexOf(root);
            int count = root.PSMSchema.Roots.Count;

            if (left)
            {
                index = (index + count - 1) % count;
            }
            else
            {
                index = (index + 1) % count;
            }
            root.PSMSchema.Roots.Remove(root);
            root.PSMSchema.Roots.Insert(root, index);

            Report = new CommandReport(CommandReports.SHIFT_PSM_ROOT, root, left ? "left" : "right");
        }
Ejemplo n.º 24
0
        internal override CommandBase.OperationResult UndoOperation()
        {
            PSMAssociation       a      = Project.TranslateComponent <PSMAssociation>(associationGuid);
            PSMAssociationMember parent = a.Parent;
            int index = parent.ChildPSMAssociations.IndexOf(a);
            int count = parent.ChildPSMAssociations.Count;

            if (left)
            {
                index = (index + 1) % count;
            }
            else
            {
                index = (index - 1) % count;
            }
            parent.ChildPSMAssociations.Remove(a);
            parent.ChildPSMAssociations.Insert(a, index);
            return(OperationResult.OK);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Draws all children of given root element and counts width of its subtree.
        /// </summary>
        /// <param name="psmDiagramView">Diagram to be layouted</param>
        /// <param name="root">Root element of layouted subtree</param>
        /// <param name="top">Location of the upper border of the root's children</param>
        /// <param name="left">Location of the left border of the entire subtree</param>
        /// <returns>Width of the subtree (root not included)</returns>
        protected virtual double DrawSubtree(PSMDiagramView psmDiagramView, PSMComponent root, double top, double left)
        {
            double right = left;

            if (root is PSMAssociationMember)
            {
                ComponentViewBase componentView = psmDiagramView.RepresentantsCollection[root];
                if (componentView is IComponentViewBaseVH && ((IComponentViewBaseVH)componentView).ViewHelper is IFoldableComponentViewHelper)
                {
                    if (((IFoldableComponentViewHelper)((IComponentViewBaseVH)componentView).ViewHelper).IsFolded)
                    {
                        return(right - left);
                    }
                }

                PSMAssociationMember rootAM = (PSMAssociationMember)root;
                if (rootAM.ChildPSMAssociations.Count > 0)
                {
                    foreach (PSMAssociation childAssociation in rootAM.ChildPSMAssociations)
                    {
                        if (childAssociation.Child.ParentAssociation != childAssociation)
                        {
                            continue;
                        }
                        right += DrawTree(psmDiagramView, (childAssociation).Child, top, right) + horizontalSpace;
                    }
                    if (rootAM is PSMClass)
                    {
                        foreach (PSMGeneralization generalization in (rootAM as PSMClass).GeneralizationsAsGeneral)
                        {
                            right += DrawTree(psmDiagramView, (generalization).Specific, top, right) + horizontalSpace;
                        }
                    }
                }
                if (right != left)
                {
                    right -= horizontalSpace;
                }
            }

            return(right - left);
        }
Ejemplo n.º 26
0
        internal override CommandBase.OperationResult UndoOperation()
        {
            PSMAssociation       psmAssociation = Project.TranslateComponent <PSMAssociation>(associationGuid);
            PSMAssociationMember oldParent      = Project.TranslateComponent <PSMAssociationMember>(oldParentGuid);
            PSMAssociationMember newParent      = Project.TranslateComponent <PSMAssociationMember>(newParentGuid);

            newParent.ChildPSMAssociations.Remove(psmAssociation);
            if (oldParent.PSMSchema != newParent.PSMSchema)
            {
                foreach (Tuple <Guid, int> t in schemaIndexes.Reverse <Tuple <Guid, int> >())
                {
                    PSMComponent c = Project.TranslateComponent <PSMComponent>(t.Item1);
                    if (c is PSMClass)
                    {
                        newParent.PSMSchema.PSMClasses.Remove(c as PSMClass);
                        oldParent.PSMSchema.PSMClasses.Insert(c as PSMClass, t.Item2);
                    }
                    else if (c is PSMAssociation)
                    {
                        newParent.PSMSchema.PSMAssociations.Remove(c as PSMAssociation);
                        oldParent.PSMSchema.PSMAssociations.Insert(c as PSMAssociation, t.Item2);
                    }
                    else if (c is PSMContentModel)
                    {
                        newParent.PSMSchema.PSMContentModels.Remove(c as PSMContentModel);
                        oldParent.PSMSchema.PSMContentModels.Insert(c as PSMContentModel, t.Item2);
                    }
                    else if (c is PSMAttribute)
                    {
                        newParent.PSMSchema.PSMAttributes.Remove(c as PSMAttribute);
                        oldParent.PSMSchema.PSMAttributes.Insert(c as PSMAttribute, t.Item2);
                    }
                    else
                    {
                        Debug.Assert(false, "Unknown type");
                    }
                }
            }
            psmAssociation.Parent = oldParent;
            oldParent.ChildPSMAssociations.Insert(psmAssociation, index);
            return(OperationResult.OK);
        }
Ejemplo n.º 27
0
        internal override void CommandOperation()
        {
            PSMAssociation       a      = Project.TranslateComponent <PSMAssociation>(associationGuid);
            PSMAssociationMember parent = a.Parent;
            int index = parent.ChildPSMAssociations.IndexOf(a);
            int count = parent.ChildPSMAssociations.Count;

            if (left)
            {
                index = (index + count - 1) % count;
            }
            else
            {
                index = (index + 1) % count;
            }
            parent.ChildPSMAssociations.Remove(a);
            parent.ChildPSMAssociations.Insert(a, index);

            Report = new CommandReport(CommandReports.PSM_ASSOC_SHIFT, a, left ? "left" : "right");
        }
Ejemplo n.º 28
0
        public override bool CanExecute()
        {
            PSMAssociation       association = Project.TranslateComponent <PSMAssociation>(AssociationGuid);
            PSMAssociationMember target      = Project.TranslateComponent <PSMAssociationMember>(NewParentGuid);
            PSMAssociationMember source      = association.Parent;

            if ((target is PSMClass) && (source is PSMClass) &&
                ((target as PSMClass).RepresentedClass == source ||
                 (source as PSMClass).RepresentedClass == target))
            {
                return(true);
            }

            if (source.GetNearestCommonAncestorAssociationMember(target) == null)
            {
                ErrorDescription = CommandErrors.CMDERR_NO_COMMON_ANCESTOR_ASSOC_MEMBER;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 29
0
        public override bool CanExecute()
        {
            if (parentGuid == Guid.Empty || childGuid == Guid.Empty || schemaGuid == Guid.Empty)
            {
                return(false);
            }
            if (!Project.VerifyComponentType <PSMAssociationMember>(parentGuid) ||
                !Project.VerifyComponentType <PSMAssociationMember>(childGuid) ||
                !Project.VerifyComponentType <PSMSchema>(schemaGuid))
            {
                return(false);
            }
            PSMAssociationMember parent = Project.TranslateComponent <PSMAssociationMember>(parentGuid);
            PSMAssociationMember child  = Project.TranslateComponent <PSMAssociationMember>(childGuid);

            if (parent.ID == child.ID)
            {
                ErrorDescription = CommandErrors.CMDERR_RECURSIVE_ASSOCIATION;
                return(false);
            }

            if (child.ParentAssociation != null)
            {
                ErrorDescription = CommandErrors.CMDERR_PARENT_ASSOCIATION_EXISTS;
                return(false);
            }

            /*if (child.Interpretation != null)
             * {
             *  if (parent is PSMClass)
             *  {
             *      if ((parent as PSMClass).NearestInterpretedClass() != null) return false;
             *  }
             *  else if (parent.NearestInterpretedParentClass() != null)
             *  {
             *      return false;
             *  }
             * }*/

            return(true);
        }
Ejemplo n.º 30
0
        internal override CommandBase.OperationResult UndoOperation()
        {
            if (childGuid != Guid.Empty)
            {
                PSMAssociationMember child = Project.TranslateComponent <PSMAssociationMember>(childGuid);
                child.PSMSchema.Roots.Remove(child);
            }
            new PSMAssociation(
                Project,
                associationGuid,
                parentGuid == Guid.Empty ? null : Project.TranslateComponent <PSMAssociationMember>(parentGuid),
                childGuid == Guid.Empty ? null : Project.TranslateComponent <PSMAssociationMember>(childGuid),
                index,
                Project.TranslateComponent <PSMSchema>(schemaGuid), setChildParentAssociation: !isNonTreeAssociation
                )
            {
                Interpretation = interpretation == Guid.Empty ? null : Project.TranslateComponent <PIMComponent>(interpretation)
            };

            return(OperationResult.OK);
        }