private List <DataGridGroupInfo> BuildGroupPath()
        {
            DataGridVirtualizingCollectionViewGroup parent = this.Parent as DataGridVirtualizingCollectionViewGroup;

            if (parent == null)
            {
                return(new List <DataGridGroupInfo>());
            }

            DataGridVirtualizingCollectionViewBase collectionView = this.GetCollectionView();

            ObservableCollection <GroupDescription> groupDescriptions = collectionView.GroupDescriptions;

            int level = this.Level;

            Debug.Assert(this.Level != -1, "A DataGridCollectionViewGroupRoot should have returned a new List since its parent should have been null.");

            List <DataGridGroupInfo> groupPath = new List <DataGridGroupInfo>(parent.GroupPath);

            Debug.Assert(groupDescriptions.Count > level);

            if (groupDescriptions.Count > level)
            {
                groupPath.Add(new DataGridGroupInfo(groupDescriptions[level], this));
            }

            return(groupPath);
        }
        private void OnVirtualItemListCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            DataGridVirtualizingCollectionViewBase collectionView = this.GetCollectionView();

            lock (collectionView.DeferredOperationManager)
            {
                DeferredOperation deferredOperation = null;

                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Replace:
                {
                    deferredOperation = new DeferredOperation(DeferredOperation.DeferredOperationAction.Replace, -1, e.NewStartingIndex + m_startGlobalIndex,
                                                              e.NewItems, e.OldStartingIndex + m_startGlobalIndex, e.OldItems);
                    break;
                }

                case NotifyCollectionChangedAction.Reset:
                {
                    deferredOperation = new DeferredOperation(DeferredOperation.DeferredOperationAction.Refresh, -1, null);
                    break;
                }

                default:
                    throw new NotSupportedException(e.Action.ToString() + " is not a supported action.");
                }

                if (deferredOperation != null)
                {
                    collectionView.ExecuteOrQueueSourceItemOperation(deferredOperation);
                }
            }
        }
        private IQueryable FilterQueryable(IQueryable queryable)
        {
            // Filters a queryable to match this Group's clause.
            // This method does not apply the AutoFilter clauses or the FilterRow clauses.
            // It is the DataGridVirtualizingQueryableCollectionViewGroupRoot's job to do so on the
            // base queryable used as a base for all other queryables.

            if (queryable == null)
            {
                throw new ArgumentNullException("queryable");
            }

            int level = this.Level;

            DataGridVirtualizingCollectionViewBase collectionView = this.GetCollectionView();

            ObservableCollection <GroupDescription> groupDescriptions = collectionView.GroupDescriptions;

            Debug.Assert((groupDescriptions != null) && (level < groupDescriptions.Count));

            DataGridGroupDescription groupBy = groupDescriptions[level] as DataGridGroupDescription;

            Debug.Assert(groupBy != null);

            ParameterExpression sharedParameterExpression = queryable.CreateParameterExpression();

            Expression expression = queryable.CreateEqualExpression(sharedParameterExpression, groupBy.PropertyName, this.Name);

            return(queryable.WhereFilter(sharedParameterExpression, expression));
        }
