コード例 #1
0
 protected override IList <OLVGroup> MakeGroups(GroupingParameters parms)
 {
     if (this.GroupingStrategy == null)
     {
         return(new List <OLVGroup>());
     }
     return(this.GroupingStrategy.GetGroups(parms));
 }
コード例 #2
0
        /// <summary>
        /// Make a list of groups that should be shown according to the given parameters
        /// </summary>
        /// <param name="parms"></param>
        /// <returns>The list of groups to be created</returns>
        /// <remarks>This should not change the state of the control. It is possible that the
        /// groups created will not be used. They may simply be discarded.</remarks>
        protected virtual IList<OLVGroup> MakeGroups(GroupingParameters parms)
        {
            // There is a lot of overlap between this method and FastListGroupingStrategy.MakeGroups()
            // Any changes made here may need to be reflected there

            // Separate the list view items into groups, using the group key as the descrimanent
            NullableDictionary<object, List<OLVListItem>> map = new NullableDictionary<object, List<OLVListItem>>();
            foreach (OLVListItem olvi in parms.ListView.Items) {
                object key = parms.GroupByColumn.GetGroupKey(olvi.RowObject);
                if (!map.ContainsKey(key))
                    map[key] = new List<OLVListItem>();
                map[key].Add(olvi);
            }

            // Sort the items within each group (unless specifically turned off)
            OLVColumn primarySortColumn = parms.SortItemsByPrimaryColumn ? parms.ListView.GetColumn(0) : parms.PrimarySort;
            if (primarySortColumn != null && parms.PrimarySortOrder != SortOrder.None) {
                ColumnComparer itemSorter = new ColumnComparer(primarySortColumn, parms.PrimarySortOrder,
                    parms.SecondarySort, parms.SecondarySortOrder);
                foreach (object key in map.Keys) {
                    map[key].Sort(parms.ItemComparer ?? itemSorter);
                }
            }

            // Make a list of the required groups
            List<OLVGroup> groups = new List<OLVGroup>();
            foreach (object key in map.Keys) {
                string title = parms.GroupByColumn.ConvertGroupKeyToTitle(key);
                if (!String.IsNullOrEmpty(parms.TitleFormat)) {
                    int count = map[key].Count;
                    string format = (count == 1 ? parms.TitleSingularFormat : parms.TitleFormat);
                    try {
                        title = String.Format(format, title, count);
                    } catch (FormatException) {
                        title = "Invalid group format: " + format;
                    }
                }

                OLVGroup lvg = new OLVGroup(title);
                lvg.Collapsible = this.HasCollapsibleGroups;
                lvg.Key = key;
                lvg.SortValue = key as IComparable;
                lvg.Items = map[key];
                if (parms.GroupByColumn.GroupFormatter != null)
                    parms.GroupByColumn.GroupFormatter(lvg, parms);
                groups.Add(lvg);
            }

            // Sort the groups
            if (parms.GroupByOrder != SortOrder.None)
                groups.Sort(parms.GroupComparer ?? new OLVGroupComparer(parms.GroupByOrder));

            return groups;
        }
コード例 #3
0
 /// <summary>
 /// Collect and return all the variables that influence the creation of groups
 /// </summary>
 /// <returns></returns>
 protected virtual GroupingParameters CollectGroupingParameters(OLVColumn groupByColumn, SortOrder groupByOrder,
     OLVColumn column, SortOrder order, OLVColumn secondaryColumn, SortOrder secondaryOrder)
 {
     string titleFormat = this.ShowItemCountOnGroups ? groupByColumn.GroupWithItemCountFormatOrDefault : null;
     string titleSingularFormat = this.ShowItemCountOnGroups ? groupByColumn.GroupWithItemCountSingularFormatOrDefault : null;
     GroupingParameters parms = new GroupingParameters(this, groupByColumn, groupByOrder,
         column, order, secondaryColumn, secondaryOrder,
         titleFormat, titleSingularFormat, this.SortGroupItemsByPrimaryColumn);
     return parms;
 }
コード例 #4
0
ファイル: Events.cs プロジェクト: heliwave/QuranCode
 /// <summary>
 /// Create a CreateGroupsEventArgs
 /// </summary>
 /// <param name="parms"></param>
 public CreateGroupsEventArgs(GroupingParameters parms) {
     this.parameters = parms;
 }
