Пример #1
0
 public void OnPostSerialize(XmlSerializer.ObjectIDmap objMap, System.Xml.XmlNode objectNode, bool saved, object serializer)
 {
     if (saved)
     {
     }
     else
     {
         if (_pointer == null && _memberPointer == null)
         {
             XmlNode node = SerializeUtil.GetClassRefNodeByObjectId(objectNode, _memberId);
             if (node != null)
             {
                 XmlObjectReader xr = (XmlObjectReader)serializer;
                 _pointer = xr.ReadObject <ClassInstancePointer>(node, ClassPointer.CreateClassPointer(objMap));
                 //_pointer.ObjectInstance = objMap.GetObjectByID(_pointer.MemberId);
             }
             else
             {
                 _pointer = objMap.GetClassRefById(_memberId) as ClassInstancePointer;
             }
         }
         if (_pointer == null)
         {
             object v = objMap.GetObjectByID(_memberId);
             if (v != null)
             {
                 _memberPointer = new MemberComponentId(objMap.GetTypedData <ClassPointer>(), v, _memberId);
             }
         }
         if (_pointer == null && _memberPointer == null)
         {
             objMap.AddPostProcessor(this);
         }
     }
 }
 public ObjectIDmap(LimnorProject prj, ObjectIDmap parent, UInt64 componentId, XmlNode data)
     : this(prj, componentId, data)
 {
     ParanetMap = parent;
     if (parent != null)
     {
         parent.AddChildMap(this);
     }
 }
        public ObjectIDmap GetMap(object obj)
        {
            ObjectIDmap map = GetRootMap();

            if (map.ContainsKey(obj))
            {
                return(map);
            }
            return(map.GetChildMapByObject(obj));
        }
        public ObjectIDmap GetMapByClassId(UInt32 classId)
        {
            ObjectIDmap map = GetRootMap();

            if (map.ClassId == classId)
            {
                return(map);
            }
            return(map.GetChildMapByClassId(classId));
        }
        public ObjectIDmap GetRootMap()
        {
            ObjectIDmap map = this;

            while (map.ParanetMap != null)
            {
                map = map.ParanetMap;
            }
            return(map);
        }
        public ObjectIDmap GetMap(UInt64 componentId)
        {
            ObjectIDmap map = GetRootMap();

            if (map.WholeMemberId == componentId)
            {
                return(map);
            }
            return(map.GetChildMapByWholeId(componentId));
        }
        public void AddChildMap(ObjectIDmap map)
        {
            ObjectIDmap mc = GetChildMapByWholeId(map.WholeMemberId);

            if (mc != null)
            {
                throw new SerializerException("object map for class [{0},{1}] already exists", map.ClassId, map.MemberId);
            }
            if (_childMaps == null)
            {
                _childMaps = new List <ObjectIDmap>();
            }
            _childMaps.Add(map);
        }
 public void OnPostSerialize(XmlSerializer.ObjectIDmap objMap, System.Xml.XmlNode objectNode, bool saved, object serializer)
 {
     if (saved)
     {
     }
     else
     {
         _root = objMap.RootPointer as ClassPointer;
         if (_owner == null)
         {
             _owner = objMap.RootPointer as IObjectPointer;
         }
     }
 }
 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 ObjectIDmap GetChildMapByObject(object obj)
 {
     if (_childMaps != null)
     {
         foreach (ObjectIDmap map in _childMaps)
         {
             if (map.ContainsKey(obj))
             {
                 return(map);
             }
             ObjectIDmap mc = map.GetChildMapByObject(obj);
             if (mc != null)
             {
                 return(mc);
             }
         }
     }
     return(null);
 }
 public ObjectIDmap GetChildMapByClassId(UInt32 componentId)
 {
     if (_childMaps != null)
     {
         foreach (ObjectIDmap map in _childMaps)
         {
             if (map.ClassId == componentId)
             {
                 return(map);
             }
             ObjectIDmap mc = map.GetChildMapByClassId(componentId);
             if (mc != null)
             {
                 return(mc);
             }
         }
     }
     return(null);
 }
 public ObjectIDmap GetChildMapByWholeId(UInt64 componentId)
 {
     if (_childMaps != null)
     {
         foreach (ObjectIDmap map in _childMaps)
         {
             if (map.WholeMemberId == componentId)
             {
                 return(map);
             }
             ObjectIDmap mc = map.GetChildMapByWholeId(componentId);
             if (mc != null)
             {
                 return(mc);
             }
         }
     }
     return(null);
 }
        public virtual Tree SearchParentByOwner(object owner)
        {
            ObjectIDmap map = Root.Map;

            foreach (Tree t in this)
            {
                if (map.IsSameInstance(t.Owner, owner))
                {
                    return(this);
                }
                else
                {
                    Tree t0 = t.SearchParentByOwner(owner);
                    if (t0 != null)
                    {
                        return(t0);
                    }
                }
            }
            return(null);
        }
        public Tree GetChildByOwner(object owner)
        {
            ObjectIDmap map = Root.Map;

            foreach (Tree t in this)
            {
                if (map.IsSameInstance(t.Owner, owner))
                {
                    return(t);
                }
                else
                {
                    Tree t0 = t.GetChildByOwner(owner);
                    if (t0 != null)
                    {
                        return(t0);
                    }
                }
            }
            return(null);
        }
        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);
        }
        /// <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 TreeRoot(ObjectIDmap map, object owner)
     : base(null, owner)
 {
     _map = map;
     _parentChangeHandler = new EventHandler(OnControlParentChanged);
 }