Example #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnFilter(FilterEventArgs e) {
     if (this.Filter != null)
         this.Filter(this, e);
 }
Example #2
0
        /// <summary>
        /// Do the actual work of filtering
        /// </summary>
        /// <param name="objects"></param>
        /// <param name="aModelFilter"></param>
        /// <param name="aListFilter"></param>
        /// <returns></returns>
        protected virtual IEnumerable FilterObjects(IEnumerable objects, IModelFilter aModelFilter, IListFilter aListFilter)
        {
            // Being cautious
            objects = objects ?? new ArrayList();

            // Tell the world to filter the objects. If they do so, don't do anything else
            FilterEventArgs args = new FilterEventArgs(objects);
            this.OnFilter(args);
            if (args.FilteredObjects != null)
                return args.FilteredObjects;

            // Apply a filter to the list as a whole
            if (aListFilter != null)
                objects = aListFilter.Filter(objects);

            // Apply the object filter if there is one
            if (aModelFilter != null) {
                ArrayList filteredObjects = new ArrayList();
                foreach (object model in objects) {
                    if (aModelFilter.Filter(model))
                        filteredObjects.Add(model);
                }
                objects = filteredObjects;
            }

            return objects;
        }
        /// <summary>
        /// Build our filtered list from our full list.
        /// </summary>
        protected void FilterObjects()
        {
            // If this list isn't filtered, we don't need to do anything else
            if (!this.listView.UseFiltering) {
                this.filteredObjectList = new ArrayList(this.fullObjectList);
                return;
            }

            // Tell the world to filter the objects. If they do so, don't do anything else
            // ReSharper disable PossibleMultipleEnumeration
            FilterEventArgs args = new FilterEventArgs(this.fullObjectList);
            this.listView.OnFilter(args);
            if (args.FilteredObjects != null) {
                this.filteredObjectList = ObjectListView.EnumerableToArray(args.FilteredObjects, false);
                return;
            }

            IEnumerable objects = (this.listFilter == null) ?
                this.fullObjectList : this.listFilter.Filter(this.fullObjectList);

            // Apply the object filter if there is one
            if (this.modelFilter == null) {
                this.filteredObjectList = ObjectListView.EnumerableToArray(objects, false);
            } else {
                this.filteredObjectList = new ArrayList();
                foreach (object model in objects) {
                    if (this.modelFilter.Filter(model))
                        this.filteredObjectList.Add(model);
                }
            }
        }