Example #1
0
 // Methods
 public ListCollectionView(IList list)
     : base(list)
 {
     this._internalList = list;
     if (this.InternalList.Count == 0)
     {
         base.SetCurrent(null, -1, 0);
     }
     else
     {
         base.SetCurrent(this.InternalList[0], 0, 1);
     }
     this._group = new CollectionViewGroupRoot(this);
     this._group.GroupDescriptionChanged += new EventHandler(this.OnGroupDescriptionChanged);
     this._group.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnGroupChanged);
     this._group.GroupDescriptions.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnGroupByChanged);
 }
Example #2
0
 public PagedCollectionView(IEnumerable source, bool isDataSorted, bool isDataInGroupOrder)
 {
     NotifyCollectionChangedEventHandler handler = null;
     this._cachedPageIndex = -1;
     this._currentChangedMonitor = new SimpleMonitor();
     this._flags = CollectionViewFlags.ShouldProcessCollectionChanged;
     this._pageIndex = -1;
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     this._sourceCollection = source;
     this.SetFlag(CollectionViewFlags.IsDataSorted, isDataSorted);
     this.SetFlag(CollectionViewFlags.IsDataInGroupOrder, isDataInGroupOrder);
     this._temporaryGroup = new CollectionViewGroupRoot(this, isDataInGroupOrder);
     this._group = new CollectionViewGroupRoot(this, false);
     this._group.GroupDescriptionChanged += new EventHandler(this.OnGroupDescriptionChanged);
     this._group.GroupDescriptions.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnGroupByChanged);
     this.CopySourceToInternalList();
     this._trackingEnumerator = source.GetEnumerator();
     if (this._internalList.Count > 0)
     {
         this.SetCurrent(this._internalList[0], 0, 1);
     }
     else
     {
         this.SetCurrent(null, -1, 0);
     }
     this.SetFlag(CollectionViewFlags.CachedIsEmpty, this.Count == 0);
     this._pollForChanges = !(source is INotifyCollectionChanged);
     if (!this._pollForChanges)
     {
         if (handler == null)
         {
             handler = delegate (object sender, NotifyCollectionChangedEventArgs args) {
                 this.ProcessCollectionChanged(args);
             };
         }
         (source as INotifyCollectionChanged).CollectionChanged += handler;
     }
 }
 /// <summary>
 /// Sets our group to a new instance of a
 /// CollectionViewGroupRoot being passed in
 /// and resets the index.
 /// </summary>
 /// <param name="group">CollectionViewGroupRoot used to compare on</param>
 internal void ResetGroup(CollectionViewGroupRoot group)
 {
     this._group = group;
     this._index = 0;
 }
 /// <summary>
 /// Constructor for the CollectionViewGroupComparer that takes
 /// in an CollectionViewGroupRoot.
 /// </summary>
 /// <param name="group">CollectionViewGroupRoot used to compare on</param>
 internal CollectionViewGroupComparer(CollectionViewGroupRoot group)
 {
     this.ResetGroup(group);
 }
        /// <summary>
        /// Use the GroupDescriptions to place items into their respective groups.
        /// Because of the fact that we have paging, it is possible that we are only
        /// going to need a subset of the items to be displayed. However, before we 
        /// actually group the entire collection, we can't display the items in the
        /// correct order. We therefore want to just create a temporary group with
        /// the entire collection, and then using this data we can create the group
        /// that is exposed with just the items we need.
        /// </summary>
        private void PrepareTemporaryGroups()
        {
            this._temporaryGroup = new CollectionViewGroupRoot(this, this.CheckFlag(CollectionViewFlags.IsDataInGroupOrder));

            foreach (GroupDescription gd in this._group.GroupDescriptions)
            {
                this._temporaryGroup.GroupDescriptions.Add(gd);
            }

            this._temporaryGroup.Initialize();

            // set to false so that we access internal collection items
            // instead of the group items, as they have been cleared
            this._isGrouping = false;

            if (this._temporaryGroup.GroupDescriptions.Count > 0)
            {
                for (int num = 0, count = this._internalList.Count; num < count; ++num)
                {
                    object item = this._internalList[num];
                    if (item != null && (!this.IsAddingNew || !object.Equals(this.CurrentAddItem, item)))
                    {
                        this._temporaryGroup.AddToSubgroups(item, true /*loading*/);
                    }
                }
                if (this.IsAddingNew)
                {
                    this._temporaryGroup.InsertSpecialItem(this._temporaryGroup.Items.Count, this.CurrentAddItem, true);
                }
            }

            this._isGrouping = this._temporaryGroup.GroupBy != null;

            // reset the grouping comparer
            this.PrepareGroupingComparer(this._temporaryGroup);
        }
 /// <summary>
 /// Sets up the ActiveComparer for the CollectionViewGroupRoot specified
 /// </summary>
 /// <param name="groupRoot">The CollectionViewGroupRoot</param>
 private void PrepareGroupingComparer(CollectionViewGroupRoot groupRoot)
 {
     if (groupRoot == this._temporaryGroup || this.PageSize == 0)
     {
         CollectionViewGroupInternal.ListComparer listComparer = groupRoot.ActiveComparer as CollectionViewGroupInternal.ListComparer;
         if (listComparer != null)
         {
             listComparer.ResetList(this.InternalList);
         }
         else
         {
             groupRoot.ActiveComparer = new CollectionViewGroupInternal.ListComparer(this.InternalList);
         }
     }
     else if (groupRoot == this._group)
     {
         // create the new comparer based on the current _temporaryGroup
         groupRoot.ActiveComparer = new CollectionViewGroupInternal.CollectionViewGroupComparer(this._temporaryGroup);
     }
 }
        public PagedCollectionView(IEnumerable source, bool isDataSorted, bool isDataInGroupOrder)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            this._sourceCollection = source;

            this.SetFlag(CollectionViewFlags.IsDataSorted, isDataSorted);
            this.SetFlag(CollectionViewFlags.IsDataInGroupOrder, isDataInGroupOrder);

            this._temporaryGroup = new CollectionViewGroupRoot(this, isDataInGroupOrder);
            this._group = new CollectionViewGroupRoot(this, false);
            this._group.GroupDescriptionChanged += new EventHandler(this.OnGroupDescriptionChanged);
            this._group.GroupDescriptions.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnGroupByChanged);

            this.CopySourceToInternalList();
            this._trackingEnumerator = source.GetEnumerator();

            // set currency
            if (this._internalList.Count > 0)
            {
                this.SetCurrent(this._internalList[0], 0, 1);
            }
            else
            {
                this.SetCurrent(null, -1, 0);
            }

            // Set flag for whether the collection is empty
            this.SetFlag(CollectionViewFlags.CachedIsEmpty, this.Count == 0);

            // If the source doesn't raise collection change events, try to
            // detect changes by polling the enumerator
            this._pollForChanges = !(source is INotifyCollectionChanged);

            // If we implement INotifyCollectionChanged
            if (!this._pollForChanges)
            {
                (source as INotifyCollectionChanged).CollectionChanged += new NotifyCollectionChangedEventHandler(delegate(object sender, NotifyCollectionChangedEventArgs args) { this.ProcessCollectionChanged(args); });
            }
        }
