コード例 #1
0
 protected override void OnCreate()
 {
     base.OnCreate();
     RequireSingletonForUpdate <GameState>();
     columnComparer = new ColumnComparer(EntityManager);
     rowComparer    = new RowComparer(EntityManager);
 }
コード例 #2
0
        public EntityReportDialog()
        {
            InitializeComponent();

            _sorter = new ColumnComparer(0);
            EntityList.ListViewItemSorter = _sorter;
        }
コード例 #3
0
            // *************************************************************

            // *************************************************************
            // Undocumented overridable that is called to create the set of columns for the grid
            protected override ArrayList CreateColumnSet(PagedDataSource dataSource, bool useDataSource)
            {
                // Let the grid generate the base column set (take the
                // AutoGenerateColumns property into account)
                ArrayList a = base.CreateColumnSet(dataSource, useDataSource);

                // If column dragging is disabled or reordering unnecessary
                if (ColumnOrder == "" || !EnableColumnDrag)
                {
                    return(a);
                }

                // Apply the desired sequence of columns
                if (ColumnOrder != "")
                {
                    // Reorder the column set to reflect the client-side changes
                    IComparer myComparer = new ColumnComparer(ColumnOrder);
                    a.Sort(myComparer);
                }

                // Client-side sorting is not restored here but once back
                // on the client. For this to happen, we only have to ensure
                // that a hidden field is created

                return(a);
            }
コード例 #4
0
    private static void OnComparerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var column         = (DataGridColumn)d;
        var columnComparer = new ColumnComparer((IComparer)e.NewValue, column);

        column.SetValue(ColumnComparerProperty, columnComparer);
    }
コード例 #5
0
 public ColumnComparer3(OLVColumn col, SortOrder order, OLVColumn col2, SortOrder order2, OLVColumn col3, SortOrder order3)
     : base(col, order, col2, order2)
 {
     // There is no point in secondary sorting on the same column
     if (col3 != col2)
     {
         this.thirdComparer = new ColumnComparer(col3, order3);
     }
 }
コード例 #6
0
ファイル: Form1.cs プロジェクト: nccgroup/ncccodenavi
        private void BuildGroups(int column)
        {
            this.listView1.Groups.Clear();

            // 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.
            int dummy = this.listView1.Items.Count;

            // Separate the list view items into groups, using the group key as the descrimanent
            Dictionary <String, List <ListViewItem> > map = new Dictionary <String, List <ListViewItem> >();

            foreach (ListViewItem lvi in this.listView1.Items)
            {
                String key = lvi.SubItems[column].Text;
                if (column == 0 && key.Length > 0)
                {
                    key = key.Substring(0, 1);
                }
                if (!map.ContainsKey(key))
                {
                    map[key] = new List <ListViewItem>();
                }
                map[key].Add(lvi);
            }

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

            foreach (String key in map.Keys)
            {
                groups.Add(new ListViewGroup(key));
            }

            // Sort the groups
            groups.Sort(new ListViewGroupComparer(this.lastSortOrder));

            // Put each group into the list view, and give each group its member items.
            // The order of statements is important here:
            // - the header must be calculate before the group is added to the list view,
            //   otherwise changing the header causes a nasty redraw (even in the middle of a BeginUpdate...EndUpdate pair)
            // - the group must be added before it is given items, otherwise an exception is thrown (is this documented?)
            ColumnComparer itemSorter = new ColumnComparer(column, this.lastSortOrder);

            foreach (ListViewGroup group in groups)
            {
                this.listView1.Groups.Add(group);
                map[group.Header].Sort(itemSorter);
                group.Items.AddRange(map[group.Header].ToArray());
            }
        }
コード例 #7
0
        public void SortElement()
        {
            RowComparer    rComparer = new RowComparer();
            ColumnComparer cComparer = new ColumnComparer();

            foreach (List <Element> r in rows)
            {
                r.Sort(rComparer);
            }
            foreach (List <Element> c in columns)
            {
                c.Sort(cComparer);
            }
        }
コード例 #8
0
        public override void ItemsChanged(params object[] items)
        {
            bool reLayout = false;

            //
            // only need to be concerned if the sort order changes
            if ((_jobGroupColumns != null && _jobGroupColumns.Length > 0) || (_jobSortColumns != null && _jobSortColumns.Length > 0))
            {
                lock (_lockObject)
                {
                    ColumnComparer comparer = new ColumnComparer(_jobGroupColumns, _jobSortColumns, this);

                    //
                    //	Check to see if changes have an effect of the sort order.
                    //	if they do then we add them to the deletes and adds.
                    //	Otherwise we don't need to do anything.
                    foreach (object o in items)
                    {
                        int searchResult = Array.BinarySearch(_sortedListItems, o, comparer);
                        if (searchResult < 0)
                        {
                            searchResult = ~searchResult;
                        }
                        if (searchResult < _sortedListItems.Length)
                        {
                            if (_sortedListItems[searchResult] == o)
                            {
                                reLayout = true; // visually may have changed so we layout
                            }
                            else
                            {
                                _deferredDeletions.Add(o);
                                _deferredAdditions.Add(o);
                            }
                        }
                    }
                }
            }
            if (reLayout)
            {
                ListControl.UpdateListSection(true);
            }
        }
