Example #1
0
        private void SaveNode(TreeNode tn)
        {
            ChangeInfo info = (ChangeInfo)tn.Tag;

            if (tn.Checked)
            {
                if (info.Original == null)
                {
                    // add new item
                    if (info.Change is DocLocalization)
                    {
                        DocLocalization localChange = (DocLocalization)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocObject  docObj     = (DocObject)parentinfo.Original;
                        docObj.RegisterLocalization(localChange.Locale, localChange.Name, localChange.Documentation);
                    }
                    else if (info.Change is DocAttribute)
                    {
                        DocAttribute localAttr = (DocAttribute)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity  docEntity  = (DocEntity)parentinfo.Original;

                        DocAttribute docAttr = (DocAttribute)localAttr.Clone();
                        docEntity.Attributes.Add(docAttr);
                    }
                    else if (info.Change is DocWhereRule)
                    {
                        DocWhereRule localAttr = (DocWhereRule)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity  docEntity  = (DocEntity)parentinfo.Original;

                        DocWhereRule docAttr = (DocWhereRule)localAttr.Clone();
                        docEntity.WhereRules.Add(docAttr);
                    }
                    else if (info.Change is DocFunction)
                    {
                        DocFunction localAttr = (DocFunction)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocSchema  docSchema  = (DocSchema)parentinfo.Original;

                        DocFunction docAttr = (DocFunction)localAttr.Clone();
                        docSchema.Functions.Add(docAttr);
                    }
                    else if (info.Change is DocConstant)
                    {
                        this.ToString();
                    }
                    else if (info.Change is DocProperty)
                    {
                        this.ToString();

                        DocProperty localProp = (DocProperty)info.Change;

                        ChangeInfo     parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocPropertySet docPset    = (DocPropertySet)parentinfo.Original;

                        DocProperty docProperty = (DocProperty)localProp.Clone();
                        docPset.Properties.Add(docProperty);
                    }
                    else if (info.Change is DocPropertyConstant)
                    {
                        this.ToString();

                        DocPropertyConstant localProp = (DocPropertyConstant)info.Change;

                        ChangeInfo             parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocPropertyEnumeration docPset    = (DocPropertyEnumeration)parentinfo.Original;

                        DocPropertyEnumeration docEnumChange = (DocPropertyEnumeration)parentinfo.Change;
                        int index = docEnumChange.Constants.IndexOf(localProp);

                        DocPropertyConstant docProperty = (DocPropertyConstant)localProp.Clone();
                        docPset.Constants.Insert(index, docProperty);
                    }
                    else
                    {
                        this.ToString();
                    }
                }
                else if (info.Change == null)
                {
                    // removal of definition
                    if (info.Original is DocAttribute)
                    {
                        DocAttribute docAttr    = (DocAttribute)info.Original;
                        ChangeInfo   parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity    docEntity  = (DocEntity)parentinfo.Original;

                        docEntity.Attributes.Remove(docAttr);
                        docAttr.Delete();
                    }
                    else
                    {
                        this.ToString();
                    }
                }
                else
                {
                    // change of documentation
                    info.Original.Name          = info.Change.Name;
                    info.Original.Documentation = info.Change.Documentation;

                    if (info.Original is DocWhereRule)
                    {
                        DocWhereRule whereOriginal = (DocWhereRule)info.Original;
                        DocWhereRule whereChange   = (DocWhereRule)info.Change;
                        whereOriginal.Expression = whereChange.Expression;
                    }
                    else if (info.Original is DocFunction)
                    {
                        DocFunction whereOriginal = (DocFunction)info.Original;
                        DocFunction whereChange   = (DocFunction)info.Change;
                        whereOriginal.Expression = whereChange.Expression;
                    }
                }
            }

            foreach (TreeNode tnSub in tn.Nodes)
            {
                SaveNode(tnSub);
            }
        }