Example #8
0
 private void PrepareTemporaryGroups()
 {
     this._temporaryGroup = new CollectionViewGroupRoot(this, this.CheckFlag(CollectionViewFlags.IsDataInGroupOrder));
     foreach (GroupDescription description in this._group.GroupDescriptions)
     {
         this._temporaryGroup.GroupDescriptions.Add(description);
     }
     this._temporaryGroup.Initialize();
     this._isGrouping = false;
     if (this._temporaryGroup.GroupDescriptions.Count > 0)
     {
         int num = 0;
         int count = this._internalList.Count;
         while (num < count)
         {
             object objB = this._internalList[num];
             if ((objB != null) && (!this.IsAddingNew || !object.Equals(this.CurrentAddItem, objB)))
             {
                 this._temporaryGroup.AddToSubgroups(objB, true);
             }
             num++;
         }
         if (this.IsAddingNew)
         {
             this._temporaryGroup.InsertSpecialItem(this._temporaryGroup.Items.Count, this.CurrentAddItem, true);
         }
     }
     this._isGrouping = this._temporaryGroup.GroupBy != null;
     this.PrepareGroupingComparer(this._temporaryGroup);
 }
Example #9
0
 private void PrepareGroupingComparer(CollectionViewGroupRoot groupRoot)
 {
     if ((groupRoot == this._temporaryGroup) || (this.PageSize == 0))
     {
         CollectionViewGroupInternal.ListComparer activeComparer = groupRoot.ActiveComparer as CollectionViewGroupInternal.ListComparer;
         if (activeComparer != null)
         {
             activeComparer.ResetList(this.InternalList);
         }
         else
         {
             groupRoot.ActiveComparer = new CollectionViewGroupInternal.ListComparer(this.InternalList);
         }
     }
     else if (groupRoot == this._group)
     {
         groupRoot.ActiveComparer = new CollectionViewGroupInternal.CollectionViewGroupComparer(this._temporaryGroup);
     }
 }
Example #10
0
 /// <summary>
 /// Sets our group to a new instance of a
 /// CollectionViewGroupRoot being passed in
 /// and resets the index.
 /// </summary>
 /// <param name="group">CollectionViewGroupRoot used to compare on</param>
 internal void ResetGroup(CollectionViewGroupRoot group)
 {
     this._group = group;
     this._index = 0;
 }
Example #11
0
 /// <summary>
 /// Constructor for the CollectionViewGroupComparer that takes
 /// in an CollectionViewGroupRoot.
 /// </summary>
 /// <param name="group">CollectionViewGroupRoot used to compare on</param>
 internal CollectionViewGroupComparer(CollectionViewGroupRoot group)
 {
     this.ResetGroup(group);
 }