internal override ObservableCollection<object> QuerySubCollectionViewGroupList( GroupDescription subGroupBy, int nextLevel, bool nextLevelIsBottom )
    {
      DataGridVirtualizingCollectionView collectionView = this.GetCollectionView() as DataGridVirtualizingCollectionView;

      Debug.Assert( collectionView != null );

      List<GroupNameCountPair> subGroupInfos = collectionView.OnQueryGroups( this );
      int subGroupCount = subGroupInfos.Count;

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

      int runningCount = this.StartGlobalIndex;
      for( int i = 0; i < subGroupCount; i++ )
      {
        object subGroupName = subGroupInfos[ i ].Name;
        int subGroupItemCount = subGroupInfos[ i ].ItemCount;

        subCollectionViewGroupList.Add(
          new DataGridVirtualizingCollectionViewGroup( subGroupName, subGroupItemCount, runningCount, this, nextLevel, nextLevelIsBottom ) );

        runningCount += subGroupItemCount;
      }

      return subCollectionViewGroupList;
    }
    internal QueryGroupsEventArgs( 
      DataGridVirtualizingCollectionView collectionView, 
      DataGridVirtualizingCollectionViewGroup parentGroup, 
      GroupDescription childGroupDescription )
    {
      m_dataGridVirtualizingCollectionView = collectionView;
      m_readonlyGroupPath = parentGroup.GroupPath.AsReadOnly();
      m_childGroupDescription = childGroupDescription;
      this.ChildGroupPropertyName = DataGridCollectionViewBase.GetPropertyNameFromGroupDescription( childGroupDescription );

      m_sortDirection = SortDirection.None;

      SortDescriptionCollection sortDescriptions = m_dataGridVirtualizingCollectionView.SortDescriptions;

      int sortDescriptionCount = ( sortDescriptions == null ) ? 0 : sortDescriptions.Count;

      for( int i = 0; i < sortDescriptions.Count ; i++ )
      {
        SortDescription sortDescription = sortDescriptions[ i ];

        if( string.Equals( sortDescription.PropertyName, this.ChildGroupPropertyName ) )
        {
          m_sortDirection = ( sortDescription.Direction == ListSortDirection.Ascending ) ? SortDirection.Ascending : SortDirection.Descending;
          break;
        }
      }

      m_childGroupNameCountPairs = new List<GroupNameCountPair>();
    }
    internal GroupLevelDescription( GroupDescription groupDescription, string fieldName )
    {
      if( groupDescription == null )
        throw new DataGridInternalException( "GroupDescription cannot be null." );

      m_groupDescription = groupDescription;
      m_fieldName = fieldName;
    }
