Exemplo n.º 1
0
        internal Group CreateGroupByName(object groupName, IGroupFactory groupFactor)
        {
            if (groupName == null)
            {
                groupName = NullValue.Instance;
            }

            Group group;

            if (!this.GroupsByName.TryGetValue(groupName, out group))
            {
                group = groupFactor.CreateGroup(groupName);
                group.InternalParent = this;
                this.GroupsByName.Add(groupName, group);
                this.InsertItem(-1, group, null);
            }

            return(group);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method should be used only after TryGetGroup returns false.
        /// </summary>
        /// <param name="groupName">The groupName.</param>
        /// <param name="groupFactory">The factory that will create new groups.</param>
        /// <param name="sortComparer">The groupName comparer.</param>
        /// <returns>Returns the index of the newly added group.</returns>
        internal int AddGroupByName(object groupName, IGroupFactory groupFactory, IComparer <object> sortComparer)
        {
            if (groupName == null)
            {
                groupName = NullValue.Instance;
            }

            System.Diagnostics.Debug.Assert(!this.GroupsByName.ContainsKey(groupName), "This method should not be called for existing groupName!");

            Group group;

            if (!this.GroupsByName.TryGetValue(groupName, out group))
            {
                group = groupFactory.CreateGroup(groupName);
                group.InternalParent = this;
                this.GroupsByName.Add(groupName, group);
                return(this.InsertItem(-1, group, sortComparer));
            }
            else
            {
                return(this.itemsList.IndexOf(group));
            }
        }
Exemplo n.º 3
0
 public static Group CreateGroup(string name)
 {
     return(Factory.CreateGroup(User.CurrentUser, name));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Performs the grouping operation for specified items.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="level">The level.</param>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        public virtual GroupCollection <T> Perform(IReadOnlyCollection <T> items, int level, Group <T> parent)
        {
            GroupDescriptorCollection groupDescriptors = this.index.CollectionView.GroupDescriptors;

            if (level >= groupDescriptors.Count)
            {
                return(GroupCollection <T> .Empty);
            }
            IGroupFactory <T> groupFactory = this.index.CollectionView.GroupFactory;

            GroupCollection <T> cache = GetCachedGroups(items, level);

            if (!IsValid(level, groupDescriptors))
            {
                if (cache != null)
                {
                    cache.Dispose();
                }
                return(this.index.CollectionView.GroupFactory.CreateCollection(GroupBuilder <T> .Empty));
            }

            IComparer <Group <T> > newComparer = Activator.CreateInstance(this.Comparer.GetType()) as IComparer <Group <T> >;

            if (newComparer == null)
            {
                newComparer = this.Comparer;
            }
            if (newComparer is GroupComparer <T> )
            {
                ((GroupComparer <T>)newComparer).Directions = this.GetComparerDirections(level);
            }

            AvlTree <Group <T> > groupList = new AvlTree <Group <T> >(newComparer);
            AvlTree <Group <T> > list      = new AvlTree <Group <T> >(new GroupComparer <T>(this.GetComparerDirections(level)));

            foreach (T item in items)
            {
                object    key = this.GroupPredicate(item, level);
                Group <T> group, newGroup = new DataItemGroup <T>(key);
                group = list.Find(newGroup); groupList.Find(newGroup);
                if (group == null)
                {
                    group = GroupBuilder <T> .GetCachedGroup(cache, newGroup);

                    if (group == null)
                    {
                        group = groupFactory.CreateGroup(key, parent);
                        DataItemGroup <T> dataGroup = group as DataItemGroup <T>;
                        dataGroup.GroupBuilder = this;
                    }

                    list.Add(group);// groupList.Add(group);
                }

                group.Items.Add(item);
            }

            for (int i = 0; i < list.Count; i++)
            {
                groupList.Add(list[i]);
            }

            if (cache != null)
            {
                cache.Dispose();
            }

            return(groupFactory.CreateCollection(groupList));
        }