private void RemoveComponentRepresentation(PSMSubordinateComponent component)
        {
            ComponentData data = ComponentsData[component];

            ComponentsData.Remove(component);
            XCaseCanavs.Children.Remove(data.Connector.Junction);
        }
Exemple #2
0
        protected override void TranslateContentChoice(PSMContentChoice contentChoice, DataGeneratorContext context)
        {
            TranslateComments(contentChoice, context);
            PSMSubordinateComponent selectedPath = contentChoice.Components.ChooseOneRandomly();

            TranslateSubordinateComponent(selectedPath, context);
        }
        private void AddComponentRepresentation(PSMSubordinateComponent component)
        {
            IModelElementRepresentant componentRepresentant = null;
            IConnectable           connectedChild           = null;
            PSM_ComponentConnector connector = null;

            if (component is PSMAssociation)
            {
                connectedChild = (IConnectable)((PSMAssociation)component).Child;
                ComponentConnectorViewHelper viewHelper = ((PSMElementViewHelper)((PSMElementViewBase)connectedChild).ViewHelper).ConnectorViewHelper;
                connector = new PSM_ComponentConnector(XCaseCanavs, SuperordinateRepresentation, connectedChild, viewHelper);
            }
            else
            {
                componentRepresentant = XCaseCanavs.ElementRepresentations[component];
                connectedChild        = (IConnectable)componentRepresentant;
                ComponentConnectorViewHelper viewHelper = ((PSMElementViewHelper)((PSMElementViewBase)connectedChild).ViewHelper).ConnectorViewHelper;
                connector = new PSM_ComponentConnector(XCaseCanavs, SuperordinateRepresentation, connectedChild, viewHelper);
            }

            ComponentData data = new ComponentData()
            {
                ComponentRepresentant = componentRepresentant,
                ConnectedChild        = connectedChild,
                Connector             = connector
            };

            ComponentsData[component] = data;
        }
Exemple #4
0
        public static void CheckPsmParentsAndRoots(PSMDiagram diagram)
        {
            foreach (Element element in diagram.DiagramElements.Keys)
            {
                PSMSubordinateComponent subordinateComponent = (element as PSMSubordinateComponent);
                if (subordinateComponent != null)
                {
                    if (subordinateComponent.Parent == null && !diagram.Roots.Contains((PSMClass)subordinateComponent))
                    {
                        throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent));
                    }
                    if (subordinateComponent.Parent != null)
                    {
                        if (!subordinateComponent.Parent.Components.Contains(subordinateComponent))
                        {
                            throw new ModelConsistencyException(string.Format("Bad subordinate component {0}", subordinateComponent));
                        }
                    }
                }

                PSMSuperordinateComponent superordinateComponent = element as PSMSuperordinateComponent;

                if (superordinateComponent != null)
                {
                    foreach (PSMSubordinateComponent component in superordinateComponent.Components)
                    {
                        if (component.Parent != superordinateComponent)
                        {
                            throw new ModelConsistencyException(string.Format("Bad superordinateComponent component {0}", superordinateComponent));
                        }
                    }
                }
            }
        }
Exemple #5
0
        //public new virtual Element Clone(Model targetModel, IDictionary<Element, Element> createdCopies)
        //{
        //    PIMClass cRepresentedClass;
        //    if (targetModel == this.Schema.Model)
        //    {
        //        cRepresentedClass = this.RepresentedClass;
        //    }
        //    else
        //    {
        //        cRepresentedClass = (PIMClass) createdCopies[this.RepresentedClass];
        //    }

        //    PSMClass copy = cRepresentedClass.DerivePSMClass();

        //    return copy;
        //}

        //public Element CreateCopy(Model targetModel, IDictionary<Element, Element> createdCopies, IList<Element> source)
        //{
        //    PSMClass element = (PSMClass) base.CreateCopy(targetModel, createdCopies, source);


        //    return element;
        //}

        #endregion

        #endregion

        #region PSMSuperordinateComponent Members

        public PSMSubordinateComponent AddComponent(PSMSubordinateComponentFactory factory)
        {
            PSMSubordinateComponent component = factory.Create(this, Schema);

            components.Add(component);

            return(component);
        }
