Пример #1
0
        private void RefreshObject(object o, bool exists)
        {
            //or from known descendancy
            var knownDescendancy = _activator.CoreChildProvider.GetDescendancyListIfAnyFor(o);

            //if it is a root object maintained by this tree and it exists
            if (MaintainRootObjects != null && MaintainRootObjects.Contains(o.GetType()) && exists)
            {
                //if tree doesn't yet contain the object
                if (!Tree.Objects.Cast <object>().Contains(o))
                {
                    Tree.AddObject(o); //add it
                    return;
                }
            }

            if (ShouldClearPinFilterOnRefresh(o, exists))
            {
                _pinFilter.UnApplyToTree();
            }

            if (!exists)
            {
                //clear the current selection (if the object to be deleted is selected)
                if (Tree.IsSelected(o))
                {
                    Tree.SelectedObject  = null;
                    Tree.SelectedObjects = null;
                }

                //remove it from tree
                Tree.RemoveObject(o);
            }


            if (!IsHiddenByFilter(o))
            {
                //By preference refresh the parent that way we deal with hierarchy changes
                if (knownDescendancy != null)
                {
                    var lastParent = knownDescendancy.Parents.LastOrDefault(p => Tree.IndexOf(p) != -1);

                    //does tree have parent?
                    if (lastParent != null)
                    {
                        Tree.RefreshObject(lastParent); //refresh parent
                    }
                    else
                    if (Tree.IndexOf(o) != -1)
                    {
                        //Tree has object but not parent, bad times, maybe BetterRouteExists?
                        Tree.RebuildAll(true);
                    }
                }
                else
                //if we have the object
                if (Tree.IndexOf(o) != -1 && exists)
                {
                    Tree.RefreshObject(o);     //it exists so refresh it!
                }
            }
        }