Exemplo n.º 1
0
        /// <summary>
        /// Create a collection of clusters that should be presented to the user
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="listView"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        protected virtual List<ICluster> Cluster(IClusteringStrategy strategy, ObjectListView listView, OLVColumn column)
        {
            // Build a map that correlates cluster key to clusters
            var map = new NullableDictionary<object, ICluster>();
            int count = 0;
            foreach (object model in listView.Objects)
            {
                object key = strategy.GetClusterKey(model);
                if (key == DBNull.Value)
                    key = null;
                if (key == null && !TreatNullAsDataValue)
                    continue;
                if (map.ContainsKey(key))
                    map[key].Count += 1;
                else
                    map[key] = strategy.CreateCluster(key);

                // Check our limit
                count += 1;
                if (count > MaxObjectsToConsider)
                    break;
            }

            // Now that we know exactly how many items are in each cluster, create a label for it
            foreach (ICluster cluster in map.Values)
                cluster.DisplayLabel = strategy.GetClusterDisplayLabel(cluster);

            return new List<ICluster>(map.Values);
        }
Exemplo n.º 2
0
        private void ClusterOneModel(IClusteringStrategy strategy, NullableDictionary <object, ICluster> map, object model)
        {
            object clusterKey = strategy.GetClusterKey(model);

            // If the returned value is an IEnumerable, that means the given model can belong to more than one cluster
            IEnumerable keyEnumerable = clusterKey as IEnumerable;

            if (clusterKey is string || keyEnumerable == null)
            {
                keyEnumerable = new object[] { clusterKey }
            }
            ;

            // Deal with nulls and DBNulls
            ArrayList nullCorrected = new ArrayList();

            foreach (object key in keyEnumerable)
            {
                if (key == null || key == System.DBNull.Value)
                {
                    if (this.TreatNullAsDataValue)
                    {
                        nullCorrected.Add(null);
                    }
                }
                else
                {
                    nullCorrected.Add(key);
                }
            }

            // Group by key
            foreach (object key in nullCorrected)
            {
                if (map.ContainsKey(key))
                {
                    map[key].Count += 1;
                }
                else
                {
                    map[key] = strategy.CreateCluster(key);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a collection of clusters that should be presented to the user
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="listView"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        virtual protected List <ICluster> Cluster(IClusteringStrategy strategy, ObjectListView listView, OLVColumn column)
        {
            // Build a map that correlates cluster key to clusters
            NullableDictionary <object, ICluster> map = new NullableDictionary <object, ICluster>();
            int count = 0;

            foreach (object model in listView.Objects)
            {
                object key = strategy.GetClusterKey(null, model);
                if (key == System.DBNull.Value)
                {
                    key = null;
                }
                if (key == null && !this.TreatNullAsDataValue)
                {
                    continue;
                }
                if (map.ContainsKey(key))
                {
                    map[key].Count += 1;
                }
                else
                {
                    map[key] = strategy.CreateCluster(key);
                }

                // Check our limit
                count += 1;
                if (count > this.MaxObjectsToConsider)
                {
                    break;
                }
            }

            // Now that we know exactly how many items are in each cluster, create a label for it
            foreach (ICluster cluster in map.Values)
            {
                cluster.DisplayLabel = strategy.GetClusterDisplayLabel(cluster);
            }

            return(new List <ICluster>(map.Values));
        }
        /// <summary>
        /// Create a collection of clusters that should be presented to the user
        /// </summary>
        /// <param name="strategy"></param>
        /// <param name="listView"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        virtual protected List <ICluster> Cluster(IClusteringStrategy strategy, ObjectListView listView, OLVColumn column)
        {
            // Build a map that correlates cluster key to clusters
            NullableDictionary <object, ICluster> map = new NullableDictionary <object, ICluster>();
            int count = 0;

            foreach (object model in listView.ObjectsForClustering)
            {
                this.ClusterOneModel(strategy, map, model);

                if (count++ > this.MaxObjectsToConsider)
                {
                    break;
                }
            }

            // Now that we know exactly how many items are in each cluster, create a label for it
            foreach (ICluster cluster in map.Values)
            {
                cluster.DisplayLabel = strategy.GetClusterDisplayLabel(cluster);
            }

            return(new List <ICluster>(map.Values));
        }
        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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }