예제 #1
0
파일: Graph.cs 프로젝트: Cloudxtreme/bot-9
        private void handleChanges()
        {
            handleNodesChangedWiring();

            if (m_centerChanged && m_nodeCollectionChanged &&
                CenterObject != null &&
                m_centerGraphContentPresenter != null
                )
            {
                Debug.Assert(!CenterObject.Equals(m_centerDataInUse));
                Debug.Assert(m_centerGraphContentPresenter.Content == null || m_centerGraphContentPresenter.Content.Equals(m_centerDataInUse));

                m_centerDataInUse = CenterObject;

                //figure out if we can re-cycle one of the existing children as the center Node
                //if we can, newCenter != null
                GraphContentPresenter newCenterPresenter = null;
                for (int i = 0; i < m_nodePresenters.Count; i++)
                {
                    if (m_nodePresenters[i].Content.Equals(CenterObject))
                    {
                        //we should re-use this
                        newCenterPresenter  = m_nodePresenters[i];
                        m_nodePresenters[i] = null;
                        break;
                    }
                }

                //figure out if we can re-cycle the exsting center as one of the new child nodes
                //if we can, newChild != null && newChildIndex == indexOf(data in Nodes)
                int newChildIndex = -1;
                GraphContentPresenter newChildPresenter = null;
                for (int i = 0; i < m_nodesInUse.Count; i++)
                {
                    if (m_nodesInUse[i] != null && m_centerGraphContentPresenter.Content != null && m_nodesInUse[i].Equals(m_centerGraphContentPresenter.Content))
                    {
                        newChildIndex                 = i;
                        newChildPresenter             = m_centerGraphContentPresenter;
                        m_centerGraphContentPresenter = null;
                        break;
                    }
                }

                //now we potentially have a center (or not) and one edge(or not)
                GraphContentPresenter[] newChildren = new GraphContentPresenter[m_nodesInUse.Count];

                //we did all the work to see if the current cernter can be reused.
                //if it can, use it
                if (newChildPresenter != null)
                {
                    newChildren[newChildIndex] = newChildPresenter;
                }

                //now go through all the existing children and place them in newChildren
                //if they match
                for (int i = 0; i < m_nodesInUse.Count; i++)
                {
                    if (newChildren[i] == null)
                    {
                        for (int j = 0; j < m_nodePresenters.Count; j++)
                        {
                            if (m_nodePresenters[j] != null)
                            {
                                if (m_nodesInUse[i].Equals(m_nodePresenters[j].Content))
                                {
                                    Debug.Assert(newChildren[i] == null);
                                    newChildren[i]      = m_nodePresenters[j];
                                    m_nodePresenters[j] = null;
                                    break;
                                }
                            }
                        }
                    }
                }

                //we've now reused everything we can
                if (m_centerGraphContentPresenter == null)
                {
                    //we didn't find anything to recycle
                    //create a new one
                    if (newCenterPresenter == null)
                    {
                        m_centerGraphContentPresenter = GetGraphContentPresenter(
                            CenterObject,
                            m_nodeTemplateBinding,
                            m_nodeTemplateSelectorBinding,
                            false
                            );
                        this.AddVisualChild(m_centerGraphContentPresenter);
                    }
                    else
                    { //we did find something to recycle. Use it.
                        m_centerGraphContentPresenter = newCenterPresenter;
                        Debug.Assert(VisualTreeHelper.GetParent(newCenterPresenter) == this);
                    }
                }
                else
                {
                    if (newCenterPresenter == null)
                    {
                        m_centerGraphContentPresenter.Content = CenterObject;
                    }
                    else
                    {
                        beginRemoveAnimation(m_centerGraphContentPresenter, true);
                        m_centerGraphContentPresenter = newCenterPresenter;
                        Debug.Assert(VisualTreeHelper.GetParent(newCenterPresenter) == this);
                    }
                }

                //go through all of the old CPs that are not being used and remove them
                m_nodePresenters
                .Where(gcp => gcp != null)
                .ForEach(gcp => beginRemoveAnimation(gcp, false));

                //go through and "fill in" all the new CPs
                for (int i = 0; i < m_nodesInUse.Count; i++)
                {
                    if (newChildren[i] == null)
                    {
                        GraphContentPresenter gcp = GetGraphContentPresenter(m_nodesInUse[i],
                                                                             m_nodeTemplateBinding, m_nodeTemplateSelectorBinding, true);
                        this.AddVisualChild(gcp);
                        newChildren[i] = gcp;
                    }
                }

                m_nodePresenters.Clear();
                m_nodePresenters.AddRange(newChildren);

                m_centerChanged         = false;
                m_nodeCollectionChanged = false;
            }
            else
            {
                if (m_centerChanged)
                {
                    m_centerDataInUse = CenterObject;
                    if (m_centerGraphContentPresenter != null)
                    {
                        Debug.Assert(m_centerDataInUse == null);
                        beginRemoveAnimation(m_centerGraphContentPresenter, true);
                        m_centerGraphContentPresenter = null;
                    }
                    if (m_centerDataInUse != null)
                    {
                        SetUpCleanCenter(m_centerDataInUse);
                    }
                    m_centerChanged = false;
                }

                if (m_nodeCollectionChanged)
                {
                    setupNodes(Nodes);

                    m_nodesInUse = Nodes;

                    m_nodeCollectionChanged = false;
                }
            }

#if DEBUG
            if (CenterObject != null)
            {
                CenterObject.Equals(m_centerDataInUse);
                Debug.Assert(m_centerGraphContentPresenter != null);
            }
            else
            {
                Debug.Assert(m_centerDataInUse == null);
            }
            if (Nodes != null)
            {
                Debug.Assert(m_nodePresenters != null);
                Debug.Assert(Nodes.Count == m_nodePresenters.Count);
                Debug.Assert(m_nodesInUse == Nodes);
            }
            else
            {
                Debug.Assert(m_nodesInUse == null);
                if (m_nodePresenters != null)
                {
                    Debug.Assert(m_nodePresenters.Count == 0);
                }
            }
#endif

            Children.ForEach(gcp => SetIsCenter(gcp, gcp == m_centerGraphContentPresenter));
        }
