Exemplo n.º 1
0
        /// <summary>
        /// Add an item to the desired subgroup(s) of the given group
        /// </summary>
        /// <param name="item">Item to add</param>
        /// <param name="group">Group to add item to</param>
        /// <param name="level">The level of grouping</param>
        /// <param name="loading">Whether we are currently loading</param>
        private void AddToSubgroups(object item, CollectionViewGroupInternal group, int level, bool loading)
        {
            object      name = this.GetGroupName(item, group.GroupBy, level);
            ICollection nameList;

            if (name == UseAsItemDirectly)
            {
                // the item belongs to the group itself (not to any subgroups)
                if (loading)
                {
                    group.Add(item);
                }
                else
                {
                    int localIndex = group.Insert(item, item, this.ActiveComparer);
                    int index      = group.LeafIndexFromItem(item, localIndex);
                    this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
                }
            }
            else if ((nameList = name as ICollection) == null)
            {
                // the item belongs to one subgroup
                this.AddToSubgroup(item, group, level, name, loading);
            }
            else
            {
                // the item belongs to multiple subgroups
                foreach (object o in nameList)
                {
                    this.AddToSubgroup(item, group, level, o, loading);
                }
            }
        }
Exemplo n.º 2
0
 private void AddToSubgroup(object item, CollectionViewGroupInternal group, int level, object name, bool loading)
 {
     CollectionViewGroupInternal internal2;
     int num = this._isDataInGroupOrder ? group.LastIndex : 0;
     int count = group.Items.Count;
     while (num < count)
     {
         internal2 = group.Items[num] as CollectionViewGroupInternal;
         if ((internal2 != null) && group.GroupBy.NamesMatch(internal2.Name, name))
         {
             group.LastIndex = num;
             this.AddToSubgroups(item, internal2, level + 1, loading);
             return;
         }
         num++;
     }
     internal2 = new CollectionViewGroupInternal(name, group);
     this.InitializeGroup(internal2, level + 1, item);
     if (loading)
     {
         group.Add(internal2);
         group.LastIndex = num;
     }
     else
     {
         group.Insert(internal2, item, this.ActiveComparer);
     }
     this.AddToSubgroups(item, internal2, level + 1, loading);
 }
Exemplo n.º 3
0
 private void AddToSubgroups(object item, CollectionViewGroupInternal group, int level, bool loading)
 {
     object name = this.GetGroupName(item, group.GroupBy, level);
     if (name == UseAsItemDirectly)
     {
         if (loading)
         {
             group.Add(item);
         }
         else
         {
             int index = group.Insert(item, item, this.ActiveComparer);
             int num2 = group.LeafIndexFromItem(item, index);
             this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(0, item, num2));
         }
     }
     else
     {
         ICollection is2 = name as ICollection;
         if (is2 == null)
         {
             this.AddToSubgroup(item, group, level, name, loading);
         }
         else
         {
             foreach (object obj3 in is2)
             {
                 this.AddToSubgroup(item, group, level, obj3, loading);
             }
         }
     }
 }
        private void InitializeGroup(CollectionViewGroupInternal group, GroupDescription parentDescription, int level)
        {
            GroupDescription groupDescription = this.GetGroupDescription((CollectionViewGroup)group, parentDescription, level);

            group.GroupBy = groupDescription;
            ObservableCollection <object> observableCollection = groupDescription != null ? groupDescription.GroupNames : (ObservableCollection <object>)null;

            if (observableCollection != null)
            {
                int index = 0;
                for (int count = observableCollection.Count; index < count; ++index)
                {
                    CollectionViewGroupInternal group1 = new CollectionViewGroupInternal(observableCollection[index], group);
                    this.InitializeGroup(group1, groupDescription, level + 1);
                    group.Add((object)group1);
                }
            }
            group.LastIndex = 0;
        }
