IfcDoc.FormEdit.treeView_AfterLabelEdit C# (CSharp) Method

treeView_AfterLabelEdit() private method

private treeView_AfterLabelEdit ( object sender, NodeLabelEditEventArgs e ) : void
sender object
e NodeLabelEditEventArgs
return void
        private void treeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            object target = e.Node.Tag;

            if (target is DocObject)
            {
                DocObject docObj = (DocObject)target;

            #if false
                if (String.IsNullOrEmpty(e.Label))
                {
                    docObj.Name = null;
                    e.Node.Text = docObj.ToString();
                    e.CancelEdit = true;
                    return;
                }
            #endif
                bool unique = true;
                if(target is DocProperty || target is DocQuantity || target is DocWhereRule || target is DocUniqueRule || target is DocTemplateUsage)
                {
                    unique = false;
                }

                // check for unique value
                TreeNode tnExist = null;
                if(e.Label == String.Empty && unique)
                {
                    MessageBox.Show("This item requires a name.");

                    e.Node.BeginEdit();
                }
                else if (e.Label != null && unique && this.m_mapTree.TryGetValue(e.Label.ToLowerInvariant(), out tnExist) && tnExist != e.Node)
                {
                    // conflict -- prompt for a different value
                    MessageBox.Show("The specified name is already in use.");

                    // rename
                    e.Node.BeginEdit();
                }
                else
                {
                    // rename and replace link
                    if (unique && docObj.Name != null)
                    {
                        string oldkey = docObj.Name.ToLowerInvariant();
                        if (this.m_mapTree.ContainsKey(oldkey))
                        {
                            this.m_mapTree.Remove(oldkey);
                        }
                    }
                    docObj.Name = e.Label;
                    e.Node.Text = docObj.ToString();
                    e.CancelEdit = true; // prevent from updating to other text

                    if (unique && docObj.Name != null)
                    {
                        this.m_mapTree.Add(docObj.Name.ToLowerInvariant(), e.Node);
                    }

                    // reposition in tree
                    if (target is DocType)
                    {
                        this.BeginInvoke(new MethodInvoker(SortType));
                    }
                    else if(target is DocEntity)
                    {
                        this.BeginInvoke(new MethodInvoker(SortEntity));
                    }
                    else if(target is DocFunction)
                    {
                        this.BeginInvoke(new MethodInvoker(SortFunction));
                    }
                    else if (target is DocGlobalRule)
                    {
                        this.BeginInvoke(new MethodInvoker(SortGlobal));
                    }
                    else if (target is DocPropertySet)
                    {
                        this.BeginInvoke(new MethodInvoker(SortPset));
                    }
                    else if (target is DocPropertyEnumeration)
                    {
                        this.BeginInvoke(new MethodInvoker(SortPropertyEnumeration));
                    }
                    else if (target is DocQuantitySet)
                    {
                        this.BeginInvoke(new MethodInvoker(SortQset));
                    }

                    //... update any named references from other schemas....

                    this.ctlExpressG.Redraw();
                }
            }
        }
FormEdit