Beispiel #1
0
        public GridRowViewModel(TRowEntity paramKey,
                                RowSettings <TRowEntity, TCellEntity> paramRowSettings,
                                int capacity,
                                IEnumerable <ColumnSettings <TCellEntity> > paramColumnSettings
                                )
        {
            List <CellViewModel <TCellEntity> > list = new List <CellViewModel <TCellEntity> >();

            for (int i = 0; i < capacity; i++)
            {
                foreach (var cs in paramColumnSettings)
                {
                    list.Add(new CellViewModel <TCellEntity>(cs));
                }
            }
            _observableGrouping = new ObservableGrouping <TRowEntity, CellViewModel <TCellEntity> >(paramKey, list);

            colSettingsCount = paramColumnSettings.Count();
            _rowSettings     = paramRowSettings;
        }
        protected override void OnAddEditors(IEnumerable <EditorViewModel> editors)
        {
            IEnumerable <EditorViewModel> props = Properties;

            if (!String.IsNullOrWhiteSpace(FilterText))
            {
                props = props.Where(MatchesFilter);
            }

            props = props.OrderBy(vm => vm.Name);

            Dictionary <string, List <PropertyViewModel> > groupedTypeProperties = null;

            this.arranged.Clear();
            foreach (var grouping in props.GroupBy(GetGroup).OrderBy(g => g.Key, CategoryComparer.Instance))
            {
                HashSet <EditorViewModel> remainingItems = null;

                if (ArrangeMode == PropertyArrangeMode.Category)
                {
                    foreach (EditorViewModel editorVm in grouping)
                    {
                        var vm = editorVm as PropertyViewModel;
                        if (vm != null && TargetPlatform.GroupedTypes != null && TargetPlatform.GroupedTypes.TryGetValue(vm.Property.Type, out string category))
                        {
                            if (remainingItems == null)
                            {
                                remainingItems = new HashSet <EditorViewModel> (grouping);
                            }

                            remainingItems.Remove(vm);

                            if (groupedTypeProperties == null)
                            {
                                groupedTypeProperties = new Dictionary <string, List <PropertyViewModel> > ();
                            }
                            if (!groupedTypeProperties.TryGetValue(category, out List <PropertyViewModel> group))
                            {
                                groupedTypeProperties[category] = group = new List <PropertyViewModel> ();
                            }

                            group.Add(vm);
                        }
                    }
                }

                if (remainingItems != null)
                {
                    this.arranged.Add(grouping.Key, remainingItems);
                }
                else
                {
                    this.arranged.Add(grouping);
                }
            }

            if (groupedTypeProperties != null)               // Insert type-grouped properties back in sorted.
            {
                int i = 0;
                foreach (var kvp in groupedTypeProperties.OrderBy(kvp => kvp.Key, CategoryComparer.Instance))
                {
                    var group = new ObservableGrouping <string, EditorViewModel> (kvp.Key)
                    {
                        new PropertyGroupViewModel(TargetPlatform, kvp.Key, kvp.Value, ObjectEditors)
                    };

                    for (; i < this.arranged.Count; i++)
                    {
                        var g = (IGrouping <string, EditorViewModel>) this.arranged[i];

                        // TODO: Are we translating categories? If so this needs to lookup the resource and be culture specific
                        if (g.Key == null)                           // nulls go on the bottom.
                        {
                            this.arranged.Insert(i, group);
                            break;
                        }
                        else if (String.Compare(g.Key, kvp.Key, StringComparison.Ordinal) > 0)
                        {
                            this.arranged.Insert(i++, group);
                            break;
                        }
                    }
                }
            }

            ArrangedPropertiesChanged?.Invoke(this, EventArgs.Empty);
        }