コード例 #9
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;
        }
コード例 #10
0
 private static void OnComparerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     var column = (DataGridColumn)d;
     var columnComparer = new ColumnComparer((IComparer)e.NewValue, column);
     column.SetValue(ColumnComparerProperty, columnComparer);
 }
コード例 #11
0
ファイル: ObjectListView.cs プロジェクト: rxantos/tesv-snip
        private void DoSort(OLVColumn columnToSort, SortOrder order)
        {
            // Sanity checks
            if (GetItemCount() == 0 || Columns.Count == 0)
                return;

            // Fill in default values, if the parameters don't make sense
            if (ShowGroups)
            {
                columnToSort = columnToSort ?? GetColumn(0);
                if (order == SortOrder.None)
                {
                    order = Sorting;
                    if (order == SortOrder.None)
                        order = SortOrder.Ascending;
                }
            }

            // Give the world a chance to fiddle with or completely avoid the sorting process
            BeforeSortingEventArgs args = BuildBeforeSortingEventArgs(columnToSort, order);
            OnBeforeSorting(args);
            if (args.Canceled)
                return;

            // Virtual lists don't preserve selection, so we have to do it specifically
            // THINK: Do we need to preserve focus too?
            IList selection = new ArrayList();
            if (VirtualMode)
                selection = SelectedObjects;

            ClearHotItem();

            // Finally, do the work of sorting, unless an event handler has already done the sorting for us
            if (!args.Handled)
            {
                // Sanity checks
                if (args.ColumnToSort != null && args.SortOrder != SortOrder.None)
                {
                    if (ShowGroups)
                        BuildGroups(args.ColumnToGroupBy, args.GroupByOrder, args.ColumnToSort, args.SortOrder,
                                    args.SecondaryColumnToSort, args.SecondarySortOrder);
                    else if (CustomSorter != null)
                        CustomSorter(columnToSort, order);
                    else
                        ListViewItemSorter = new ColumnComparer(args.ColumnToSort, args.SortOrder,
                                                                args.SecondaryColumnToSort, args.SecondarySortOrder);
                }
            }

            if (ShowSortIndicators)
                ShowSortIndicator(args.ColumnToSort, args.SortOrder);

            LastSortColumn = args.ColumnToSort;
            LastSortOrder = args.SortOrder;

            if (selection.Count > 0)
                SelectedObjects = selection;

            RefreshHotItem();

            OnAfterSorting(new AfterSortingEventArgs(args));
        }
コード例 #12
0
ファイル: EntityReportDialog.cs プロジェクト: jpiolho/sledge
 public EntityReportDialog()
 {
     InitializeComponent();
     _sorter = new ColumnComparer(0);
     EntityList.ListViewItemSorter = _sorter;
 }
コード例 #13
0
        private void UpdateJob(object state)
        {
            try
            {
                object[]     additions;
                object[]     oldSortedList;
                Set <object> deferredDeletions = new Set <object>();

                bool sortNeeded;
                lock (_lockObject) // nip in to the shared areas and take a copy of the data
                {
                    additions         = _deferredAdditions.ToArray();
                    deferredDeletions = new Set <object>(_deferredDeletions);
                    oldSortedList     = (object[])_sortedListItems.Clone();
                    _deferredAdditions.Clear();
                    _deferredDeletions.Clear();
                    sortNeeded     = _jobSortNeeded;
                    _jobSortNeeded = false;
                }

                List <object> newSortedList = new List <object>(_sortedListItems.Length + additions.Length);


                //
                // Copy the necessary lists
                if (deferredDeletions.Count > 0)
                {
                    for (int i = 0; i < oldSortedList.Length; i++)
                    {
                        object item = oldSortedList[i];
                        if (!deferredDeletions.Contains(item))
                        {
                            newSortedList.Add(item);
                        }
                    }
                }
                else
                {
                    newSortedList = new List <object>(_sortedListItems);
                }

                if (_jobGroupColumns.Length > 0 || _jobSortColumns.Length > 0)
                {
                    ColumnComparer comparer = new ColumnComparer(_jobGroupColumns, _jobSortColumns, this);

                    //
                    // Perform sort.
                    if (!sortNeeded && additions.Length != 0 && newSortedList.Count > additions.Length)
                    {
                        //
                        //	We insert the new entries using BinarySearch since the
                        //	default sort for the Clr is QuickSort which works best on
                        //	unsorted lists.
                        foreach (object item in additions)
                        {
                            int searchResult = newSortedList.BinarySearch(item, comparer);
                            if (searchResult < 0)
                            {
                                searchResult = ~searchResult;
                            }
                            newSortedList.Insert(searchResult, item);
                        }
                    }
                    else
                    {
                        newSortedList.AddRange(additions);
                        newSortedList.Sort(comparer);
                    }
                }
                else
                {
                    newSortedList.AddRange(additions);
                }
                lock (_lockObject)
                {
                    _jobSortedList = newSortedList;
                }
            }
            finally
            {
                _jobQueued = false;
            }
        }