예제 #2
0
        private void handleChanges()
        {
            handleNodesChangedWiring();

            if (_centerChanged && _nodeCollectionChanged && _centerObjectPresenter != null && _nodePresenters != null &&
                CenterObject != null && !CenterObject.Equals(_centerDataInUse))
            {
                Debug.Assert(!CenterObject.Equals(_centerDataInUse));
                Debug.Assert(_centerObjectPresenter.Content == null || _centerObjectPresenter.Content.Equals(_centerDataInUse));

                _centerDataInUse = CenterObject;

                //figure out if we can re-cycle one of the existing children as the center Node
                //if we can, newCenter != null
                GraphContentPresenter newCenterPresenter = null;
                for (int i = 0; i < _nodePresenters.Count; i++)
                {
                    if (_nodePresenters[i].Content.Equals(CenterObject))
                    {
                        //we should re-use this
                        newCenterPresenter = _nodePresenters[i];
                        _nodePresenters[i] = null;
                        break;
                    }
                }

                //figure out if we can re-cycle the exsting center as one of the new child nodes
                //if we can, newChild != null && newChildIndex == indexOf(data in Nodes)
                int newChildIndex = -1;
                GraphContentPresenter newChildPresnter = null;
                for (int i = 0; i < _nodesInUse.Count; i++)
                {
                    if (_nodesInUse[i] != null && _centerObjectPresenter.Content != null && _nodesInUse[i].Equals(_centerObjectPresenter.Content))
                    {
                        newChildIndex          = i;
                        newChildPresnter       = _centerObjectPresenter;
                        _centerObjectPresenter = null;
                        break;
                    }
                }

                //now we potentially have a center (or not) and one edge(or not)
                GraphContentPresenter[] newChildren = new GraphContentPresenter[_nodesInUse.Count];
                if (newChildPresnter != null)
                {
                    newChildren[newChildIndex] = newChildPresnter;
                }

                for (int i = 0; i < _nodesInUse.Count; i++)
                {
                    if (newChildren[i] == null)
                    {
                        for (int j = 0; j < _nodePresenters.Count; j++)
                        {
                            if (_nodePresenters[j] != null)
                            {
                                if (_nodesInUse[i].Equals(_nodePresenters[j].Content))
                                {
                                    Debug.Assert(newChildren[i] == null);
                                    newChildren[i]     = _nodePresenters[j];
                                    _nodePresenters[j] = null;
                                    break;
                                }
                            }
                        }
                    }
                }

                //we've no reused everything we can
                if (_centerObjectPresenter == null)
                {
                    if (newCenterPresenter == null)
                    {
                        _centerObjectPresenter = GetGraphContentPresenter(CenterObject,
                                                                          _nodeTemplateBinding, _nodeTemplateSelectorBinding, false
                                                                          );
                        this.AddVisualChild(_centerObjectPresenter);
                    }
                    else
                    {
                        _centerObjectPresenter = newCenterPresenter;
                        Debug.Assert(VisualTreeHelper.GetParent(newCenterPresenter) == this);
                    }
                }
                else
                {
                    if (newCenterPresenter == null)
                    {
                        _centerObjectPresenter.Content = CenterObject;
                    }
                    else
                    {
                        KillGCP(_centerObjectPresenter, true);
                        _centerObjectPresenter = newCenterPresenter;
                        Debug.Assert(VisualTreeHelper.GetParent(newCenterPresenter) == this);
                    }
                }

                //go through all of the old CPs that are not being used and remove them
                for (int i = 0; i < _nodePresenters.Count; i++)
                {
                    if (_nodePresenters[i] != null)
                    {
                        KillGCP(_nodePresenters[i], false);
                    }
                }

                //go throug and "fill in" all the new CPs
                for (int i = 0; i < _nodesInUse.Count; i++)
                {
                    if (newChildren[i] == null)
                    {
                        GraphContentPresenter gcp = GetGraphContentPresenter(_nodesInUse[i],
                                                                             _nodeTemplateBinding, _nodeTemplateSelectorBinding, true);
                        this.AddVisualChild(gcp);
                        newChildren[i] = gcp;
                    }
                }

                _nodePresenters.Clear();
                _nodePresenters.AddRange(newChildren);

                _isChildCountValid = false;

                _centerChanged         = false;
                _nodeCollectionChanged = false;
            }

            if (_centerChanged)
            {
                _centerDataInUse = CenterObject;
                if (_centerObjectPresenter != null)
                {
                    KillGCP(_centerObjectPresenter, true);
                    _centerObjectPresenter = null;
                }
                if (_centerDataInUse != null)
                {
                    SetUpCleanCenter(_centerDataInUse);
                }
                _centerChanged = false;
            }

            if (_nodeCollectionChanged)
            {
                SetupNodes(Nodes);

                _nodesInUse = Nodes;

                _nodeCollectionChanged = false;
            }

#if DEBUG
            if (CenterObject != null)
            {
                CenterObject.Equals(_centerDataInUse);
                Debug.Assert(_centerObjectPresenter != null);
            }
            else
            {
                Debug.Assert(_centerDataInUse == null);
            }
            if (Nodes != null)
            {
                Debug.Assert(_nodePresenters != null);
                Debug.Assert(Nodes.Count == _nodePresenters.Count);
                Debug.Assert(_nodesInUse == Nodes);
            }
            else
            {
                Debug.Assert(_nodesInUse == null);
                if (_nodePresenters != null)
                {
                    Debug.Assert(_nodePresenters.Count == 0);
                }
            }
#endif
        }