Exemple #6
0
        public PSMSubordinateComponent AddComponent(PSMSubordinateComponentFactory factory, int index)
        {
            PSMSubordinateComponent component = factory.Create(this, Schema);

            components.Insert(index, component);

            return(component);
        }
Exemple #7
0
        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (format == null)
            {
                format = "R";
            }

            if (formatProvider != null)
            {
                ICustomFormatter formatter = formatProvider.GetFormat(
                    this.GetType())
                                             as ICustomFormatter;

                if (formatter != null)
                {
                    return(formatter.Format(format, this, formatProvider));
                }
            }

            string normal = this.ToString();

            if (this.HasElementLabel)
            {
                normal += string.Format(" - '{0}'", ElementName);
            }

            switch (format)
            {
            case "r":
            case "R":
                PSMSubordinateComponent as_subordinate = this as PSMSubordinateComponent;
                if (as_subordinate != null)
                {
                    if (as_subordinate.Parent.Components.Count == 1)
                    {
                        return(string.Format("{0} in {1:f}", normal, as_subordinate.Parent));
                    }
                    else
                    {
                        return(string.Format("{0} in {1:f} (Component index: {2})", normal, as_subordinate.Parent, as_subordinate.Parent.Components.IndexOf(as_subordinate)));
                    }
                }
                else
                {
                    return(normal);
                }

            case "f":
            case "F":
                return(normal);

            default: return(base.ToString());
            }
        }
        public override void Execute(object parameter)
        {
            MoveComponentOutOfContainerCommand command =
                (MoveComponentOutOfContainerCommand)
                MoveComponentOutOfContainerCommandFactory.Factory().Create(ActiveDiagramView.Controller);

            PSMSubordinateComponent sub = (PSMSubordinateComponent)ActiveDiagramView.ElementRepresentations.GetElementRepresentedBy(ActiveDiagramView.SelectedRepresentants.First());

            command.Container = sub.Parent;
            command.MovedComponents.Add(sub);
            command.Execute();
        }
        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (format == null)
            {
                format = "R";
            }

            if (formatProvider != null)
            {
                ICustomFormatter formatter = formatProvider.GetFormat(
                    this.GetType())
                                             as ICustomFormatter;

                if (formatter != null)
                {
                    return(formatter.Format(format, this, formatProvider));
                }
            }

            string normal = ElementName;

            switch (format)
            {
            case "r":
            case "R":
                PSMSubordinateComponent as_subordinate = this as PSMSubordinateComponent;
                if (as_subordinate != null)
                {
                    System.Diagnostics.Debug.Assert(as_subordinate.Parent != null);
                    if (as_subordinate.Parent != null)
                    {
                        if (as_subordinate.Parent.Components.Count == 1)
                        {
                            return(string.Format("{0} in {1:f}", normal, as_subordinate.Parent));
                        }
                        else
                        {
                            return(string.Format("{0} in {1:f} (Component index: {2})", normal, as_subordinate.Parent,
                                                 as_subordinate.Parent.Components.IndexOf(as_subordinate)));
                        }
                    }
                }
                return(normal);

            case "f":
            case "F":
                return(normal);

            default: return(base.ToString());
            }
        }