コード例 #5
0
 /// <summary>
 /// Make a list of groups that should be shown according to the given parameters
 /// </summary>
 /// <param name="parms"></param>
 /// <returns></returns>
 protected override IList<OLVGroup> MakeGroups(GroupingParameters parms) {
     if (this.GroupingStrategy == null)
         return new List<OLVGroup>();
     else
         return this.GroupingStrategy.GetGroups(parms);
 }
コード例 #6
0
ファイル: CreateGroupsEventArgs.cs プロジェクト: etupper/PFM
 public CreateGroupsEventArgs(GroupingParameters parms)
 {
     this.parameters = parms;
 }
コード例 #7
0
ファイル: VirtualGroups.cs プロジェクト: CaulyKan/logwizard
 /// <summary>
 /// Return the list of groups that should be shown according to the given parameters
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public virtual IList<OLVGroup> GetGroups(GroupingParameters parameters) {
     return new List<OLVGroup>();
 }
コード例 #8
0
ファイル: VirtualGroups.cs プロジェクト: CaulyKan/logwizard
        /// <summary>
        /// Create groups for FastListView
        /// </summary>
        /// <param name="parmameters"></param>
        /// <returns></returns>
        public override IList<OLVGroup> GetGroups(GroupingParameters parmameters) {

            // There is a lot of overlap between this method and ObjectListView.MakeGroups()
            // Any changes made here may need to be reflected there

            // This strategy can only be used on FastObjectListViews
            FastObjectListView folv = (FastObjectListView)parmameters.ListView;

            // Separate the list view items into groups, using the group key as the descrimanent
            int objectCount = 0;
            NullableDictionary<object, List<object>> map = new NullableDictionary<object, List<object>>();
            foreach (object model in folv.FilteredObjects) {
                object key = parmameters.GroupByColumn.GetGroupKey(model);
                if (!map.ContainsKey(key))
                    map[key] = new List<object>();
                map[key].Add(model);
                objectCount++;
            }

            // Sort the items within each group
            // TODO: Give parameters a ModelComparer property
            OLVColumn primarySortColumn = parmameters.SortItemsByPrimaryColumn ? parmameters.ListView.GetColumn(0) : parmameters.PrimarySort;
            ModelObjectComparer sorter = new ModelObjectComparer(primarySortColumn, parmameters.PrimarySortOrder,
                parmameters.SecondarySort, parmameters.SecondarySortOrder);
            foreach (object key in map.Keys) {
                map[key].Sort(sorter);
            }

            // Make a list of the required groups
            List<OLVGroup> groups = new List<OLVGroup>();
            foreach (object key in map.Keys) {
                string title = parmameters.GroupByColumn.ConvertGroupKeyToTitle(key);
                if (!String.IsNullOrEmpty(parmameters.TitleFormat)) {
                    int count = map[key].Count;
                    string format = (count == 1 ? parmameters.TitleSingularFormat : parmameters.TitleFormat);
                    try {
                        title = String.Format(format, title, count);
                    } catch (FormatException) {
                        title = "Invalid group format: " + format;
                    }
                }
                OLVGroup lvg = new OLVGroup(title);
                lvg.Collapsible = folv.HasCollapsibleGroups;
                lvg.Key = key;
                lvg.SortValue = key as IComparable;
                lvg.Contents = map[key].ConvertAll<int>(delegate(object x) { return folv.IndexOf(x); });
                lvg.VirtualItemCount = map[key].Count;
                if (parmameters.GroupByColumn.GroupFormatter != null)
                    parmameters.GroupByColumn.GroupFormatter(lvg, parmameters);
                groups.Add(lvg);
            }

            // Sort the groups
            if (parmameters.GroupByOrder != SortOrder.None)
                groups.Sort(parmameters.GroupComparer ?? new OLVGroupComparer(parmameters.GroupByOrder));

            // Build an array that remembers which group each item belongs to.
            this.indexToGroupMap = new List<int>(objectCount);
            this.indexToGroupMap.AddRange(new int[objectCount]);

            for (int i = 0; i < groups.Count; i++) {
                OLVGroup group = groups[i];
                List<int> members = (List<int>)group.Contents;
                foreach (int j in members)
                    this.indexToGroupMap[j] = i;
            }

            return groups;
        }