Esempio n. 4
0
    internal DataGridGroupInfo( GroupDescription groupDescription, CollectionViewGroup collectionViewGroup )
    {
      if( groupDescription == null )
        throw new ArgumentNullException( "groupDescription" );

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

      this.GroupDescription = groupDescription;
      this.PropertyName = DataGridCollectionViewBase.GetPropertyNameFromGroupDescription( groupDescription );
      this.Value = collectionViewGroup.Name;
    }
    internal static string GetPropertyNameFromGroupDescription( GroupDescription groupDescription )
    {
      PropertyGroupDescription propertyGroupDescription = groupDescription as PropertyGroupDescription;

      if( propertyGroupDescription != null )
        return propertyGroupDescription.PropertyName;

      DataGridGroupDescription dataGridGroupDescription = groupDescription as DataGridGroupDescription;

      if( dataGridGroupDescription != null )
        return dataGridGroupDescription.PropertyName;

      return null;
    }
    internal LateGroupLevelDescription( GroupDescription groupDescription, IEnumerable<GroupLevelDescription> groupLevelDescriptions )
    {
      if( groupDescription == null )
        throw new ArgumentNullException( "groupDescription" );

      var finder = new GroupLevelDescriptionFinder( groupDescription, groupLevelDescriptions );

      m_groupDescription = groupDescription;
      m_groupLevelDescription = finder.GroupLevelDescription;

      if( m_groupLevelDescription == null )
      {
        m_finder = finder;
        m_finder.PropertyChanged += new PropertyChangedEventHandler( this.OnGroupLevelDescriptionFound );
      }
      else
      {
        finder.Dispose();

        PropertyChangedEventManager.AddListener( m_groupLevelDescription, this, string.Empty );
      }
    }
    internal void SetSubGroupBy( GroupDescription groupBy )
    {
      bool oldIsBottomLevel = this.IsBottomLevel;
      m_subGroupBy = groupBy;

      if( m_subGroupBy != null )
      {
        if( m_groupsDictionary == null )
          m_groupsDictionary = new Hashtable();
      }

      if( oldIsBottomLevel != this.IsBottomLevel )
        this.OnPropertyChanged( new PropertyChangedEventArgs( "IsBottomLevel" ) );
    }
 public virtual GroupConfiguration SelectGroupConfiguration( int groupLevel, CollectionViewGroup collectionViewGroup, GroupDescription groupDescription )
 {
   return null;
 }
        /// <summary>
        /// Determines whether the <paramref name="groupDescription"/> and <paramref name="groupDescriptor"/> are equivalent.
        /// </summary>
        /// <param name="groupDescription">The description to compare</param>
        /// <param name="groupDescriptor">The descriptor to compare</param>
        /// <returns><c>true</c> if the two are equivalent</returns>
        private static bool AreEquivalent(GroupDescription groupDescription, GroupDescriptor groupDescriptor)
        {
            Debug.Assert((groupDescription != null) && (groupDescriptor != null), "Both should be non-null.");

            PropertyGroupDescription propertyGroupDescription = groupDescription as PropertyGroupDescription;
            if (propertyGroupDescription == null)
            {
                return false;
            }

            return (propertyGroupDescription.PropertyName == groupDescriptor.PropertyPath);
        }
 private void UpdateGrouping( GroupDescription groupDescription )
 {
     GroupDescriptions.Clear ();
     if ( groupDescription != null )
     {
         GroupDescriptions.Add ( groupDescription );
     }
     if ( View != null )
     {
         View.Refresh ();
     }
 }
      private static bool TryFind( IEnumerable<GroupLevelDescription> collection, GroupDescription description, out GroupLevelDescription result )
      {
        if( ( collection == null ) || ( description == null ) )
        {
          result = null;
        }
        else
        {
          result = collection.Where( item => ( item.GroupDescription == description ) ).FirstOrDefault();
        }

        return ( result != null );
      }
 /// <summary>
 /// Synchronizes the group descriptors collection to the group descriptions collection.
 /// </summary>
 /// <param name="description">The description that changed</param>
 /// <param name="e">The property change event</param>
 private void HandleGroupDescriptionChanged(GroupDescription description, PropertyChangedEventArgs e)
 {
     this._ignoreChanges = true;
     try
     {
         // We have to reset when the collections were not equal before the change
         if (this._sourceCollection.Count != this._descriptionCollection.Count)
         {
             GroupCollectionManager.ResetToGroupDescriptions(this._descriptionCollection, this._sourceCollection);
         }
         else
         {
             int index = this._descriptionCollection.IndexOf(description);
             this._sourceCollection[index] = GroupCollectionManager.GetDescriptorFromDescription(description);
         }
     }
     finally
     {
         this._ignoreChanges = false;
     }
 }
        /// <summary>
        /// Initializes the group descriptions
        /// </summary>
        internal void Initialize()
        {
            if (topLevelGroupDescription == null)
            {
                topLevelGroupDescription = new TopLevelGroupDescription();
            }

            this.InitializeGroup(this, 0, null);
        }
    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 abstract ObservableCollection<object> QuerySubCollectionViewGroupList( GroupDescription subGroupBy, int nextLevel, bool nextLevelIsBottom );
        // return the description of how to divide the given group into subgroups
        GroupDescription GetGroupDescription(CollectionViewGroup group, GroupDescription parentDescription, int level)
        {
            GroupDescription result = null;
            if (group == this)
            {
                group = null;       // users don't see the synthetic group
            }

            if (parentDescription != null)
            {
#if GROUPDESCRIPTION_HAS_SUBGROUP
                // a. Use the parent description's subgroup description
                result = parentDescription.Subgroup;
#endif // GROUPDESCRIPTION_HAS_SUBGROUP

#if GROUPDESCRIPTION_HAS_SELECTOR
                // b. Call the parent description's selector
                if (result == null && parentDescription.SubgroupSelector != null)
                {
                    result = parentDescription.SubgroupSelector(group, level);
                }
#endif // GROUPDESCRIPTION_HAS_SELECTOR
            }

            // c. Call the global chooser
            if (result == null && GroupBySelector != null)
            {
                result = GroupBySelector(group, level);
            }

            // d. Use the global array
            if (result == null && level < GroupDescriptions.Count)
            {
                result = GroupDescriptions[level];
            }

            return result;
        }
        // Initialize the given group
        void InitializeGroup(CollectionViewGroupInternal group, GroupDescription parentDescription, int level)
        {
            // set the group description for dividing the group into subgroups
            GroupDescription groupDescription = GetGroupDescription(group, parentDescription, level);
            group.GroupBy = groupDescription;

            // create subgroups for each of the explicit names
            ObservableCollection<object> explicitNames =
                        (groupDescription != null) ? groupDescription.GroupNames : null;
            if (explicitNames != null)
            {
                for (int k=0, n=explicitNames.Count;  k<n;  ++k)
                {
                    CollectionViewGroupInternal subgroup = new CollectionViewGroupInternal(explicitNames[k], group);
                    InitializeGroup(subgroup, groupDescription, level+1);
                    group.Add(subgroup);
                }
            }

            group.LastIndex = 0;
        }