Exemple #10
0
        internal static Element GetComponentAndCollection(ISelectable selectedItem, PSMDiagram diagram, out IList <PSMSuperordinateComponent> rootsCollection, out IList <PSMAssociationChild> associationChildCollection, out IList <PSMSubordinateComponent> subordinateComponentCollection)
        {
            rootsCollection                = null;
            associationChildCollection     = null;
            subordinateComponentCollection = null;

            if (selectedItem is IPSMSubordinateComponentRepresentant)
            {
                PSMSubordinateComponent subordinateComponent = ((IPSMSubordinateComponentRepresentant)selectedItem).ModelSubordinateComponent;
                if (subordinateComponent.Parent != null)
                {
                    subordinateComponentCollection = subordinateComponent.Parent.Components;
                    return(subordinateComponent);
                }
            }

            PSMAssociationChild associationChild = null;

            if (selectedItem is PSM_Class)
            {
                associationChild = ((PSM_Class)selectedItem).PSMClass;
                PSMClass psmClass = (PSMClass)associationChild;

                if (diagram.Roots.Contains(psmClass))
                {
                    rootsCollection = diagram.Roots;
                    return(psmClass);
                }
            }
            if (selectedItem is PSM_ClassUnion)
            {
                associationChild = ((PSM_ClassUnion)selectedItem).ClassUnion;
            }

            if (associationChild != null)
            {
                if (associationChild.ParentAssociation != null && associationChild.ParentAssociation.Parent != null)
                {
                    subordinateComponentCollection = associationChild.ParentAssociation.Parent.Components;
                    return(associationChild.ParentAssociation);
                }
                else if (associationChild.ParentUnion != null)
                {
                    associationChildCollection = associationChild.ParentUnion.Components;
                    return(associationChild);
                }
            }

            return(null);
        }
Exemple #11
0
        public static Element GetRightSiblingOfElement(Element element)
        {
            PSMSubordinateComponent subordinateComponent = element as PSMSubordinateComponent;

            if (subordinateComponent != null)
            {
                PSMSuperordinateComponent parent = subordinateComponent.Parent;
                if (parent != null)
                {
                    ObservableCollection <PSMSubordinateComponent> components = parent.Components;
                    if (components.IndexOf(subordinateComponent) < components.Count - 1)
                    {
                        return(components[components.IndexOf(subordinateComponent) + 1]);
                    }
                    else if (parent is PSMClass)
                    {
                        PSMClass parentClass = parent as PSMClass;
                        if (parentClass.Specifications.Count > 0)
                        {
                            return(parentClass.Specifications.First());
                        }
                    }
                }
            }

            Generalization generalization = element as Generalization;

            if (generalization != null)
            {
                IList <Generalization> specifications = generalization.General.Specifications;
                if (specifications.IndexOf(generalization) != specifications.Count - 1)
                {
                    return(specifications[specifications.IndexOf(generalization) + 1]);
                }
            }

            PSMClass psmClass = element as PSMClass;

            if (psmClass != null && psmClass.ParentUnion != null)
            {
                ObservableCollection <PSMAssociationChild> components = psmClass.ParentUnion.Components;
                if (components.IndexOf(psmClass) < components.Count - 1)
                {
                    return(components[components.IndexOf(psmClass) + 1]);
                }
            }

            return(null);
        }