コード例 #9
0
ファイル: ObjectListView.cs プロジェクト: FOSBOS/diNo
        /// <summary>
        /// Collect and return all the variables that influence the creation of groups
        /// </summary>
        /// <returns></returns>
        protected virtual GroupingParameters CollectGroupingParameters(OLVColumn groupByColumn, SortOrder groupByOrder,
            OLVColumn sortByColumn, SortOrder sortByOrder, OLVColumn secondaryColumn, SortOrder secondaryOrder)
        {
            // If the user tries to group by a non-groupable column, keep the current group by
            // settings, but use the non-groupable column for sorting
            if (!groupByColumn.Groupable && lastGroupingParameters != null) {
                sortByColumn = groupByColumn;
                sortByOrder = groupByOrder;
                groupByColumn = lastGroupingParameters.GroupByColumn;
                groupByOrder = lastGroupingParameters.GroupByOrder;
            }

            string titleFormat = this.ShowItemCountOnGroups ? groupByColumn.GroupWithItemCountFormatOrDefault : null;
            string titleSingularFormat = this.ShowItemCountOnGroups ? groupByColumn.GroupWithItemCountSingularFormatOrDefault : null;
            GroupingParameters parms = new GroupingParameters(this, groupByColumn, groupByOrder,
                sortByColumn, sortByOrder, secondaryColumn, secondaryOrder,
                titleFormat, titleSingularFormat, this.SortGroupItemsByPrimaryColumn);
            return parms;
        }
コード例 #10
0
ファイル: ObjectListView.cs プロジェクト: FOSBOS/diNo
        /// <summary>
        /// Organise the view items into groups, based on the given columns
        /// </summary>
        /// <param name="groupByColumn">What column will be used for grouping</param>
        /// <param name="groupByOrder">What ordering will be used for groups</param>
        /// <param name="column">The column whose values should be used for sorting. Cannot be null</param>
        /// <param name="order">The order in which the values from column will be sorted</param>
        /// <param name="secondaryColumn">When the values from 'column' are equal, use the values provided by this column</param>
        /// <param name="secondaryOrder">How will the secondary values be sorted</param>
        /// <remarks>This method does not trigger sorting events. Use BuildGroups() to do that</remarks>
        public virtual void BuildGroups(OLVColumn groupByColumn, SortOrder groupByOrder,
            OLVColumn column, SortOrder order, OLVColumn secondaryColumn, SortOrder secondaryOrder)
        {
            // Sanity checks
            if (groupByColumn == null)
                return;

            // Getting the Count forces any internal cache of the ListView to be flushed. Without
            // this, iterating over the Items will not work correctly if the ListView handle
            // has not yet been created.
            #pragma warning disable 168
            // ReSharper disable once UnusedVariable
            int dummy = this.Items.Count;
            #pragma warning restore 168

            // Collect all the information that governs the creation of groups
            GroupingParameters parms = this.CollectGroupingParameters(groupByColumn, groupByOrder,
                column, order, secondaryColumn, secondaryOrder);

            // Trigger an event to let the world create groups if they want
            CreateGroupsEventArgs args = new CreateGroupsEventArgs(parms);
            if (parms.GroupByColumn != null)
                args.Canceled = !parms.GroupByColumn.Groupable;
            this.OnBeforeCreatingGroups(args);
            if (args.Canceled)
                return;

            // If the event didn't create them for us, use our default strategy
            if (args.Groups == null)
                args.Groups = this.MakeGroups(parms);

            // Give the world a chance to munge the groups before they are created
            this.OnAboutToCreateGroups(args);
            if (args.Canceled)
                return;

            // Create the groups now
            this.OLVGroups = args.Groups;
            this.CreateGroups(args.Groups);

            // Tell the world that new groups have been created
            this.OnAfterCreatingGroups(args);
            lastGroupingParameters = args.Parameters;
        }
