예제 #1
0
        /// <summary>
        ///     Brings the model element from an update dictionary to the updated dictionary
        /// </summary>
        public virtual void Merge()
        {
            ModelElement target = Updates;

            if (target == null)
            {
                // Copy element to parent
                ModelElement parent = Enclosing as ModelElement;
                if (parent != null)
                {
                    NameSpace parentNameSpace = parent.Updates as NameSpace;
                    if (parentNameSpace != null)
                    {
                        parentNameSpace.AddModelElement(Duplicate());
                    }

                    Paragraph parentParagraph = parent.Updates as Paragraph;
                    if (parentParagraph != null)
                    {
                        parentParagraph.AddModelElement(Duplicate());
                    }

                    Structure parentStructure = parent.Updates as Structure;
                    if (parentStructure != null)
                    {
                        parentStructure.AddModelElement(Duplicate());
                    }

                    StateMachine parentStateMachine = parent.Updates as StateMachine;
                    if (parentStateMachine != null)
                    {
                        parentStateMachine.AddModelElement(Duplicate());
                    }
                }
            }
            else
            {
                if (!IsRemoved)
                {
                    target.UpdateModelElementAccordingToSource(this);
                }
                else
                {
                    target.Delete();
                }
            }
        }
예제 #2
0
        /// <summary>
        ///     Accepts the drop of a base tree node on this node
        /// </summary>
        /// <param name="sourceNode"></param>
        public virtual void AcceptCopy(BaseTreeNode sourceNode)
        {
            try
            {
                ModelElement modelElement = sourceNode.Model as ModelElement;
                if (modelElement != null)
                {
                    ModelElement copy = modelElement.Duplicate();
                    if (copy != null)
                    {
                        DataDictionary.Util.DontNotify(() =>
                        {
                            // Trick : This is used to know the enclosing collection in the target
                            Model.AddModelElement(copy);
                            ArrayList targetCollection = copy.EnclosingCollection;
                            copy.Delete();
                            // End of trick

                            if (targetCollection != null)
                            {
                                int previousIndex = -1;
                                int index         = 0;
                                while (previousIndex != index)
                                {
                                    previousIndex = index;
                                    foreach (INamable other in targetCollection)
                                    {
                                        if (index > 0)
                                        {
                                            if (other.Name.Equals(copy.Name + "_" + index))
                                            {
                                                index += 1;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            if (other.Name.Equals(copy.Name))
                                            {
                                                index += 1;
                                                break;
                                            }
                                        }
                                    }
                                }

                                // Renaming is mandatory
                                if (index > 0)
                                {
                                    copy.Name = copy.Name + "_" + index;
                                }
                            }
                        });

                        Model.AddModelElement(copy);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Cannot copy element\n");
            }
        }