Exemple #12
0
		/// <summary>
		/// Checks whether <paramref name="items"/> are all children of a common parent, that is a <see cref="PSMSuperordinateComponent"/> and all
		/// items are <see cref="PSMSubordinateComponent"/>s. 
		/// </summary>
		/// <param name="items">list of selectable items</param>
		/// <param name="parent">common parent for <paramref name="items"/> (if found)</param>
		/// <param name="components"><see cref="PSMSubordinateComponent"/>s that are represented by <paramref name="items"/></param>
		/// <returns>true if <paramref name="items"/> are all components of a common parent, false otherwise</returns>
		public static bool AreComponentsOfCommonParent(IEnumerable<IModelElementRepresentant> items, out PSMSuperordinateComponent parent, out IList<PSMSubordinateComponent> components)
		{
			parent = null;
			List<PSMSubordinateComponent> result = new List<PSMSubordinateComponent>();
			components = null;
			foreach (IModelElementRepresentant item in items)
			{
				if (!(item is IPSMSubordinateComponentRepresentant) && !(item is Controls.PSM_Class))
				{
					return false;
				}
				else
				{
					PSMSubordinateComponent component = null;
					if (item is Controls.PSM_Class)
					{
						PSMAssociationChild associationChild = (item as Controls.PSM_Class).ClassController.Class;
						if (associationChild != null && associationChild.ParentAssociation != null)
							component = associationChild.ParentAssociation;
					}
					else
					{
						component = ((IPSMSubordinateComponentRepresentant)item).ModelSubordinateComponent;
					}
					if (component == null)
					{
						return false;
					}

					
					PSMSuperordinateComponent itemParent = component.Parent;
					if (parent == null)
						parent = itemParent;
					else
					{
						if (parent != itemParent)
						{
							return false;
						}
					}

					if (!result.Contains(component))
						result.Add(component);
				}
			}
			components = result;
			return true;
		}
        internal override void CommandOperation()
        {
            if (CreatedContainer == null)
            {
                CreatedContainer = new Helpers.ElementHolder <PSMContentContainer>();
            }

            PSMSubordinateComponent first = Parent.Components.FirstOrDefault(component => containedComponents.Contains(component));
            PSMContentContainer     psmContainer;

            if (Parent != null)
            {
                if (first == null)
                {
                    psmContainer = (PSMContentContainer)Parent.AddComponent(PSMContentContainerFactory.Instance);
                }
                else
                {
                    psmContainer = (PSMContentContainer)Parent.AddComponent(
                        PSMContentContainerFactory.Instance, Parent.Components.IndexOf(first));
                }
            }
            else //add as root
            {
                PSMDiagram          diagram          = (PSMDiagram)Diagram;
                PSMContentContainer contentContainer = (PSMContentContainer)PSMContentContainerFactory.Instance.Create(null, diagram.Project.Schema);
                contentContainer.Diagram = diagram;
                psmContainer             = contentContainer;
                diagram.Roots.Add(psmContainer);
            }
            psmContainer.Name = Name;

            CreatedContainer.Element = psmContainer;

            AssociatedElements.Add(psmContainer);

            foreach (PSMSubordinateComponent containedComponent in containedComponents)
            {
                oldIndexes[containedComponent] = containedComponent.ComponentIndex();
                Parent.Components.Remove(containedComponent);
                psmContainer.Components.Add(containedComponent);
            }

            Debug.Assert(CreatedContainer.HasValue);
            Diagram.AddModelElement(psmContainer, ViewHelper = new PSMElementViewHelper(Diagram));
        }
Exemple #14
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);
            }
        }
        public static IList <EvolutionChange> Detect(Version v1, Version v2, PSMSubordinateComponent subordinateComponent)
        {
            List <EvolutionChange> result = new List <EvolutionChange>();

            PSMSubordinateComponent oldVersion = (PSMSubordinateComponent)subordinateComponent.GetInVersion(v1);
            PSMSubordinateComponent newVersion = (PSMSubordinateComponent)subordinateComponent.GetInVersion(v2);

            if (newVersion != null && oldVersion != null &&
                oldVersion.Parent != newVersion.Parent.GetInVersion(v1))
            {
                result.Add(new SubordinateComponentMovedChange(subordinateComponent)
                {
                    OldVersion = v1, NewVersion = v2
                });
            }

            return(result);
        }
        public static IList <EvolutionChange> Detect(Version v1, Version v2, PSMSubordinateComponent subordinateComponent)
        {
            List <EvolutionChange> result = new List <EvolutionChange>();

            PSMSubordinateComponent subordinateOldVersion = (PSMSubordinateComponent)subordinateComponent.GetInVersion(v1);

            if (subordinateComponent.Parent.GetInVersion(v1) == subordinateOldVersion.Parent &&
                subordinateComponent.ComponentIndex() != subordinateOldVersion.ComponentIndex())
            {
                SubordinateComponentComponentIndexChange change = new SubordinateComponentComponentIndexChange(subordinateComponent)
                {
                    OldVersion = v1, NewVersion = v2
                };
                result.Add(change);
            }

            return(result);
        }
