Ejemplo n.º 1
0
        public PSMAttribute AddAttribute(Property attribute)
        {
            if (attribute == null)
            {
                return((PSMAttribute)AddAttribute());
            }

            if (attribute != null && !representedClass.MeAndAncestors.Contains(attribute.Class))
            {
                throw new ArgumentException("The given attribute is not owned by the represented class!");
            }

            PSMAttribute attr = new _PSMAttribute(attribute, Schema);

            psmAttributes.Add(attr);
            attr.Diagram = this.Diagram;
            attribute.DerivedPSMAttributes.Add(attr);

            if (attribute.Class != representedClass)
            {
                List <Generalization> path = representedClass.GetPathToAncestor(attribute.Class);
                if (path != null)
                {
                    foreach (Generalization gen in path)
                    {
                        gen.ReferencingPSMAttributes.Add(attr);
                        attr.UsedGeneralizations.Add(gen);
                    }
                }
            }

            return(attr);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Occurs whenever the Attributes collection has changed.
        /// </summary>
        /// <param name="sender">Object that has raised the event</param>
        /// <param name="e">Information about the change</param>
        protected void OnAttributesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (PSMAttribute attribute in e.NewItems)
                {
                    _PSMAttribute implAttr = attribute as _PSMAttribute;
                    if (implAttr == null)
                    {
                        attributes.Remove(attribute);
                        throw new ArgumentException("Inserted attribute was created outside the model library!");
                    }

                    implAttr.Class = PSMClass;
                    implAttr.AttributeContainer = this;
                    adaptedElement.OwnedAttribute.Add(implAttr.AdaptedElement);
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (PSMAttribute attribute in e.OldItems)
                {
                    _PSMAttribute implAttr = attribute as _PSMAttribute;
                    implAttr.Class = null;
                    implAttr.AttributeContainer = null;
                    adaptedElement.OwnedAttribute.Remove(implAttr.AdaptedElement);
                }
            }
        }
Ejemplo n.º 3
0
        public PSMAttribute AddAttribute()
        {
            PSMAttribute attr = new _PSMAttribute(null, Schema);

            attributes.Add(attr);
            attr.Diagram = this.Diagram;
            return(attr);
        }
Ejemplo n.º 4
0
        public override Property AddAttribute()
        {
            PSMAttribute attr = new _PSMAttribute(null, Schema);

            psmAttributes.Add(attr);

            attr.Diagram = this.Diagram;
            attr.Name    = "FreeAttribute" + psmAttributes.Count;
            attr.Alias   = attr.Name;
            attr.Class   = this;
            return(attr);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Occurs whenever the PSMAttributes collection has changed.
        /// Synchronizes the content of the Attributes collection.
        /// </summary>
        /// <param name="sender">Object that has raised the event</param>
        /// <param name="e">Information about the change</param>
        /// <exception cref="ArgumentException">
        /// Added some attributes that are not inherited from _PSMAttribute
        /// </exception>
        protected void OnPSMAttributesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (Property prop in e.NewItems)
                {
                    _PSMAttribute implAttr = prop as _PSMAttribute;
                    if (implAttr == null)
                    {
                        psmAttributes.Remove(implAttr);
                        throw new ArgumentException("A PIM attribute or a PSM attribute created outside " +
                                                    "the model library has been added to the collection!");
                    }

                    implAttr.Class = this;
                    if (!adaptedElement.OwnedAttribute.Contains(implAttr.Adaptee))
                    {
                        adaptedElement.OwnedAttribute.Add(implAttr.Adaptee);
                    }

                    if (!attributes.Contains(implAttr))
                    {
                        attributes.Add(implAttr);
                    }
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (Property prop in e.OldItems)
                {
                    _PSMAttribute implAttr = prop as _PSMAttribute;

                    implAttr.Class = null;
                    adaptedElement.OwnedAttribute.Remove(implAttr.Adaptee);

                    attributes.Remove(implAttr);
                }
            }
        }