Esempio n. 18
0
    internal void ClearGroup()
    {
      m_groupDescription = null;
      m_collectionViewGroup = null;
      m_propertyChanged = null;

      this.DataGridContext = null;
      this.GeneratorNode = null;
      this.GroupLevelDescription = null;
    }
      internal GroupLevelDescriptionFinder( GroupDescription groupDescription, IEnumerable<GroupLevelDescription> groupLevelDescriptions )
      {
        if( groupDescription == null )
          throw new ArgumentNullException( "groupDescription" );

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

        if( !GroupLevelDescriptionFinder.TryFind( groupLevelDescriptions, groupDescription, out m_groupLevelDescription ) )
        {
          m_groupDescription = groupDescription;
          m_groupLevelDescriptions = groupLevelDescriptions;

          this.RegisterCollectionChanged( ( INotifyCollectionChanged )groupLevelDescriptions );
        }
      }
 /// <summary>
 /// Get the group name(s) for the given item
 /// </summary>
 /// <param name="item">Item to get group name for</param>
 /// <param name="groupDescription">GroupDescription for the group</param>
 /// <param name="level">The level of grouping</param>
 /// <returns>Group names for the specified item</returns>
 private object GetGroupName(object item, GroupDescription groupDescription, int level)
 {
     if (groupDescription != null)
     {
         return groupDescription.GroupNameFromItem(item, level, this.Culture);
     }
     else
     {
         return UseAsItemDirectly;
     }
 }
 /// <summary>
 /// Returns a <see cref="GroupDescriptor"/> equivalent to the specified description
 /// </summary>
 /// <param name="groupDescription">The description to get a descriptor from</param>
 /// <returns>A <see cref="GroupDescriptor"/> equivalent to the specified description</returns>
 /// <exception cref="InvalidOperationException"> is thrown if the description is not a
 /// <see cref="PropertyGroupDescription"/>.
 /// </exception>
 private static GroupDescriptor GetDescriptorFromDescription(GroupDescription groupDescription)
 {
     PropertyGroupDescription propertyGroupDescription = groupDescription as PropertyGroupDescription;
     if (propertyGroupDescription == null)
     {
         throw new InvalidOperationException(DomainDataSourceResources.RequiresPropertyGroupDescription);
     }
     return new GroupDescriptor(propertyGroupDescription.PropertyName);
 }