IfcDoc.FormEdit.toolStripMenuItemEditDelete_Click C# (CSharp) Method

toolStripMenuItemEditDelete_Click() private method

private toolStripMenuItemEditDelete_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void toolStripMenuItemEditDelete_Click(object sender, EventArgs e)
        {
            if (!this.treeView.Focused)
                return;

            this.ctlExpressG.ScrollToSelection = false;

            if (this.treeView.SelectedNode.Tag is DocTerm)
            {
                DocTerm docTerm = (DocTerm)this.treeView.SelectedNode.Tag;
                DocTerm parent = this.treeView.SelectedNode.Parent.Tag as DocTerm;
                if (parent != null)
                {
                    parent.Terms.Remove(docTerm);
                }
                else
                {
                    this.m_project.Terms.Remove(docTerm);
                }
                this.treeView.SelectedNode.Remove();
                docTerm.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocAbbreviation)
            {
                DocAbbreviation docTerm = (DocAbbreviation)this.treeView.SelectedNode.Tag;
                this.m_project.Abbreviations.Remove(docTerm);
                this.treeView.SelectedNode.Remove();
                docTerm.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocReference)
            {
                DocReference docRef = (DocReference)this.treeView.SelectedNode.Tag;
                if(this.m_project.NormativeReferences != null && this.m_project.NormativeReferences.Contains(docRef))
                {
                    this.m_project.NormativeReferences.Remove(docRef);
                    this.treeView.SelectedNode.Remove();
                    docRef.Delete();
                }
                else if(this.m_project.InformativeReferences != null && this.m_project.InformativeReferences.Contains(docRef))
                {
                    this.m_project.InformativeReferences.Remove(docRef);
                    this.treeView.SelectedNode.Remove();
                    docRef.Delete();
                }
            }
            else if (this.treeView.SelectedNode.Tag is DocTemplateItem)
            {
                DocTemplateItem item = (DocTemplateItem)this.treeView.SelectedNode.Tag;
                DocTemplateUsage usage = (DocTemplateUsage)this.treeView.SelectedNode.Parent.Tag;
                usage.Items.Remove(item);
                this.treeView.SelectedNode.Remove();
                item.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocConceptRoot)
            {
                DocConceptRoot conceptroot = (DocConceptRoot)this.treeView.SelectedNode.Tag;

                // find the model view
                foreach (DocModelView docView in this.m_project.ModelViews)
                {
                    if (docView.ConceptRoots != null && docView.ConceptRoots.Contains(conceptroot))
                    {
                        docView.ConceptRoots.Remove(conceptroot);
                        break;
                    }
                }

                this.treeView.SelectedNode.Remove();
                conceptroot.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocTemplateUsage)
            {
                DocTemplateUsage usage = (DocTemplateUsage)this.treeView.SelectedNode.Tag;
                DocConceptRoot entity = (DocConceptRoot)this.treeView.SelectedNode.Parent.Tag;
                entity.Concepts.Remove(usage);
                this.treeView.SelectedNode.Remove();
                usage.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocTemplateDefinition)
            {
                DocTemplateDefinition target = (DocTemplateDefinition)this.treeView.SelectedNode.Tag;
                DocTemplateDefinition parent = this.treeView.SelectedNode.Parent.Tag as DocTemplateDefinition;
                if (parent != null)
                {
                    parent.Templates.Remove(target);
                }
                else
                {
                    this.m_project.Templates.Remove(target);
                }
                this.treeView.SelectedNode.Remove();

                // delete all usage of template
                foreach (DocModelView docView in this.m_project.ModelViews)
                {
                    foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                    {
                        for (int i = docRoot.Concepts.Count - 1; i >= 0; i--)
                        {
                            DocTemplateUsage docUsage = docRoot.Concepts[i];
                            if (docUsage.Definition == target)
                            {
                                docRoot.Concepts.RemoveAt(i);
                                docUsage.Delete();
                            }
                        }
                    }
                }

                // delete referencing of template from examples
                if (this.m_project.Examples != null)
                {
                    foreach(DocExample docExample in this.m_project.Examples)
                    {
                        Dereference(docExample, target);
                    }
                }

                target.Delete();

                // refresh tree to remove referenced concept leafs
                this.LoadTree();
            }
            else if (this.treeView.SelectedNode.Tag is DocModelView)
            {
                DocModelView target = (DocModelView)this.treeView.SelectedNode.Tag;
                this.m_project.ModelViews.Remove(target);
                this.treeView.SelectedNode.Remove();
                target.Delete();

                // delete referencing of view from examples
                if (this.m_project.Examples != null)
                {
                    foreach (DocExample docExample in this.m_project.Examples)
                    {
                        Dereference(docExample, target);
                    }
                }

                // delete referencing of view from publications
                foreach (DocPublication docPub in this.m_project.Publications)
                {
                    if(docPub.Views.Contains(target))
                    {
                        docPub.Views.Remove(target);
                    }
                }

                // refresh tree to remove referenced concept roots
                this.LoadTree();
            }
            else if (this.treeView.SelectedNode.Tag is DocExchangeDefinition)
            {
                DocExchangeDefinition target = (DocExchangeDefinition)this.treeView.SelectedNode.Tag;
                DocModelView docView = (DocModelView)this.treeView.SelectedNode.Parent.Tag;
                docView.Exchanges.Remove(target);
                this.treeView.SelectedNode.Remove();

                // delete referenced exchange uses
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    foreach (DocTemplateUsage docUsage in docRoot.Concepts)
                    {
                        for (int i = docUsage.Exchanges.Count - 1; i >= 0; i--)
                        {
                            DocExchangeItem docItem = docUsage.Exchanges[i];
                            if (docItem.Exchange == target)
                            {
                                docUsage.Exchanges.RemoveAt(i);
                                docItem.Delete();
                            }
                        }
                    }
                }

                target.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocChangeSet)
            {
                DocChangeSet changeset = (DocChangeSet)this.treeView.SelectedNode.Tag;
                this.m_project.ChangeSets.Remove(changeset);
                this.treeView.SelectedNode.Remove();
                changeset.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocPropertySet)
            {
                DocPropertySet docTarget = (DocPropertySet)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.PropertySets.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocProperty)
            {
                DocProperty docTarget = (DocProperty)this.treeView.SelectedNode.Tag;
                DocPropertySet docPset = (DocPropertySet)this.treeView.SelectedNode.Parent.Tag;
                docPset.Properties.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if(this.treeView.SelectedNode.Tag is DocPropertyEnumeration)
            {
                DocPropertyEnumeration docTarget = (DocPropertyEnumeration)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.PropertyEnums.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocPropertyConstant)
            {
                DocPropertyConstant docTarget = (DocPropertyConstant)this.treeView.SelectedNode.Tag;
                DocPropertyEnumeration docPset = (DocPropertyEnumeration)this.treeView.SelectedNode.Parent.Tag;
                docPset.Constants.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocQuantitySet)
            {
                DocQuantitySet docTarget = (DocQuantitySet)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.QuantitySets.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocQuantity)
            {
                DocQuantity docTarget = (DocQuantity)this.treeView.SelectedNode.Tag;
                DocQuantitySet docPset = (DocQuantitySet)this.treeView.SelectedNode.Parent.Tag;
                docPset.Quantities.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if(this.treeView.SelectedNode.Tag is DocSchema)
            {
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Tag;
                DocSection docSection = (DocSection)this.treeView.SelectedNode.Parent.Tag;
                docSection.Schemas.Remove(docSchema);
                this.treeView.SelectedNode.Remove();
                docSchema.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocEntity)
            {
                DocEntity docTarget = (DocEntity)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.Entities.Remove(docTarget);
                docTarget.Delete();
                DeleteReferencesForSchemaDefinition(docSchema, docTarget);
                DeleteReferencesForDefinition(docTarget.Name);

                //this.treeView.SelectedNode.Remove();
            }
            else if(this.treeView.SelectedNode.Tag is DocAttribute)
            {
                DocEntity docEntity = (DocEntity)this.treeView.SelectedNode.Parent.Tag;
                DocAttribute docAttr = (DocAttribute)this.treeView.SelectedNode.Tag;
                docEntity.Attributes.Remove(docAttr);
                docAttr.Delete();
                DeleteReferencesForAttribute(docEntity.Name, docAttr.Name);

                //this.treeView.SelectedNode.Remove();
            }
            else if (this.treeView.SelectedNode.Tag is DocUniqueRule)
            {
                DocEntity docEntity = (DocEntity)this.treeView.SelectedNode.Parent.Tag;
                DocUniqueRule docAttr = (DocUniqueRule)this.treeView.SelectedNode.Tag;
                docEntity.UniqueRules.Remove(docAttr);
                this.treeView.SelectedNode.Remove();
                docAttr.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocWhereRule)
            {
                DocWhereRule docAttr = (DocWhereRule)this.treeView.SelectedNode.Tag;

                if (this.treeView.SelectedNode.Parent.Tag is DocEntity)
                {
                    DocEntity docEntity = (DocEntity)this.treeView.SelectedNode.Parent.Tag;
                    docEntity.WhereRules.Remove(docAttr);
                }
                else if(this.treeView.SelectedNode.Parent.Tag is DocDefined)
                {
                    DocDefined docDefined = (DocDefined)this.treeView.SelectedNode.Parent.Tag;
                    docDefined.WhereRules.Remove(docAttr);
                }

                this.treeView.SelectedNode.Remove();
                docAttr.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocType)
            {
                DocType docTarget = (DocType)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.Types.Remove(docTarget);
                docTarget.Delete();
                DeleteReferencesForSchemaDefinition(docSchema, docTarget);
                DeleteReferencesForDefinition(docTarget.Name);
            }
            else if(this.treeView.SelectedNode.Tag is DocConstant)
            {
                DocConstant docTarget = (DocConstant)this.treeView.SelectedNode.Tag;
                DocEnumeration docEnum = (DocEnumeration)this.treeView.SelectedNode.Parent.Tag;
                docEnum.Constants.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocGlobalRule)
            {
                DocGlobalRule docTarget = (DocGlobalRule)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.GlobalRules.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocFunction)
            {
                DocFunction docTarget = (DocFunction)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.Functions.Remove(docTarget);
                this.treeView.SelectedNode.Remove();
                docTarget.Delete();
            }
            else if (this.treeView.SelectedNode.Tag is DocExample)
            {
                DocExample docExample = (DocExample)this.treeView.SelectedNode.Tag;
                DocExample parent = this.treeView.SelectedNode.Parent.Tag as DocExample;

                if (parent != null)
                {
                    parent.Examples.Remove(docExample);
                }
                else
                {
                    this.m_project.Examples.Remove(docExample);
                }
                this.treeView.SelectedNode.Remove();
                docExample.Delete();
            }
            else if(this.treeView.SelectedNode.Tag is DocComment)
            {
                DocComment docComment = (DocComment)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.Comments.Remove(docComment);
                this.treeView.SelectedNode.Remove();
                docComment.Delete();
            }
            else if(this.treeView.SelectedNode.Tag is DocPrimitive)
            {
                DocPrimitive docPrimitive = (DocPrimitive)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.Primitives.Remove(docPrimitive);
                this.treeView.SelectedNode.Remove();
                docPrimitive.Delete();

                DeleteReferencesForSchemaDefinition(docSchema, docPrimitive);
                UpdateTreeDeletion();
                this.ctlExpressG.Redraw();
            }
            else if(this.treeView.SelectedNode.Tag is DocPageTarget)
            {
                DocPageTarget docPageTarget = (DocPageTarget)this.treeView.SelectedNode.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Tag;
                docSchema.PageTargets.Remove(docPageTarget);
                this.treeView.SelectedNode.Remove();
                docPageTarget.Delete();

                foreach(DocPageSource docPageSource in docPageTarget.Sources)
                {
                    DeleteReferencesForSchemaDefinition(docSchema, docPageSource);
                }
                UpdateTreeDeletion();
                this.ctlExpressG.Redraw();
            }
            else if (this.treeView.SelectedNode.Tag is DocPageSource)
            {
                DocPageSource docPageSource = (DocPageSource)this.treeView.SelectedNode.Tag;
                DocPageTarget docPageTarget = (DocPageTarget)this.treeView.SelectedNode.Parent.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Parent.Tag;
                docPageTarget.Sources.Remove(docPageSource);
                this.treeView.SelectedNode.Remove();
                docPageSource.Delete();

                DeleteReferencesForSchemaDefinition(docSchema, docPageSource);
                UpdateTreeDeletion();
                this.ctlExpressG.Redraw();
            }
            else if (this.treeView.SelectedNode.Tag is DocDefinitionRef)
            {
                DocDefinitionRef docDefRef = (DocDefinitionRef)this.treeView.SelectedNode.Tag;
                DocSchemaRef docSchemaRef = (DocSchemaRef)this.treeView.SelectedNode.Parent.Tag;
                DocSchema docSchema = (DocSchema)this.treeView.SelectedNode.Parent.Parent.Parent.Tag;
                docSchemaRef.Definitions.Remove(docDefRef);
                this.treeView.SelectedNode.Remove();
                docDefRef.Delete();

                DeleteReferencesForSchemaDefinition(docSchema, docDefRef);
                UpdateTreeDeletion();
                this.ctlExpressG.Redraw();
            }
            else if(this.treeView.SelectedNode.Tag is DocPublication)
            {
                DocPublication docPublication = (DocPublication)this.treeView.SelectedNode.Tag;
                docPublication.Delete();
                this.m_project.Publications.Remove(docPublication);
                this.treeView.SelectedNode.Parent.Nodes.Remove(this.treeView.SelectedNode);
            }

            this.ctlExpressG.ScrollToSelection = true;
        }
FormEdit