Processing of entries
Processing of entries include filtering and sorting.

In v1, the list of entries are parsed manually in CurrentDirectoryViewModel, the returned entries are actually a List instead an ObservableCollection.

In v2, a CollectionViewSource is created and filtering/sorting is done using CustomSort and Filter property, stored inside an DirectoryViewModel.createColViewSource() and EntryComparerHelper.ChangeSortMethod() extension method.

    System.Windows.Data.ListCollectionView dataView =
        (System.Windows.Data.ListCollectionView)
        (System.Windows.Data.CollectionViewSource.GetDefaultView(collection));
    dataView.CustomSort = new EntryComparer<FI, DI, FSI>(sortBy, direction) { IsFolderFirst = true };

In v3, to allow reuse these code, EntriesProcessor is added, it takes an EntriesHelper (see Asynchronous loading of entries), it allow Sort (Sort() method), Filter (CustomFilter property) and Filter based on columns (ColumnsHelper property).

public class EntriesProcessor<VM> : IEntriesProcessor<VM>
{
    public EntriesProcessor(IEntriesHelper<VM> entriesHelper)
    {
        EntriesHelper = entriesHelper;
    }

    public void Sort(IComparer comparer, string groupDescription)
    {
        All.CustomSort = comparer;
        All.GroupDescriptions.Add(new PropertyGroupDescription(groupDescription));
    }
    ...      
    public void SetFilters(params ColumnFilter[] filters)
    {
        _colFilters = filters;
        updateFilters();
    }
    ...
  
    public Func<object, bool> CustomFilter
    {
        get { return _customFilter; }
        set { _customFilter = value ?? (e => true); updateFilters(); }
    }

    public ListCollectionView All
    {
        get
        {
            if (_processedItems == null)                
                _processedItems = 
                      CollectionViewSource.GetDefaultView(EntriesHelper.All) as ListCollectionView;                
            return _processedItems;
        }
    }
    public IEntriesHelper<VM> EntriesHelper { get; private set; }
    public IColumnsHelper ColumnHelper { get; private set; }    
}

Currently the ColumnsHelper support IEntryModel only, it let you specify the columns in ListView as well as filters.

public interface IColumnsHelper
{
    ColumnInfo[] ColumnList { get; set; }
    ColumnFilter[] ColumnFilters { get; set; }

    event EventHandler FilterChanged; //These trigger EntriesProcessor
    event EventHandler SortChanged;
    void CalculateColumnHeaderCount(IEnumerable<IEntryModel> entryModels);
    IComparer GetComparer(ColumnInfo colInfo, ListSortDirection direction);
}

Last edited May 24, 2014 at 6:24 AM by lycj, version 2

Comments

No comments yet.