Exemplo n.º 5
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        /// <summary>
        /// Add an item to the subgroup with the given name
        /// </summary>
        /// <param name="item">Item to add</param>
        /// <param name="group">Group to add item to</param>
        /// <param name="level">The level of grouping.</param>
        /// <param name="name">Name of subgroup to add to</param>
        /// <param name="loading">Whether we are currently loading</param>
        private void AddToSubgroup(object item, CollectionViewGroupInternal group, int level, object name, bool loading)
        {
            CollectionViewGroupInternal subgroup;
            int index = (this._isDataInGroupOrder) ? group.LastIndex : 0;

            // find the desired subgroup
            for (int n = group.Items.Count; index < n; ++index)
            {
                subgroup = group.Items[index] as CollectionViewGroupInternal;
                if (subgroup == null)
                {
                    continue;           // skip children that are not groups
                }

                if (group.GroupBy.NamesMatch(subgroup.Name, name))
                {
                    group.LastIndex = index;
                    this.AddToSubgroups(item, subgroup, level + 1, loading);
                    return;
                }
            }

            // the item didn't match any subgroups.  Create a new subgroup and add the item.
            subgroup = new CollectionViewGroupInternal(name, group);
            this.InitializeGroup(subgroup, level + 1, item);


            if (loading)
            {
                group.Add(subgroup);
                group.LastIndex = index;
            }
            else
            {
                // using insert will find the correct sort index to
                // place the subgroup, and will default to the last
                // position if no ActiveComparer is specified
                group.Insert(subgroup, item, this.ActiveComparer);
            }

            this.AddToSubgroups(item, subgroup, level + 1, loading);
        }
        private void AddToSubgroup(object item, LiveShapingItem lsi, CollectionViewGroupInternal group, int level, object name, bool loading)
        {
            int    index        = !loading || !this.IsDataInGroupOrder ? 0 : group.LastIndex;
            object groupNameKey = this.GetGroupNameKey(name, group);
            CollectionViewGroupInternal subgroupFromMap;

            if ((subgroupFromMap = group.GetSubgroupFromMap(groupNameKey)) != null && group.GroupBy.NamesMatch(subgroupFromMap.Name, name))
            {
                group.LastIndex = group.Items[index] == subgroupFromMap ? index : 0;
                this.AddToSubgroups(item, lsi, subgroupFromMap, level + 1, loading);
            }
            else
            {
                for (int count = group.Items.Count; index < count; ++index)
                {
                    CollectionViewGroupInternal viewGroupInternal = group.Items[index] as CollectionViewGroupInternal;
                    if (viewGroupInternal != null && group.GroupBy.NamesMatch(viewGroupInternal.Name, name))
                    {
                        group.LastIndex = index;
                        group.AddSubgroupToMap(groupNameKey, viewGroupInternal);
                        this.AddToSubgroups(item, lsi, viewGroupInternal, level + 1, loading);
                        return;
                    }
                }
                CollectionViewGroupInternal viewGroupInternal1 = new CollectionViewGroupInternal(name, group);
                this.InitializeGroup(viewGroupInternal1, group.GroupBy, level + 1);
                if (loading)
                {
                    group.Add((object)viewGroupInternal1);
                    group.LastIndex = index;
                }
                else
                {
                    group.Insert((object)viewGroupInternal1, item, this.ActiveComparer);
                }
                group.AddSubgroupToMap(groupNameKey, viewGroupInternal1);
                this.AddToSubgroups(item, lsi, viewGroupInternal1, level + 1, loading);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initialize the given group
        /// </summary>
        /// <param name="group">Group to initialize</param>
        /// <param name="level">The level of grouping</param>
        /// <param name="seedItem">The seed item to compare with to see where to insert</param>
        private void InitializeGroup(CollectionViewGroupInternal group, int level, object seedItem)
        {
            // set the group description for dividing the group into subgroups
            GroupDescription groupDescription = this.GetGroupDescription(group, 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);
                    this.InitializeGroup(subgroup, level + 1, seedItem);
                    group.Add(subgroup);
                }
            }

            group.LastIndex = 0;
        }
        private void AddToSubgroups(object item, LiveShapingItem lsi, CollectionViewGroupInternal group, int level, bool loading)
        {
            object groupName = this.GetGroupName(item, group.GroupBy, level);

            if (groupName == CollectionViewGroupRoot.UseAsItemDirectly)
            {
                if (lsi != null)
                {
                    lsi.AddParentGroup(group);
                }
                if (loading)
                {
                    group.Add(item);
                }
                else
                {
                    int index1 = group.Insert(item, item, this.ActiveComparer);
                    int index2 = group.LeafIndexFromItem(item, index1);
                    this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index2));
                }
            }
            else
            {
                ICollection collection;
                if ((collection = groupName as ICollection) == null)
                {
                    this.AddToSubgroup(item, lsi, group, level, groupName, loading);
                }
                else
                {
                    foreach (object name in (IEnumerable)collection)
                    {
                        this.AddToSubgroup(item, lsi, group, level, name, loading);
                    }
                }
            }
        }
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
        
        /// <summary>
        /// Add an item to the subgroup with the given name
        /// </summary>
        /// <param name="item">Item to add</param>
        /// <param name="group">Group to add item to</param>
        /// <param name="level">The level of grouping.</param>
        /// <param name="name">Name of subgroup to add to</param>
        /// <param name="loading">Whether we are currently loading</param>
        /// <param name="insertedBefore">The item to insert this item before,
        /// or <c>null</c> if the item should be added at the end.</param>
        private void AddToSubgroup(object item, CollectionViewGroupInternal group, int level, object name, bool loading, object insertedBefore)
        {
            CollectionViewGroupInternal subgroup;
            int index = (this._isDataInGroupOrder) ? group.LastIndex : 0;

            // find the desired subgroup
            for (int n = group.Items.Count; index < n; ++index)
            {
                subgroup = group.Items[index] as CollectionViewGroupInternal;
                if (subgroup == null)
                {
                    continue;           // skip children that are not groups
                }

                if (group.GroupBy.NamesMatch(subgroup.Name, name))
                {
                    group.LastIndex = index;
                    this.AddToSubgroups(item, subgroup, level + 1, loading, insertedBefore);
                    return;
                }
            }

            // the item didn't match any subgroups.  Create a new subgroup and add the item.
            subgroup = new CollectionViewGroupInternal(name, group);
            this.InitializeGroup(subgroup, level + 1, item);

            if (loading)
            {
                group.Add(subgroup);
                group.LastIndex = index;
            }
            else
            {
                if (insertedBefore != null && group.ItemCount > 0)
                {
                    index = 0;

                    // If we were given an item to insert before, find its index
                    // within the target group.  If it's not in the group, we'll
                    // get -1 back, which we'll translate into putting the item
                    // at the end of the list.
                    int itemIndex = group.LeafIndexOf(insertedBefore);

                    if (itemIndex == -1)
                    {
                        index = group.ItemCount;
                    }
                    else
                    {
                        // But if the item to be inserted before is within this
                        // group, then we need to find the correct group position
                        // for the insert.  Iterate through the groups, finding
                        // the correct insert position.
                        CollectionViewGroupInternal nextGroup = ((CollectionViewGroupInternal)group.Items[index]);

                        while (itemIndex >= nextGroup.ItemCount)
                        {
                            itemIndex -= nextGroup.ItemCount;

                            // Increment the index and set the next group
                            nextGroup = ((CollectionViewGroupInternal)group.Items[++index]);
                        }
                    }
                }

                group.Insert(subgroup, index);
            }

            this.AddToSubgroups(item, subgroup, level + 1, loading, insertedBefore);
        }