Exemple #17
0
 /// <summary>
 /// Translates the subordinate component.
 /// </summary>
 /// <remarks>If not redefined, the defult implementation calls one of the following according
 /// to the type of the component: <see cref="TranslateContentContainer"/>,
 /// <see cref="TranslateContentChoice"/>, <see cref="TranslateAssociation"/> or
 /// <see cref="TranslateAttributeContainer"/>.
 /// </remarks>
 /// <param name="component">The component.</param>
 /// <param name="context">The translation context.</param>
 protected void TranslateSubordinateComponent(PSMSubordinateComponent component, Context context)
 {
     if (component is PSMContentContainer)
     {
         TranslateContentContainer((PSMContentContainer)component, context);
     }
     else if (component is PSMContentChoice)
     {
         TranslateContentChoice((PSMContentChoice)component, context);
     }
     else if (component is PSMAttributeContainer)
     {
         TranslateAttributeContainer((PSMAttributeContainer)component, context);
     }
     else if (component is PSMAssociation)
     {
         TranslateAssociation((PSMAssociation)component, context);
     }
 }
Exemple #18
0
        public static Element GetLeftSiblingOfElement(Element element)
        {
            PSMSubordinateComponent subordinateComponent = element as PSMSubordinateComponent;

            if (subordinateComponent != null)
            {
                PSMSuperordinateComponent parent = subordinateComponent.Parent;
                if (parent != null && parent.Components.IndexOf(subordinateComponent) >= 1)
                {
                    return(parent.Components[parent.Components.IndexOf(subordinateComponent) - 1]);
                }
            }

            PSMClass psmClass = element as PSMClass;

            if (psmClass != null && psmClass.ParentUnion != null)
            {
                if (psmClass.ParentUnion.Components.IndexOf(psmClass) > 0)
                {
                    return(psmClass.ParentUnion.Components[psmClass.ParentUnion.Components.IndexOf(psmClass) - 1]);
                }
            }

            Generalization generalization = element as Generalization;

            if (generalization != null)
            {
                IList <Generalization> specifications = generalization.General.Specifications;
                if (specifications.IndexOf(generalization) == 0)
                {
                    return(((PSMClass)generalization.General).Components.LastOrDefault());
                }
                if (specifications.IndexOf(generalization) > 0)
                {
                    return(specifications[specifications.IndexOf(generalization) - 1]);
                }
            }

            return(null);
        }
Exemple #19
0
        /// <summary>
        /// Gets the root of the PSM tree that contains the given item (if any).
        /// </summary>
        /// <param name="item">Reference to the item being searched</param>
        /// <returns>Reference to the root of the tree that contains item or null if no such exists</returns>
        public static PSMSuperordinateComponent GetRootOf(object item)
        {
            if (item is PSMSubordinateComponent)
            {
                PSMSubordinateComponent comp = item as PSMSubordinateComponent;
                if (comp.Parent == null)
                {
                    return(item as PSMSuperordinateComponent);
                }
                else
                {
                    return(GetRootOf(comp.Parent));
                }
            }

            if (item is PSMAssociationChild)
            {
                PSMAssociationChild child = item as PSMAssociationChild;
                if (child.ParentAssociation != null)
                {
                    return(GetRootOf(child.ParentAssociation));
                }
                if (child.ParentUnion != null)
                {
                    return(GetRootOf(child.ParentUnion));
                }

                return(item as PSMSuperordinateComponent);
            }

            if (item is PSMAttribute)
            {
                return(GetRootOf((item as PSMAttribute).Class));
            }


            return(null);
        }
Exemple #20
0
        internal override void CommandOperation()
        {
            if (CreatedChoice == null)
            {
                CreatedChoice = new Helpers.ElementHolder <PSMContentChoice>();
            }

            PSMSubordinateComponent first = Parent.Components.FirstOrDefault(component => containedComponents.Contains(component));
            PSMContentChoice        psmChoice;

            if (first == null)
            {
                psmChoice =
                    (PSMContentChoice)Parent.AddComponent(PSMContentChoiceFactory.Instance);
            }
            else
            {
                psmChoice =
                    (PSMContentChoice)Parent.AddComponent(PSMContentChoiceFactory.Instance, first.ComponentIndex());
            }

            psmChoice.Name = Name;

            CreatedChoice.Element = psmChoice;

            AssociatedElements.Add(psmChoice);

            foreach (PSMSubordinateComponent containedComponent in containedComponents)
            {
                oldIndexes[containedComponent] = containedComponent.ComponentIndex();
                Parent.Components.Remove(containedComponent);
                psmChoice.Components.Add(containedComponent);
            }

            Debug.Assert(CreatedChoice.HasValue);
            Diagram.AddModelElement(psmChoice, ViewHelper = new PSMElementViewHelper(Diagram));
        }
 public SubordinateComponentComponentIndexChange(PSMSubordinateComponent subordinate) : base(subordinate)
 {
 }