コード例 #11
0
        public override IList <OLVGroup> GetGroups(GroupingParameters parms)
        {
            Converter <object, int> converter = null;
            FastObjectListView      folv      = (FastObjectListView)parms.ListView;
            int capacity = 0;
            NullableDictionary <object, List <object> > dictionary = new NullableDictionary <object, List <object> >();

            foreach (object obj2 in folv.Objects)
            {
                object groupKey = parms.GroupByColumn.GetGroupKey(obj2);
                if (!dictionary.ContainsKey(groupKey))
                {
                    dictionary[groupKey] = new List <object>();
                }
                dictionary[groupKey].Add(obj2);
                capacity++;
            }
            OLVColumn           col      = parms.SortItemsByPrimaryColumn ? parms.ListView.GetColumn(0) : parms.PrimarySort;
            ModelObjectComparer comparer = new ModelObjectComparer(col, parms.PrimarySortOrder, parms.SecondarySort, parms.SecondarySortOrder);

            foreach (object obj3 in dictionary.Keys)
            {
                dictionary[obj3].Sort(comparer);
            }
            List <OLVGroup> list = new List <OLVGroup>();

            foreach (object obj3 in dictionary.Keys)
            {
                string str = parms.GroupByColumn.ConvertGroupKeyToTitle(obj3);
                if (!string.IsNullOrEmpty(parms.TitleFormat))
                {
                    int count = dictionary[obj3].Count;
                    str = string.Format((count == 1) ? parms.TitleSingularFormat : parms.TitleFormat, str, count);
                }
                OLVGroup group = new OLVGroup(str)
                {
                    Key       = obj3,
                    SortValue = obj3 as IComparable
                };
                if (converter == null)
                {
                    converter = x => folv.IndexOf(x);
                }
                group.Contents         = dictionary[obj3].ConvertAll <int>(converter);
                group.VirtualItemCount = dictionary[obj3].Count;
                if (parms.GroupByColumn.GroupFormatter != null)
                {
                    parms.GroupByColumn.GroupFormatter(group, parms);
                }
                list.Add(group);
            }
            list.Sort(new OLVGroupComparer(parms.PrimarySortOrder));
            this.indexToGroupMap = new List <int>(capacity);
            this.indexToGroupMap.AddRange(new int[capacity]);
            for (int i = 0; i < list.Count; i++)
            {
                OLVGroup   group2   = list[i];
                List <int> contents = (List <int>)group2.Contents;
                foreach (int num4 in contents)
                {
                    this.indexToGroupMap[num4] = i;
                }
            }
            return(list);
        }
コード例 #12
0
 /// <summary>
 /// Return the list of groups that should be shown according to the given parameters
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public virtual IList <OLVGroup> GetGroups(GroupingParameters parameters)
 {
     return(new List <OLVGroup>());
 }
コード例 #13
0
        /// <summary>
        /// Create groups for FastListView
        /// </summary>
        /// <param name="parmameters"></param>
        /// <returns></returns>
        public override IList <OLVGroup> GetGroups(GroupingParameters parmameters)
        {
            // There is a lot of overlap between this method and ObjectListView.MakeGroups()
            // Any changes made here may need to be reflected there

            // This strategy can only be used on FastObjectListViews
            FastObjectListView folv = (FastObjectListView)parmameters.ListView;

            // Separate the list view items into groups, using the group key as the descrimanent
            int objectCount = 0;
            NullableDictionary <object, List <object> > map = new NullableDictionary <object, List <object> >();

            foreach (object model in folv.FilteredObjects)
            {
                object key = parmameters.GroupByColumn.GetGroupKey(model);
                if (!map.ContainsKey(key))
                {
                    map[key] = new List <object>();
                }
                map[key].Add(model);
                objectCount++;
            }

            // Sort the items within each group
            // TODO: Give parameters a ModelComparer property
            OLVColumn           primarySortColumn = parmameters.SortItemsByPrimaryColumn ? parmameters.ListView.GetColumn(0) : parmameters.PrimarySort;
            ModelObjectComparer sorter            = new ModelObjectComparer(primarySortColumn, parmameters.PrimarySortOrder,
                                                                            parmameters.SecondarySort, parmameters.SecondarySortOrder);

            foreach (object key in map.Keys)
            {
                map[key].Sort(sorter);
            }

            // Make a list of the required groups
            List <OLVGroup> groups = new List <OLVGroup>();

            foreach (object key in map.Keys)
            {
                string title = parmameters.GroupByColumn.ConvertGroupKeyToTitle(key);
                if (!String.IsNullOrEmpty(parmameters.TitleFormat))
                {
                    int    count  = map[key].Count;
                    string format = (count == 1 ? parmameters.TitleSingularFormat : parmameters.TitleFormat);
                    try {
                        title = String.Format(format, title, count);
                    } catch (FormatException) {
                        title = "Invalid group format: " + format;
                    }
                }
                OLVGroup lvg = new OLVGroup(title);
                lvg.Collapsible      = folv.HasCollapsibleGroups;
                lvg.Key              = key;
                lvg.SortValue        = key as IComparable;
                lvg.Contents         = map[key].ConvertAll <int>(delegate(object x) { return(folv.IndexOf(x)); });
                lvg.VirtualItemCount = map[key].Count;
                if (parmameters.GroupByColumn.GroupFormatter != null)
                {
                    parmameters.GroupByColumn.GroupFormatter(lvg, parmameters);
                }
                groups.Add(lvg);
            }

            // Sort the groups
            if (parmameters.GroupByOrder != SortOrder.None)
            {
                groups.Sort(parmameters.GroupComparer ?? new OLVGroupComparer(parmameters.GroupByOrder));
            }

            // Build an array that remembers which group each item belongs to.
            this.indexToGroupMap = new List <int>(objectCount);
            this.indexToGroupMap.AddRange(new int[objectCount]);

            for (int i = 0; i < groups.Count; i++)
            {
                OLVGroup   group   = groups[i];
                List <int> members = (List <int>)group.Contents;
                foreach (int j in members)
                {
                    this.indexToGroupMap[j] = i;
                }
            }

            return(groups);
        }