Exemplo n.º 10
0
 private void InitializeGroup(CollectionViewGroupInternal group, int level)
 {
     GroupDescription groupDescription = level < this.GroupDescriptions.Count ? this.GroupDescriptions[level] : (GroupDescription)null;
     group.GroupBy = groupDescription;
     ObservableCollection<object> observableCollection = groupDescription != null ? groupDescription.GroupNames : (ObservableCollection<object>)null;
     if (observableCollection != null)
     {
         int index = 0;
         for (int count = observableCollection.Count; index < count; ++index)
         {
             CollectionViewGroupInternal group1 = new CollectionViewGroupInternal(observableCollection[index], group);
             this.InitializeGroup(group1, level + 1);
             group.Add((object)group1);
         }
     }
     group.LastIndex = 0;
 }
Exemplo n.º 11
0
 private void AddToSubgroups(object item, CollectionViewGroupInternal group, int level, bool loading)
 {
     object groupName = this.GetGroupName(item, group.GroupBy, level);
     if (groupName == CollectionViewGroupRoot.UseAsItemDirectly)
     {
         if (loading)
         {
             group.Add(item);
         }
         else
         {
             int index1 = group.Insert(item, item, this.ActiveComparer);
             int index2 = group.LeafIndexFromItem(item, index1);
             this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index2));
         }
     }
     else
     {
         ICollection collection;
         if ((collection = groupName as ICollection) == null)
         {
             this.AddToSubgroup(item, group, level, groupName, loading);
         }
         else
         {
             foreach (object name in (IEnumerable)collection)
             {
                 this.AddToSubgroup(item, group, level, name, loading);
             }
         }
     }
 }
        // add an item to the desired subgroup(s) of the given group
        void AddToSubgroups(object item, LiveShapingItem lsi, CollectionViewGroupInternal group, int level, bool loading)
        {
            object name = GetGroupName(item, group.GroupBy, level);
            ICollection nameList;

            if (name == UseAsItemDirectly)
            {
                // the item belongs to the group itself (not to any subgroups)
                if (lsi != null)
                {
                    lsi.AddParentGroup(group);
                }

                if (loading)
                {
                    group.Add(item);
                }
                else
                {
                    int localIndex = group.Insert(item, item, ActiveComparer);
                    int index = group.LeafIndexFromItem(item, localIndex);
                    OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
                }
            }
            else if ((nameList = name as ICollection) == null)
            {
                // the item belongs to one subgroup
                AddToSubgroup(item, lsi, group, level, name, loading);
            }
            else
            {
                // the item belongs to multiple subgroups
                foreach (object o in nameList)
                {
                    AddToSubgroup(item, lsi, group, level, o, loading);
                }
            }
        }