Exemple #4
0
        internal override void ApplyExtraPropertiesToView(DataGridCollectionViewBase currentView)
        {
            base.ApplyExtraPropertiesToView(currentView);

            DataGridVirtualizingCollectionViewBase dataGridVirtualizingCollectionView = currentView as DataGridVirtualizingCollectionViewBase;

            dataGridVirtualizingCollectionView.PreemptivePageQueryRatio = this.PreemptivePageQueryRatio;
            dataGridVirtualizingCollectionView.CommitMode = this.CommitMode;
        }
    public static void RemoveListener( DataGridVirtualizingCollectionViewBase source, IWeakEventListener listener )
    {
      if( source == null )
        throw new ArgumentNullException( "source" );

      if( listener == null )
        throw new ArgumentNullException( "listener" );

      CurrentManager.ProtectedRemoveListener( source, listener );
    }
        private void RaiseCollectionViewOnCommitItems(VirtualPage dispatchedPage, AsyncCommitInfo dispatchedCommitInfo)
        {
            DataGridVirtualizingCollectionViewBase collectionView = this.CollectionView as DataGridVirtualizingCollectionViewBase;

            DataGridVirtualizingCollectionViewGroupBase collectionViewGroup =
                this.GetLinkedCollectionViewGroup(dispatchedPage.ParentVirtualList) as DataGridVirtualizingCollectionViewGroupBase;

            Debug.Assert((collectionViewGroup != null) && (collectionView != null));

            collectionView.OnCommitItems(dispatchedCommitInfo);
        }
        private VirtualList CreateNewVirtualList()
        {
            Debug.Assert(m_isBottomLevel);

            DataGridVirtualizingCollectionViewBase collectionView = this.GetCollectionView();

            DataGridPageManagerBase virtualPageManagerBase = collectionView.RootGroup.GetVirtualPageManager();

            VirtualList virtualItemList = new VirtualList(virtualPageManagerBase, m_virtualItemCount);

            virtualPageManagerBase.LinkVirtualListAndCollectionViewGroup(virtualItemList, this);

            return(virtualItemList);
        }
        public static void RemoveListener(DataGridVirtualizingCollectionViewBase source, IWeakEventListener listener)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }

            CurrentManager.ProtectedRemoveListener(source, listener);
        }
        private void EnsureProtectedVirtualItems()
        {
            if (m_protectedVirtualItems != null)
            {
                return;
            }

            DataGridVirtualizingCollectionViewBase collectionView = this.GetCollectionView();

            Debug.Assert(collectionView != null);

            if (m_isBottomLevel)
            {
                m_protectedVirtualItems = this.CreateNewVirtualList();
            }
            else
            {
                ObservableCollection <GroupDescription> groupDescriptions = collectionView.GroupDescriptions;

                int groupDescriptionCount = (groupDescriptions == null) ? 0 : groupDescriptions.Count;

                int nextLevel = m_level + 1;

                if (nextLevel > (groupDescriptionCount - 1))
                {
                    throw new DataGridInternalException("At attempt was made to retrieve child groups for a non-existing group description.");
                }

                GroupDescription subGroupBy = groupDescriptions[nextLevel];

                if (subGroupBy == null)
                {
                    throw new InvalidOperationException("TODDOOC: ");
                }

                bool nextLevelIsBottom = (nextLevel == (groupDescriptionCount - 1));

                m_protectedVirtualItems = this.QuerySubCollectionViewGroupList(subGroupBy, nextLevel, nextLevelIsBottom);
            }
        }
        private IQueryable SortQueryable(IQueryable queryable, bool reverseSort)
        {
            DataGridVirtualizingCollectionViewBase parentCollectionView = this.GetCollectionView();

            Debug.Assert(parentCollectionView != null);

            SortDescriptionCollection explicitSortDescriptions = parentCollectionView.SortDescriptions;

            ListSortDirection directionToUseForImplicitSortDescriptions = ListSortDirection.Ascending;

            if (explicitSortDescriptions.Count > 0)
            {
                directionToUseForImplicitSortDescriptions = explicitSortDescriptions[explicitSortDescriptions.Count - 1].Direction;
            }

            SortDescriptionCollection implicitSortDescriptions = new SortDescriptionCollection();

            DataGridVirtualizingQueryableCollectionViewGroupRoot groupRoot =
                parentCollectionView.RootGroup as DataGridVirtualizingQueryableCollectionViewGroupRoot;

            Debug.Assert(groupRoot != null);

            string[] primaryKeys = groupRoot.PrimaryKeys;

            if (primaryKeys != null)
            {
                for (int i = 0; i < primaryKeys.Length; i++)
                {
                    string primaryKey = primaryKeys[i];

                    Debug.Assert(!string.IsNullOrEmpty(primaryKey));

                    implicitSortDescriptions.Add(new SortDescription(primaryKey, directionToUseForImplicitSortDescriptions));
                }
            }

            return(queryable.OrderBy(implicitSortDescriptions, explicitSortDescriptions, reverseSort));
        }
 internal CommitItemsEventArgs(DataGridVirtualizingCollectionViewBase collectionView, AsyncCommitInfo asyncCommitInfo)
 {
     m_dataGridVirtualizingCollectionViewBase = collectionView;
     m_asyncCommitInfo = asyncCommitInfo;
 }
        internal override ObservableCollection <object> QuerySubCollectionViewGroupList(GroupDescription childGroupBy, int nextLevel, bool nextLevelIsBottom)
        {
            string childGroupByPropertyName = DataGridCollectionViewBase.GetPropertyNameFromGroupDescription(childGroupBy);

            if (String.IsNullOrEmpty(childGroupByPropertyName))
            {
                throw new NotSupportedException("Custom groups are not supported when using a DataGridVirtualizingQueryableCollectionView.");
            }

            DataGridVirtualizingCollectionViewBase collectionView = this.GetCollectionView();

            bool sortGroupBy = false;
            ListSortDirection groupByDirection = ListSortDirection.Ascending;

            foreach (SortDescription sortDescription in collectionView.SortDescriptions)
            {
                if (sortDescription.PropertyName == childGroupByPropertyName)
                {
                    sortGroupBy      = true;
                    groupByDirection = sortDescription.Direction;
                    break;
                }
            }

            IQueryable groupsAndCountsQueryable = this.Queryable.GetSubGroupsAndCountsQueryable(childGroupByPropertyName, sortGroupBy, groupByDirection);

            List <QueryableExtensions.IQueryableGroupNameCountPair> distinctValuesAndCounts = new List <QueryableExtensions.IQueryableGroupNameCountPair>();

            try
            {
                System.Collections.IEnumerator enumerator = groupsAndCountsQueryable.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    QueryableExtensions.IQueryableGroupNameCountPair current = enumerator.Current as QueryableExtensions.IQueryableGroupNameCountPair;

                    if (current != null)
                    {
                        distinctValuesAndCounts.Add(current);
                    }
                }
            }
            catch
            {
                // TimeOut exception on the connection or other.
                distinctValuesAndCounts.Clear();
            }


            // If we are not the bottom level, we should have subgroups.
            // However, if the connection timed out and the catch statement set the coundAndDistinctValues to an empty array,
            // then we shouldn't add anything.  We cannot reset on the spot since we might already be resetting.


            // Create the collection of sub CollectionViewGroups
            ObservableCollection <object> subCollectionViewGroupList = new ObservableCollection <object>();

            int runningCount        = this.StartGlobalIndex;
            int distinctValuesCount = distinctValuesAndCounts.Count;

            for (int i = 0; i < distinctValuesCount; i++)
            {
                QueryableExtensions.IQueryableGroupNameCountPair queryableGroupNameCountPair = distinctValuesAndCounts[i];

                subCollectionViewGroupList.Add(
                    new DataGridVirtualizingQueryableCollectionViewGroup(queryableGroupNameCountPair.GroupName, queryableGroupNameCountPair.Count, runningCount, this, nextLevel, nextLevelIsBottom));

                runningCount += queryableGroupNameCountPair.Count;
            }

            return(subCollectionViewGroupList);
        }
 internal CommitItemsEventArgs( DataGridVirtualizingCollectionViewBase collectionView, AsyncCommitInfo asyncCommitInfo )
 {
   m_dataGridVirtualizingCollectionViewBase = collectionView;
   m_asyncCommitInfo = asyncCommitInfo;
 }
 public DataGridPageManagerBase(DataGridVirtualizingCollectionViewBase collectionView)
     : base(collectionView.Dispatcher, collectionView.PageSize, collectionView.MaxRealizedItemCount, collectionView.PreemptivePageQueryRatio)
 {
     m_collectionView = collectionView;
     m_virtualListVSCollectionViewGroupDictionary = new Dictionary <VirtualList, DataGridVirtualizingCollectionViewGroupBase>();
 }