コード例 #14
0
        public override IList <OLVGroup> GetGroups(GroupingParameters parms)
        {
            // This strategy can only be used on FastObjectListViews
            FastObjectListView folv = (FastObjectListView)parms.ListView;

            // Separate the list view items into groups, using the group key as the descrimanent
            int objectCount = 0;
            NullableDictionary <object, List <object> > map = new NullableDictionary <object, List <object> >();

            foreach (object model in folv.Objects)
            {
                object key = parms.GroupByColumn.GetGroupKey(model);
                if (!map.ContainsKey(key))
                {
                    map[key] = new List <object>();
                }
                map[key].Add(model);
                objectCount++;
            }

            // Sort the items within each group
            OLVColumn           primarySortColumn = parms.SortItemsByPrimaryColumn ? parms.ListView.GetColumn(0) : parms.PrimarySort;
            ModelObjectComparer sorter            = new ModelObjectComparer(primarySortColumn, parms.PrimarySortOrder,
                                                                            parms.SecondarySort, parms.SecondarySortOrder);

            foreach (object key in map.Keys)
            {
                map[key].Sort(sorter);
            }

            // Make a list of the required groups
            List <OLVGroup> groups = new List <OLVGroup>();

            foreach (object key in map.Keys)
            {
                string title = parms.GroupByColumn.ConvertGroupKeyToTitle(key);
                if (!String.IsNullOrEmpty(parms.TitleFormat))
                {
                    int count = map[key].Count;
                    title = String.Format((count == 1 ? parms.TitleSingularFormat : parms.TitleFormat), title, count);
                }
                OLVGroup lvg = new OLVGroup(title);
                lvg.Key              = key;
                lvg.SortValue        = key as IComparable;
                lvg.Contents         = map[key].ConvertAll <int>(delegate(object x) { return(folv.IndexOf(x)); });
                lvg.VirtualItemCount = map[key].Count;
                if (parms.GroupByColumn.GroupFormatter != null)
                {
                    parms.GroupByColumn.GroupFormatter(lvg, parms);
                }
                groups.Add(lvg);
            }

            // Sort the groups
            groups.Sort(new OLVGroupComparer(parms.PrimarySortOrder));

            // Build an array that remembers which group each item belongs to.
            this.indexToGroupMap = new List <int>(objectCount);
            this.indexToGroupMap.AddRange(new int[objectCount]);

            for (int i = 0; i < groups.Count; i++)
            {
                OLVGroup   group   = groups[i];
                List <int> members = (List <int>)group.Contents;
                foreach (int j in members)
                {
                    this.indexToGroupMap[j] = i;
                }
            }

            return(groups);
        }