Exemplo n.º 13
0
 private void InitializeGroup(CollectionViewGroupInternal group, int level, object seedItem)
 {
     GroupDescription groupDescription = this.GetGroupDescription(group, level);
     group.GroupBy = groupDescription;
     ObservableCollection<object> observables = (groupDescription != null) ? groupDescription.get_GroupNames() : null;
     if (observables != null)
     {
         int num = 0;
         int count = observables.Count;
         while (num < count)
         {
             CollectionViewGroupInternal internal2 = new CollectionViewGroupInternal(observables[num], group);
             this.InitializeGroup(internal2, level + 1, seedItem);
             group.Add(internal2);
             num++;
         }
     }
     group.LastIndex = 0;
 }
        // add an item to the subgroup with the given name
        void AddToSubgroup(object item, LiveShapingItem lsi, CollectionViewGroupInternal group, int level, object name, bool loading)
        {
            CollectionViewGroupInternal subgroup;
            int index = (loading && IsDataInGroupOrder) ? group.LastIndex : 0;

            // find the desired subgroup using the map
            object groupNameKey = GetGroupNameKey(name, group);
            if (((subgroup = group.GetSubgroupFromMap(groupNameKey) as CollectionViewGroupInternal) != null) &&
                group.GroupBy.NamesMatch(subgroup.Name, name))
            {
                // Try best to set the LastIndex. If not possible reset it to 0.
                group.LastIndex = (group.Items[index] == subgroup ? index : 0);

                // Recursively call the AddToSubgroups method on subgroup.
                AddToSubgroups(item, lsi, subgroup, level + 1, loading);
                return;
            }

            // find the desired subgroup using linear search
            for (int n = group.Items.Count; index < n; ++index)
            {
                subgroup = group.Items[index] as CollectionViewGroupInternal;
                if (subgroup == null)
                    continue;           // skip children that are not groups

                if (group.GroupBy.NamesMatch(subgroup.Name, name))
                {
                    group.LastIndex = index;

                    // Update the name to subgroup map on the group.
                    group.AddSubgroupToMap(groupNameKey, subgroup);

                    // Recursively call the AddToSubgroups method on subgroup.
                    AddToSubgroups(item, lsi, subgroup, level+1, loading);
                    return;
                }
            }

            // the item didn't match any subgroups.  Create a new subgroup and add the item.
            subgroup = new CollectionViewGroupInternal(name, group);
            InitializeGroup(subgroup, group.GroupBy, level+1);

            if (loading)
            {
                group.Add(subgroup);
                group.LastIndex = index;
            }
            else
            {
                group.Insert(subgroup, item, ActiveComparer);
            }

            // Update the name to subgroup map on the group.
            group.AddSubgroupToMap(groupNameKey, subgroup);

            // Recursively call the AddToSubgroups method on subgroup.
            AddToSubgroups(item, lsi, subgroup, level+1, loading);
        }
        /// <summary>
        /// Add an item to the desired subgroup(s) of the given group
        /// </summary>
        /// <param name="item">Item to add</param>
        /// <param name="group">Group to add item to</param>
        /// <param name="level">The level of grouping</param>
        /// <param name="loading">Whether we are currently loading</param>
        /// <param name="insertedBefore">The item to insert this item before,
        /// or <c>null</c> if the item should be added at the end.</param>
        private void AddToSubgroups(object item, CollectionViewGroupInternal group, int level, bool loading, object insertedBefore)
        {
            object name = this.GetGroupName(item, group.GroupBy, level);
            ICollection nameList;

            if (name == UseAsItemDirectly)
            {
                // the item belongs to the group itself (not to any subgroups)
                if (loading)
                {
                    group.Add(item);
                }
                else
                {
                    int localIndex = -1;

                    // If we were given an item to insert before, find its index
                    // within the target group.  If it's not in the group, we'll
                    // get -1 back, which we'll translate into putting the item
                    // at the end of the list.
                    if (insertedBefore != null)
                    {
                        localIndex = group.LeafIndexOf(insertedBefore);
                    }

                    if (localIndex == -1)
                    {
                        localIndex = group.ItemCount;
                    }

                    group.Insert(item, localIndex);
                    int index = group.LeafIndexFromItem(item, localIndex);
                    this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
                }
            }
            else if ((nameList = name as ICollection) == null)
            {
                // the item belongs to one subgroup
                this.AddToSubgroup(item, group, level, name, loading, insertedBefore);
            }
            else
            {
                // the item belongs to multiple subgroups
                foreach (object o in nameList)
                {
                    this.AddToSubgroup(item, group, level, o, loading, insertedBefore);
                }
            }
        }
