Esempio n. 1
0
        public override object GetAt(int index)
        {
            if (index < 0)
            {
                return(null);
            }

            if ((m_detailsMapping == null) ||
                (m_detailsMapping.Count == 0))
            {
                //If there are no details, call base (quicker)
                return(base.GetAt(index));
            }

            int masterIndex;
            int detailIndex;
            int detailNodeIndex;
            DetailGeneratorNode detailNode = this.GetDetailNodeForIndex(index, out masterIndex, out detailIndex, out detailNodeIndex);

            if (detailNode == null)
            {
                return(this.Items[masterIndex]);
            }

            return(detailNode.DetailGenerator.ItemFromIndex(detailIndex));
        }
Esempio n. 2
0
        public DetailGeneratorNode GetDetailNodeForIndex(int targetIndex, out int masterIndex, out int detailIndex, out int detailNodeIndex)
        {
            masterIndex     = -1;
            detailIndex     = -1;
            detailNodeIndex = -1;

            if ((m_detailsMapping == null) ||
                (m_detailsMapping.Count == 0))
            {
                masterIndex = targetIndex;
                return(null);
            }

            int runningDetailCount = 0;

            foreach (KeyValuePair <int, List <DetailGeneratorNode> > pair in m_detailsMapping)
            {
                List <DetailGeneratorNode> detailNodeList = pair.Value;
                int currentIndex = pair.Key;

                int runningIndex = (currentIndex + runningDetailCount);

                if (targetIndex < runningIndex)
                {
                    masterIndex = targetIndex - runningDetailCount;
                    return(null);
                }

                if (runningIndex == targetIndex)
                {
                    masterIndex = currentIndex;
                    return(null);
                }

                int count = detailNodeList.Count;
                for (int i = 0; i < count; i++)
                {
                    DetailGeneratorNode detailNode = detailNodeList[i];
                    int detailItemCount            = detailNode.ItemCount;

                    if (targetIndex <= (runningIndex + detailItemCount))
                    {
                        masterIndex     = currentIndex;
                        detailIndex     = targetIndex - runningIndex - 1;
                        detailNodeIndex = i;
                        return(detailNode);
                    }
                    else
                    {
                        runningDetailCount += detailItemCount;
                        runningIndex       += detailItemCount;
                    }
                }
            }

            masterIndex = targetIndex - runningDetailCount;
            return(null);
        }
Esempio n. 3
0
        public override int IndexOf(object item)
        {
            if ((m_detailsMapping == null) ||
                (m_detailsMapping.Count == 0))
            {
                return(base.IndexOf(item));
            }

            int tmpIndex = this.Items.IndexOf(item);

            if (tmpIndex != -1)
            {
                return(tmpIndex + this.CountDetailsBeforeDataIndex(tmpIndex));
            }

            int runningDetailCount = 0;

            foreach (KeyValuePair <int, List <DetailGeneratorNode> > pair in m_detailsMapping)
            {
                List <DetailGeneratorNode> detailNodeList = pair.Value;

                int currentIndex = pair.Key;
                int runningIndex = (currentIndex + runningDetailCount);

                int count = detailNodeList.Count;
                for (int i = 0; i < count; i++)
                {
                    DetailGeneratorNode detailNode = detailNodeList[i];
                    int detailIndex = detailNode.DetailGenerator.IndexFromItem(item);

                    if (detailIndex > -1)
                    {
                        return(runningIndex + detailIndex + 1);
                    }

                    int detailItemCount = detailNode.ItemCount;

                    runningDetailCount += detailItemCount;
                    runningIndex       += detailItemCount;
                }
            }

            return(-1);
        }
