public object LoadObjects()
        {
            _treeRoot = null;
            DesignerLoaderHost dlh = new DesignerLoaderHost();
            ComponentFactory   of  = new ComponentFactory();

            of.DesignerLoaderHost = dlh;
            of.ComponentContainer = dlh;
            object o = Reader.ReadRootObject(of, _xml);

            return(o);
        }
 public Tree(Tree parent, object owner)
 {
     _parent = parent;
     if (parent != null)
     {
         TreeRoot    r   = parent.Root;
         ObjectIDmap map = r.Map;
         IClassRef   cr  = map.GetClassRefByObject(owner);
         if (cr != null)
         {
             owner = cr;
         }
     }
     _owner = owner;
 }
        public TreeRoot GetAllObjectsInTree()
        {
            object        r    = GetRootObject();
            List <object> list = new List <object>();

            foreach (object o in this.Keys)
            {
                object v = o;
                if (_classRefMap != null)
                {
                    IClassRef cr;
                    if (_classRefMap.TryGetValue(o, out cr))
                    {
                        v = cr;
                    }
                }
                list.Add(v);
            }
            TreeRoot top = Tree.PopulateChildren(this, r, list);

            return(top);
        }
 public void RefreshObjectTree()
 {
     _treeRoot = GetAllObjectsInTree();
 }
        /// <summary>
        /// to be called from root
        /// </summary>
        /// <param name="c"></param>
        public Tree AddChild(object c)
        {
            ObjectIDmap map = Root.Map;
            IClassRef   cr  = map.GetClassRefByObject(c);

            if (cr != null)
            {
                c = cr;
            }
            Tree t0 = SearchChildByOwner(c);

            if (t0 != null)
            {
                return(t0);
            }
            ToolStripItem mi = c as ToolStripItem;

            if (mi != null)
            {
                ToolStrip ts = GetTopMenuOwner(mi);
                if (ts == this.Owner)
                {
                    if (mi.OwnerItem == null)
                    {
                        this.Add(new Tree(this, mi));
                        return(this);
                    }
                    else
                    {
                        Tree t = this.SearchChildByOwner(mi.OwnerItem);
                        if (t != null)
                        {
                            t.Add(new Tree(t, mi));
                            return(t);
                        }
                        else
                        {
                            this.Add(new Tree(this, mi));
                            return(this);
                        }
                    }
                }
                else
                {
                    foreach (Tree t in this)
                    {
                        if (ts == t.Owner)
                        {
                            return(t.AddChild(mi));
                        }
                    }
                    this.Add(new Tree(this, mi));
                    return(this);
                }
            }
            else
            {
                DataGridViewColumn dc = c as DataGridViewColumn;
                if (dc != null)
                {
                    Tree tp = this.SearchChildByOwner(dc.DataGridView);
                    if (tp == null)
                    {
                        tp = this;
                    }
                    tp.Add(new Tree(tp, c));
                    return(tp);
                }
                SplitterPanel stp = c as SplitterPanel;
                if (stp != null)
                {
                    Tree tp = this.SearchChildByOwner(stp.Parent);
                    if (tp == null)
                    {
                        tp = this;
                    }
                    tp.Add(new Tree(tp, c));
                    return(tp);
                }
                else
                {
                    Control ctl = c as Control;
                    if (ctl != null)
                    {
                        TreeRoot tr = this as TreeRoot;
                        if (tr != null)
                        {
                            ctl.ParentChanged -= tr.ParentChangehandler;
                            ctl.ParentChanged += tr.ParentChangehandler;
                        }
                    }
                    Tree tParent = this;

                    Control r = this.Owner as Control;

                    if (ctl != null)
                    {
                        if (ctl.Parent != null)
                        {
                            if (ctl.Parent != r)
                            {
                                Tree t = this.SearchChildByOwner(ctl.Parent);
                                if (t != null)
                                {
                                    tParent = t;
                                }
                            }
                        }
                    }
                    Tree tx = new Tree(tParent, c);
                    tParent.Add(tx);
                    SplitContainer sc = c as SplitContainer;
                    if (sc != null)
                    {
                        tx.Add(new Tree(tx, sc.Panel1));
                        tx.Add(new Tree(tx, sc.Panel2));
                    }
                    return(tParent);
                }
            }
        }
        public static TreeRoot PopulateChildren(ObjectIDmap map, object root, IList <object> list)
        {
            TreeRoot                  top            = new TreeRoot(map, root);
            Control                   rc             = root as Control;
            List <Control>            ctrls          = new List <Control>();
            List <ToolStripItem>      menuItems      = new List <ToolStripItem>();
            List <SplitterPanel>      splitterpanels = new List <SplitterPanel>();
            List <DataGridViewColumn> dcolumns       = new List <DataGridViewColumn>();

            foreach (object v in list)
            {
                if (v != root)
                {
                    ToolStripItem mi = v as ToolStripItem;
                    if (mi != null)
                    {
                        menuItems.Add(mi);
                        continue;
                    }
                    DataGridViewColumn dc = v as DataGridViewColumn;
                    if (dc != null)
                    {
                        dcolumns.Add(dc);
                        continue;
                    }
                    SplitterPanel sp = v as SplitterPanel;
                    if (sp != null)
                    {
                        splitterpanels.Add(sp);
                        continue;
                    }
                    Control c = v as Control;
                    if (c != null)
                    {
                        c.ParentChanged += new EventHandler(top.OnControlParentChanged);

                        if (c.Parent != null && c.Parent != rc)
                        {
                            ctrls.Add(c);
                            continue;
                        }
                    }
                    //
                    Tree t0 = new Tree(top, v);
                    top.Add(t0);
                    SplitContainer sc = v as SplitContainer;
                    if (sc != null)
                    {
                        t0.Add(new Tree(t0, sc.Panel1));
                        t0.Add(new Tree(t0, sc.Panel2));
                    }
                }
            }

            while (menuItems.Count > 0)
            {
                List <ToolStripItem> menuItems0 = new List <ToolStripItem>();
                foreach (ToolStripItem mi in menuItems)
                {
                    ToolStrip ts = GetTopMenuOwner(mi);
                    if (ts == null)
                    {
                        top.Add(new Tree(top, mi));
                    }
                    else
                    {
                        Tree t = top.GetChildByOwner(ts);
                        if (t == null)
                        {
                            top.Add(new Tree(top, mi));
                        }
                        else
                        {
                            if (mi.OwnerItem == null)
                            {
                                t.Add(new Tree(t, mi));
                            }
                            else
                            {
                                t = top.SearchChildByOwner(mi.OwnerItem);
                                if (t != null)
                                {
                                    t.Add(new Tree(t, mi));
                                }
                                else
                                {
                                    menuItems0.Add(mi);
                                }
                            }
                        }
                    }
                }
                if (menuItems.Count == menuItems0.Count)
                {
                    foreach (ToolStripItem mi in menuItems0)
                    {
                        top.Add(new Tree(top, mi));
                    }
                    break;
                }
                menuItems = menuItems0;
            }

            while (ctrls.Count > 0)
            {
                List <Control> ctrls0 = new List <Control>();
                foreach (Control c in ctrls)
                {
                    Tree t = top.SearchChildByOwner(c.Parent);
                    if (t != null)
                    {
                        Tree t0 = new Tree(t, c);
                        t.Add(t0);
                        SplitContainer sc = c as SplitContainer;
                        if (sc != null)
                        {
                            t0.Add(new Tree(t0, sc.Panel1));
                            t0.Add(new Tree(t0, sc.Panel2));
                        }
                    }
                    else
                    {
                        ctrls0.Add(c);
                    }
                }
                if (ctrls.Count == ctrls0.Count)
                {
                    foreach (Control c in ctrls0)
                    {
                        Tree t0 = new Tree(top, c);
                        top.Add(t0);
                        SplitContainer sc = c as SplitContainer;
                        if (sc != null)
                        {
                            t0.Add(new Tree(t0, sc.Panel1));
                            t0.Add(new Tree(t0, sc.Panel2));
                        }
                    }
                    break;
                }
                ctrls = ctrls0;
            }

            if (splitterpanels.Count > 0)
            {
                foreach (SplitterPanel sp in splitterpanels)
                {
                    Tree t = top.SearchChildByOwner(sp.Parent);
                    if (t != null)
                    {
                        t.Add(new Tree(t, sp));
                    }
                }
            }

            if (dcolumns.Count > 0)
            {
                foreach (DataGridViewColumn dc in dcolumns)
                {
                    Tree t = top.GetChildByOwner(dc.DataGridView);
                    if (t == null)
                    {
                        top.Add(new Tree(top, dc));
                    }
                    else
                    {
                        t.Add(new Tree(t, dc));
                    }
                }
            }
            return(top);
        }