Exemplo n.º 16
0
 private void AddToSubgroup(object item, CollectionViewGroupInternal group, int level, object name, bool loading)
 {
     int index = 0;
     for (int count = group.Items.Count; index < count; ++index)
     {
         CollectionViewGroupInternal group1 = group.Items[index] as CollectionViewGroupInternal;
         if (group1 != null && group.GroupBy.NamesMatch(group1.Name, name))
         {
             group.LastIndex = index;
             this.AddToSubgroups(item, group1, level + 1, loading);
             return;
         }
     }
     CollectionViewGroupInternal group2 = new CollectionViewGroupInternal(name, group);
     this.InitializeGroup(group2, level + 1);
     if (loading)
     {
         group.Add((object)group2);
         group.LastIndex = index;
     }
     else
     {
         group.Insert((object)group2, item, this.ActiveComparer);
     }
     this.AddToSubgroups(item, group2, level + 1, loading);
 }
        /// <summary>
        /// Initialize the given group
        /// </summary>
        /// <param name="group">Group to initialize</param>
        /// <param name="level">The level of grouping</param>
        /// <param name="seedItem">The seed item to compare with to see where to insert</param>
        private void InitializeGroup(CollectionViewGroupInternal group, int level, object seedItem)
        {
            // set the group description for dividing the group into subgroups
            GroupDescription groupDescription = this.GetGroupDescription(group, 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);
                    this.InitializeGroup(subgroup, level + 1, seedItem);
                    group.Add(subgroup);
                }
            }

            group.LastIndex = 0;
        }
Exemplo n.º 18
0
        // add an item to the subgroup with the given name 
        void AddToSubgroup(object item, CollectionViewGroupInternal group, int level, object name, bool loading)
        { 
            CollectionViewGroupInternal subgroup;
            int index = (loading && IsDataInGroupOrder) ? group.LastIndex : 0;

            // find the desired subgroup 
            for (int n=group.Items.Count;  index < n;  ++index)
            { 
                subgroup = group.Items[index] as CollectionViewGroupInternal; 
                if (subgroup == null)
                    continue;           // skip children that are not groups 

                if (group.GroupBy.NamesMatch(subgroup.Name, name))
                {
                    group.LastIndex = index; 
                    AddToSubgroups(item, subgroup, level+1, loading);
                    return; 
                } 
            }
 
            // the item didn't match any subgroups.  Create a new subgroup and add the item.
            subgroup = new CollectionViewGroupInternal(name, group);
            InitializeGroup(subgroup, group.GroupBy, level+1);
 
            if (loading)
            { 
                group.Add(subgroup); 
                group.LastIndex = index;
            } 
            else
            {
                group.Insert(subgroup, item, ActiveComparer);
            } 

            AddToSubgroups(item, subgroup, level+1, loading); 
        }