Esempio n. 4
0
        private static void ProcessItemsNodeBlockVisit(
            ItemsGeneratorNode itemsNode,
            DataGridContext sourceContext,
            int minIndex,
            int maxIndex,
            IDataGridContextVisitor visitor,
            DataGridContextVisitorType visitorType,
            bool visitDetails,
            bool containsDetails,
            int sourceDataItemIndex,
            ref int startSourceDataItemIndex,
            ref int endSourceDataItemIndex,
            ref bool stopVisit)
        {
            if (maxIndex < minIndex)
            {
                return;
            }

            int runningIndex = minIndex;

            sourceDataItemIndex += minIndex - itemsNode.CountDetailsBeforeGlobalIndex(minIndex);

            if (!containsDetails)
            {
                // If we contains no detail, we take a quick way out of it.
                if (startSourceDataItemIndex == -1)
                {
                    startSourceDataItemIndex = sourceDataItemIndex;
                }
                else
                {
                    if ((endSourceDataItemIndex + 1) != sourceDataItemIndex)
                    {
                        visitor.Visit(sourceContext, startSourceDataItemIndex, endSourceDataItemIndex, ref stopVisit);

                        if (stopVisit)
                        {
                            return;
                        }

                        startSourceDataItemIndex = sourceDataItemIndex;
                    }
                }

                endSourceDataItemIndex = sourceDataItemIndex + System.Math.Min(maxIndex - minIndex, itemsNode.Items.Count - 1);
                return;
            }

            int masterIndex;
            int detailStartIndex;
            int detailNodeIndex;

            while (runningIndex <= maxIndex)
            {
                DetailGeneratorNode detailNode = itemsNode.GetDetailNodeForIndex(runningIndex, out masterIndex, out detailStartIndex, out detailNodeIndex);

                if (detailNode != null)
                {
                    int detailEndIndex = System.Math.Min(detailNode.ItemCount - 1, detailStartIndex + (maxIndex - runningIndex));
                    sourceDataItemIndex -= detailStartIndex;
                    bool visitWasStopped;

                    (( IDataGridContextVisitable )detailNode.DetailGenerator).AcceptVisitor(
                        detailStartIndex, detailEndIndex, visitor, visitorType, visitDetails, out visitWasStopped);

                    stopVisit = stopVisit || visitWasStopped;

                    if (stopVisit)
                    {
                        break;
                    }

                    runningIndex += detailNode.ItemCount - detailStartIndex - 1;
                }
                else
                {
                    // set the first data index that will be visited for that items block
                    if (startSourceDataItemIndex == -1)
                    {
                        startSourceDataItemIndex = sourceDataItemIndex;
                        endSourceDataItemIndex   = sourceDataItemIndex;
                    }
                    else
                    {
                        if ((endSourceDataItemIndex + 1) != sourceDataItemIndex)
                        {
                            visitor.Visit(sourceContext, startSourceDataItemIndex, endSourceDataItemIndex, ref stopVisit);

                            if (stopVisit)
                            {
                                break;
                            }

                            startSourceDataItemIndex = sourceDataItemIndex;
                        }

                        endSourceDataItemIndex = sourceDataItemIndex;
                    }

                    sourceDataItemIndex++;
                }

                runningIndex++;
            }
        }
Esempio n. 5
0
        private static void ProcessItemsNodeVisit(
            ItemsGeneratorNode itemsNode,
            DataGridContext sourceContext,
            int minIndex,
            int maxIndex,
            IDataGridContextVisitor visitor,
            DataGridContextVisitorType visitorType,
            bool visitDetails,
            int sourceDataItemIndex,
            ref bool stopVisit)
        {
            int runningIndex = minIndex;

            sourceDataItemIndex += minIndex;

            int masterIndex;
            int detailStartIndex;
            int detailNodeIndex;

            while (runningIndex <= maxIndex)
            {
                DetailGeneratorNode detailNode = itemsNode.GetDetailNodeForIndex(runningIndex, out masterIndex, out detailStartIndex, out detailNodeIndex);

                if (detailNode != null)
                {
                    int detailEndIndex = System.Math.Min(detailNode.ItemCount - 1, detailStartIndex + (maxIndex - runningIndex));
                    sourceDataItemIndex -= detailStartIndex;

                    if (visitDetails)
                    {
                        bool visitWasStopped;

                        (( IDataGridContextVisitable )detailNode.DetailGenerator).AcceptVisitor(
                            detailStartIndex, detailEndIndex, visitor, visitorType, visitDetails, out visitWasStopped);

                        stopVisit = stopVisit || visitWasStopped;

                        if (stopVisit)
                        {
                            break;
                        }

                        runningIndex += detailNode.ItemCount - detailStartIndex - 1;
                    }
                }
                else
                {
                    if ((visitorType & DataGridContextVisitorType.Items) == DataGridContextVisitorType.Items)
                    {
                        object dataItem = itemsNode.GetAt(runningIndex);
                        visitor.Visit(sourceContext, sourceDataItemIndex, dataItem, ref stopVisit);

                        if (stopVisit)
                        {
                            break;
                        }
                    }

                    sourceDataItemIndex++;
                }

                runningIndex++;
            }
        }