Exemple #22
0
        public PSMElement GetParent()
        {
            PSMElement parent = null;

            {
                PSMClass cl = CurrentNode as PSMClass;
                if (cl != null)
                {
                    if (cl.ParentAssociation != null)
                    {
                        parent = cl.ParentAssociation.Parent;
                        return(parent);
                    }
                    if (cl.ParentUnion != null)
                    {
                        parent = cl.ParentUnion;
                        return(parent);
                    }
                    if (Diagram.Roots.Contains(cl))
                    {
                        return(null);
                    }
                    if (cl.Generalizations.Count > 0)
                    {
                        PSMTreeIterator tmp = new PSMTreeIterator((PSMClass)cl.Generalizations[0].General);
                        return(tmp.GetParent());
                    }
                }
            }

            {
                PSMSubordinateComponent cs = CurrentNode as PSMSubordinateComponent;
                if (cs != null)
                {
                    parent = cs.Parent;
                    return(parent);
                }
            }

            {
                PSMClassUnion cu = CurrentNode as PSMClassUnion;
                if (cu != null)
                {
                    parent = cu.ParentAssociation.Parent;
                    return(parent);
                }
            }

            {
                PSMAttribute ca = CurrentNode as PSMAttribute;
                if (ca != null)
                {
                    if (ca.AttributeContainer != null)
                    {
                        return(ca.AttributeContainer);
                    }
                    else
                    {
                        return(ca.Class);
                    }
                }
            }

            return(parent);
        }
Exemple #23
0
 public static int ComponentIndex(this PSMSubordinateComponent subordinate)
 {
     return(subordinate.Parent.Components.IndexOf(subordinate));
 }
