/// <summary>
        /// Replaces a node.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void Replace(IWriteableReplaceOperation operation)
        {
            int BlockIndex = operation.BlockIndex;

            Debug.Assert(BlockIndex >= 0 && BlockIndex < BlockStateList.Count);

            IWriteableBlockState BlockState = (IWriteableBlockState)BlockStateList[BlockIndex];

            int Index = operation.Index;

            Debug.Assert(Index >= 0 && Index < BlockState.StateList.Count);

            IBlock ChildBlock = BlockState.ChildBlock;
            Node   ParentNode = Owner.Node;

            IWriteableNodeState OldChildState = (IWriteableNodeState)BlockState.StateList[Index];
            Node OldNode = OldChildState.Node;
            IWriteableBrowsingBlockNodeIndex OldBrowsingIndex = (IWriteableBrowsingBlockNodeIndex)OldChildState.ParentIndex;

            BlockState.Remove(OldBrowsingIndex, Index);

            NodeTreeHelperBlockList.ReplaceInBlock(ChildBlock, Index, operation.NewNode);

            IWriteableBrowsingExistingBlockNodeIndex NewBrowsingIndex = CreateBrowsingNodeIndex(operation.NewNode, BlockIndex, Index);
            IWriteablePlaceholderNodeState           NewChildState    = (IWriteablePlaceholderNodeState)CreateNodeState(NewBrowsingIndex);

            BlockState.Insert(NewBrowsingIndex, Index, NewChildState);

            operation.Update(OldBrowsingIndex, NewBrowsingIndex, OldNode, NewChildState);
        }
Esempio n. 2
0
        /// <summary>
        /// Replaces a node.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void Replace(IWriteableReplaceOperation operation)
        {
            Debug.Assert(operation != null);

            int Index = operation.Index;

            Debug.Assert(Index >= 0 && Index < StateList.Count);

            INode ParentNode = Owner.Node;

            IWriteableNodeState OldChildState = StateList[Index];
            INode OldNode = OldChildState.Node;
            IWriteableBrowsingListNodeIndex OldBrowsingIndex = (IWriteableBrowsingListNodeIndex)OldChildState.ParentIndex;

            RemoveFromStateList(Index);

            NodeTreeHelperList.ReplaceNode(ParentNode, PropertyName, Index, operation.NewNode);

            IWriteableBrowsingListNodeIndex NewBrowsingIndex = CreateBrowsingNodeIndex(operation.NewNode, Index);
            IWriteablePlaceholderNodeState  NewChildState    = (IWriteablePlaceholderNodeState)CreateNodeState(NewBrowsingIndex);

            InsertInStateList(Index, NewChildState);

            operation.Update(OldBrowsingIndex, NewBrowsingIndex, OldNode, NewChildState);
        }
        private protected virtual void ClearOptional(IWriteableReplaceOperation operation)
        {
            INode ParentNode = Owner.Node;

            WriteableBrowsingOptionalNodeIndex OldBrowsingIndex = (WriteableBrowsingOptionalNodeIndex)ChildState.ParentIndex;
            INode OldNode = ChildState.Optional.HasItem ? ChildState.Node : null;

            NodeTreeHelperOptional.ClearOptionalChildNode(ParentNode, PropertyName);

            IWriteableBrowsingOptionalNodeIndex NewBrowsingIndex = CreateBrowsingNodeIndex();
            IWriteableOptionalNodeState         NewChildState    = (IWriteableOptionalNodeState)CreateNodeState(NewBrowsingIndex);

            SetChildState(NewChildState);

            operation.Update(OldBrowsingIndex, NewBrowsingIndex, OldNode, NewChildState);
        }
Esempio n. 4
0
        /// <summary>
        /// Replaces a node.
        /// </summary>
        /// <param name="operation">Details of the operation performed.</param>
        public virtual void Replace(IWriteableReplaceOperation operation)
        {
            Node ParentNode = Owner.Node;

            IWriteableBrowsingPlaceholderNodeIndex OldBrowsingIndex = (IWriteableBrowsingPlaceholderNodeIndex)ChildState.ParentIndex;
            IWriteablePlaceholderNodeState         OldChildState    = (IWriteablePlaceholderNodeState)ChildState;
            Node OldNode = OldChildState.Node;

            NodeTreeHelperChild.SetChildNode(ParentNode, PropertyName, operation.NewNode);

            IWriteableBrowsingPlaceholderNodeIndex NewBrowsingIndex = CreateBrowsingNodeIndex(operation.NewNode);
            IWriteablePlaceholderNodeState         NewChildState    = (IWriteablePlaceholderNodeState)CreateNodeState(NewBrowsingIndex);

            SetChildState(NewChildState);

            operation.Update(OldBrowsingIndex, NewBrowsingIndex, OldNode, NewChildState);
        }
        private protected virtual void ReplaceOptional(IWriteableReplaceOperation operation)
        {
            Node ParentNode = Owner.Node;

            IWriteableBrowsingOptionalNodeIndex OldBrowsingIndex = (IWriteableBrowsingOptionalNodeIndex)ChildState.ParentIndex;
            Node OldNode = ChildState.Node;

            if (operation.ClearNode)
            {
                NodeTreeHelperOptional.UnassignChildNode(ParentNode, PropertyName);
            }
            else
            {
                NodeTreeHelperOptional.SetOptionalChildNode(ParentNode, PropertyName, operation.NewNode);
            }

            IWriteableBrowsingOptionalNodeIndex NewBrowsingIndex = CreateBrowsingNodeIndex();
            IWriteableOptionalNodeState         NewChildState    = (IWriteableOptionalNodeState)CreateNodeState(NewBrowsingIndex);

            SetChildState(NewChildState);

            operation.Update(OldBrowsingIndex, NewBrowsingIndex, OldNode, NewChildState);
        }