Exemple #24
0
 protected SubordinateChange(PSMSubordinateComponent subordinate)
 {
     Element = subordinate;
 }
        /// <summary>
        /// Sets this command for use.
        /// </summary>
        /// <param name="parent">Reference to the PSM component that is the root of joined associations</param>
        /// <param name="joinedAssociations">List of associations to be joined to one class union</param>
        public void Set(PSMSuperordinateComponent parent, IEnumerable <PSMAssociation> joinedAssociations)
        {
            JoinedAssociations = new List <PSMAssociation>(joinedAssociations);

            PSMSubordinateComponent first = parent.Components.First(assoc => JoinedAssociations.Contains(assoc as PSMAssociation));
            int?index = parent.Components.IndexOf(first);


            if (ParentHolder == null)
            {
                ParentHolder = new Helpers.ElementHolder <PSMSuperordinateComponent>();
            }
            ParentHolder.Element = parent;

            if (CreatedUnion == null)
            {
                CreatedUnion = new Helpers.ElementHolder <PSMClassUnion>();
            }

            if (CreatedAssocChild == null)
            {
                CreatedAssocChild = new Helpers.ElementHolder <PSMAssociationChild>();
            }

            if (CreatedAssociationHolder == null)
            {
                CreatedAssociationHolder = new Helpers.ElementHolder <PSMAssociation>();
            }

            NewPSMClassUnionCommand c1 = NewPSMClassUnionCommandFactory.Factory().Create(Controller) as NewPSMClassUnionCommand;

            c1.CreatedUnion = CreatedUnion;
            c1.Parent       = parent;
            Commands.Add(c1);

            Helpers.HolderConvertorCommand <PSMClassUnion, PSMAssociationChild> cc =
                new Commands.Helpers.HolderConvertorCommand <PSMClassUnion, PSMAssociationChild>(CreatedUnion,
                                                                                                 CreatedAssocChild);
            Commands.Add(cc);

            NewPSMAssociationCommand newAssocCommand = NewPSMAssociationCommandFactory.Factory().Create(Controller.ModelController) as NewPSMAssociationCommand;

            newAssocCommand.Set(ParentHolder, CreatedAssocChild, CreatedAssociationHolder, index);
            Commands.Add(newAssocCommand);

            CopyNestingJoinsCommand copyNJcommand = CopyNestingJoinsCommandFactory.Factory().Create(Controller.ModelController) as CopyNestingJoinsCommand;

            copyNJcommand.Set(CreatedAssociationHolder, JoinedAssociations);
            Commands.Add(copyNJcommand);

            /*GetClassUnionContentCommand c4 = GetClassUnionContentCommandFactory.Factory().Create(Controller.ModelController) as GetClassUnionContentCommand;
             * c4.Set(joinedAssociations, CreatedUnion);
             * Commands.Add(c4);*/

            PutClassesToUnionCommand putCommand = PutClassesToUnionCommandFactory.Factory().Create(Controller.ModelController) as PutClassesToUnionCommand;

            putCommand.Set(joinedAssociations, CreatedUnion);
            Commands.Add(putCommand);

            DeleteFromPSMDiagramCommand delCommand = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;

            delCommand.DeletedElements = new List <Element>(JoinedAssociations.Cast <Element>());
            delCommand.CheckOrdering   = false;
            Commands.Add(delCommand);

            foreach (PSMAssociation assoc in joinedAssociations)
            {
                PSMClassUnion union = assoc.Child as PSMClassUnion;
                if (union != null)
                {
                    MoveClassUnionContentCommand moveCommand = MoveClassUnionContentCommandFactory.Factory().Create(Controller) as MoveClassUnionContentCommand;
                    moveCommand.Set(union, CreatedUnion);
                    Commands.Add(moveCommand);
                    DeleteFromPSMDiagramCommand delUnion = DeleteFromPSMDiagramCommandFactory.Factory().Create(Controller) as DeleteFromPSMDiagramCommand;
                    delUnion.DeletedElements = new List <Element>();
                    delUnion.DeletedElements.Add(union);
                    Commands.Add(delUnion);
                }
            }

            ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper> includeAssociation = (ElementToDiagramCommand <PSMAssociation, PSMAssociationViewHelper>) ElementToDiagramCommandFactory <PSMAssociation, PSMAssociationViewHelper> .Factory().Create(Controller);

            includeAssociation.IncludedElement = CreatedAssociationHolder;
            Commands.Add(includeAssociation);
        }
 public SubordinateComponentMovedChange(PSMSubordinateComponent subordinate)
     : base(subordinate)
 {
 }
Exemple #27
0
        /// <summary>
        /// Returns the elements of subtrees of roots in an order in which they can be
        /// added to a PSM diagram.
        /// </summary>
        /// <param name="roots">The roots.</param>
        /// <param name="ordered">The ordered.</param>
        /// <param name="addMetElements">if set to <c>true</c> method adds any elements met
        /// during the execution (subelements of the elements in <paramref name="roots"/>).</param>
        /// <returns></returns>
        public static bool ReturnElementsInPSMOrder(IEnumerable <Element> roots, out IList <Element> ordered, bool addMetElements)
        {
            /* PSM diagram elements must be loaded from root to leaves,
             * following code is BFS implementation */
            Queue <Element> elementsToDo     = new Queue <Element>();
            List <Element>  alreadyProcessed = new List <Element>();
            List <Element>  delayedElements  = new List <Element>();

            List <Element> _roots = roots.ToList();

            _roots.Sort(CompareByRootPositionsDesc);
            foreach (Element root in _roots)
            {
                elementsToDo.Enqueue(root);
            }

            List <Element> needed = new List <Element>();

            while (elementsToDo.Count > 0)
            {
                Element node = elementsToDo.Dequeue();
                if (!alreadyProcessed.Contains(node))
                {
                    if (node is PSMSuperordinateComponent)
                    {
                        foreach (PSMSubordinateComponent component in ((PSMSuperordinateComponent)node).Components.Where(i => !alreadyProcessed.Contains(i) && !elementsToDo.Contains(i)))
                        {
                            elementsToDo.Enqueue(component);
                        }
                    }

                    if (node is PSMClassUnion)
                    {
                        foreach (PSMAssociationChild component in ((PSMClassUnion)node).Components.Where(i => !alreadyProcessed.Contains(i) && !elementsToDo.Contains(i)))
                        {
                            elementsToDo.Enqueue(component);
                        }
                    }

                    PSMClass psmClass = node as PSMClass;

                    if (psmClass != null)
                    {
                        foreach (Generalization specification in psmClass.Specifications.Where(i => !alreadyProcessed.Contains(i) && !elementsToDo.Contains(i)))
                        {
                            elementsToDo.Enqueue(specification);
                        }
                    }

                    PSMAssociation a = node as PSMAssociation;
                    Generalization g = node as Generalization;

                    PSMSubordinateComponent sub   = node as PSMSubordinateComponent;
                    PSMAssociationChild     child = node as PSMAssociationChild;

                    /*
                     * association can be loaded only after the child is already loaded too.
                     * otherwise it is postponed,
                     *
                     * generalizations can be loaded after both
                     * general and specific class are loaded
                     *
                     * component can be loaded after parent is loaded
                     */
                    needed.Clear();
                    if (a != null)
                    {
                        if (elementsToDo.Contains(a.Parent))
                        {
                            needed.Add(a.Parent);
                        }
                        needed.Add(a.Child);
                    }
                    if (g != null)
                    {
                        if (elementsToDo.Contains(g.General))
                        {
                            needed.Add(g.General);
                        }
                        needed.Add(g.Specific);
                    }
                    if (sub != null)
                    {
                        if (elementsToDo.Contains(sub.Parent))
                        {
                            needed.Add(sub.Parent);
                        }
                        //IList<PSMSubordinateComponent> components = sub.Parent.Components;
                        //int index = components.IndexOf(sub);
                        //needed.AddRange(components.Where(component => components.IndexOf(component) < index).Cast<Element>());
                    }
                    if (child != null && child.ParentUnion != null)
                    {
                        if (elementsToDo.Contains(child.ParentUnion))
                        {
                            needed.Add(child.ParentUnion);
                        }
                        //IList<PSMAssociationChild> components = child.ParentUnion.Components;
                        //int index = components.IndexOf(child);
                        //needed.AddRange(components.Where(component => components.IndexOf(component) < index).Cast<Element>());
                    }
                    //if (child != null && child.ParentAssociation != null)
                    //{
                    //    if (elementsToDo.Contains(child.ParentAssociation))
                    //        needed.Add(child.ParentAssociation);
                    //    //IList<PSMAssociationChild> components = child.ParentAssociation.Components;
                    //    //int index = components.IndexOf(child);
                    //    //needed.AddRange(components.Where(component => components.IndexOf(component) < index).Cast<Element>());
                    //}

                    if (needed.All(alreadyProcessed.Contains))
                    {
                        if (!alreadyProcessed.Contains(node))
                        {
                            alreadyProcessed.Add(node);
                        }
                    }
                    else
                    {
                        if (delayedElements.Contains(node))
                        {
                            /*
                             * association/generalization was already delayed once,
                             * now it is clear that it will never be loaded correctly,
                             * algortithm is stopped to avoid infinite cycle.
                             */
                            ordered = null;
                            return(false);
                        }
                        else
                        {
                            /* wait untill the association child is loaded */
                            foreach (Element element in needed.Where(i => !alreadyProcessed.Contains(i) && !elementsToDo.Contains(i)))
                            {
                                elementsToDo.Enqueue(element);
                            }
                            elementsToDo.Enqueue(node);
                            delayedElements.Add(node);
                        }
                    }
                }
            }

            if (!addMetElements)
            {
                alreadyProcessed.RemoveAll(element => !roots.Contains(element));
            }

            ordered = alreadyProcessed;
            return(true);
        }