internal override void RequestTreeItems(TreeGridRequestTreeItemsEventArgs e) { bool canPopualate = (e.ParentNode != null && e.ParentNode.ChildNodes.Any() && e.ResetChildAndRepopulate) || (e.ParentNode != null && !e.ParentNode.ChildNodes.Any()) || e.ParentNode == null; if (!canPopualate) { if (e.ParentNode != null) { if (SortDescriptions.Any()) { e.ParentNode.ChildNodes.Sort(SortDescriptions, SortComparers); } } return; } if (e.ParentItem == null) { e.ChildItems = TreeGrid.ItemsSource as IEnumerable; } if (e.CanAddChildNode) { PopulateTreeNodes(e); if (this.SortDescriptions.Any()) { SortNodes(e.ParentNode); } } }
/// /////////////////////////////////////////////////////////////// // Implementation void request_page(int page_num) { if (page_num < 0) { throw new ArgumentOutOfRangeException(); } if (!_dataRows.TryAdd(page_num, null)) // Return if the key already exists. { return; } ItemsEventArgs args = new ItemsEventArgs( _pageSize * page_num, // startIndex _pageSize, // requestedCount SortDescriptions.FirstOrDefault()); Task <List <T> > items_task = ItemsRequest(this, args); items_task.ContinueWith(task => { _dataRows[page_num] = task.Result; // Dictionary<>はthread-safe ではない! Console.WriteLine("Updated: " + page_num); Action action = () => { this.Refresh(); }; Application.Current.Dispatcher.BeginInvoke(action); // UIスレッドに戻す }); }
internal override void RequestTreeItems(TreeGridRequestTreeItemsEventArgs e) { bool canPopualate = (e.ParentNode != null && e.ParentNode.ChildNodes.Any() && e.ResetChildAndRepopulate) || (e.ParentNode != null && !e.ParentNode.ChildNodes.Any()) || e.ParentNode == null; if (!canPopualate) { if (e.ParentNode != null) { if (SortDescriptions.Any()) { e.ParentNode.ChildNodes.Sort(SortDescriptions, SortComparers); } } return; } if (e.ParentItem == null) { e.ChildItems = GetChildSourceFromParentID(SelfRelationRootValue, e.ParentItem, true); } else { object parentValue = propertyAccessProvider.GetValue(e.ParentItem, parentPropertyName); e.ChildItems = GetChildSourceFromParentID(parentValue, e.ParentItem, e.CanAddChildNode); } if (e.CanAddChildNode) { PopulateTreeNodes(e); if (this.SortDescriptions.Any()) { SortNodes(e.ParentNode); } } }
internal override void RequestTreeItems(TreeGridRequestTreeItemsEventArgs e) { bool canPopualte = (e.ParentNode != null && e.ParentNode.ChildNodes.Any() && e.ResetChildAndRepopulate) || (e.ParentNode != null && !e.ParentNode.ChildNodes.Any()) || e.ParentNode == null; if (!canPopualte) { if (e.ParentNode != null && SortDescriptions.Any()) { e.ParentNode.ChildNodes.Sort(SortDescriptions, SortComparers); } return; } this.TreeGrid.RaiseRequestTreeItemsEvent(e); if (e.CanAddChildNode) { PopulateTreeNodes(e); if (e.ChildItems != null) { WireNotifyPropertyChange(e.ChildItems); } if (this.SortDescriptions.Any()) { SortNodes(e.ParentNode); } } }
private void AddNodesUnderRootNodes(object item) { TreeNode parentNode = null; if (SortDescriptions.Count == 1 && SortDescriptions.Any(desc => desc.ColumnName == parentPropertyName)) { object newAddItem = null; object childValue = propertyAccessProvider.GetValue(item, childPropertyName); var itemType = this.SourceCollection.GetItemType(true); if (itemType != null) { if (itemType.IsInterface() || itemType.IsAbstract()) { newAddItem = null; } else { newAddItem = itemType.CreateNew(); } propertyAccessProvider.SetValue(newAddItem, parentPropertyName, childValue); } var tempNode = new TreeNode() { Item = newAddItem }; parentNode = FindParentNode(this.Nodes.RootNodes, tempNode); } else { object childValue = propertyAccessProvider.GetValue(item, childPropertyName); parentNode = FindParentNode(this.Nodes.RootNodes, childValue); } if (parentNode == null) { return; } if (parentNode.IsExpanded || parentNode.ChildNodes.Any()) { AddNode(parentNode, item, parentNode.ChildNodes.Count); } else { if (!parentNode.HasVisibleChildNodes) { // If FilterLevel is Root, no need to update HasVisibleChildNodes based on filtering. if (FilterLevel != FilterLevel.Root) { UpdateHasVisibleChildNodesBasedOnChildItem(parentNode, item); } } } parentNode.HasChildNodes = true; ChangeParentNodeExpander(parentNode); }
private void RemoveNodesUnderRootNodes(object item) { TreeNode parentNode = null; // Remove nodes under Root nodes if (SortDescriptions.Count == 1 && SortDescriptions.Any(desc => desc.ColumnName == parentPropertyName)) { object CurrentAddItem = null; object childValue = propertyAccessProvider.GetValue(item, childPropertyName); var itemType = this.SourceCollection.GetItemType(true); if (itemType != null) { if (itemType.IsInterface() || itemType.IsAbstract()) { CurrentAddItem = null; } else { CurrentAddItem = itemType.CreateNew(); } propertyAccessProvider.SetValue(CurrentAddItem, parentPropertyName, childValue); } var tempNode = new TreeNode() { Item = CurrentAddItem }; parentNode = FindParentNode(this.Nodes.RootNodes, tempNode); } else { object childValue = propertyAccessProvider.GetValue(item, childPropertyName); parentNode = FindParentNode(this.Nodes.RootNodes, childValue); } if (parentNode == null) { return; } if (parentNode.IsExpanded || parentNode.ChildNodes.Any()) { RemoveNode(parentNode, item); } else { if (parentNode.HasChildNodes) { parentNode.isVisibleChildNodeAvailabilityChecked = false; ChangeParentNodeExpander(parentNode); } } }
internal override void RequestTreeItems(TreeGridRequestTreeItemsEventArgs e) { bool canPopualate = (e.ParentNode != null && e.ParentNode.ChildNodes.Any() && e.ResetChildAndRepopulate) || (e.ParentNode != null && !e.ParentNode.ChildNodes.Any()) || e.ParentNode == null; if (!canPopualate) { if (e.ParentNode != null) { if (SortDescriptions.Any()) { e.ParentNode.ChildNodes.Sort(SortDescriptions, SortComparers); } } return; } if (e.ParentItem == null) { e.ChildItems = TreeGrid.ItemsSource as IEnumerable; } else { if (!e.ParentNode.HasChildItems || e.ResetChildAndRepopulate) { e.ChildItems = GetChildSource(e.ParentItem, childPropertyName); if (e.ChildItems is INotifyCollectionChanged) { e.ParentNode.HasChildItems = true; } } else { e.ChildItems = (IEnumerable)e.ParentNode.ChildItems; } } if (e.ChildItems != null && e.ParentNode != null) { WireNotifyPropertyChange(e.ChildItems, e.ParentNode); } if (e.CanAddChildNode) { PopulateTreeNodes(e); if (this.SortDescriptions.Any()) { SortNodes(e.ParentNode); } } }
/// <summary> /// Saves the songs to the database /// </summary> /// <param name="songs">Songs being saved</param> private void SaveSongs(IEnumerable <Song> songs) { List <SortDescription> sortDescriptions = new List <SortDescription>(SortDescriptions); OnMediaItemsSaved(songs); SortDescriptions.Clear(); foreach (SortDescription sortDescription in sortDescriptions) { SortDescriptions.Add(sortDescription); } mivSongs.UpdateLayout(); }
/// <summary> /// Saves the videos to the database /// </summary> /// <param name="videos">Videos being saved</param> private void SaveVideos(IEnumerable <Video> videos) { List <SortDescription> sortDescriptions = new List <SortDescription>(SortDescriptions); OnMediaItemsSaved(videos); SortDescriptions.Clear(); foreach (SortDescription sortDescription in sortDescriptions) { SortDescriptions.Add(sortDescription); } mivVideos.UpdateLayout(); }
private void dgMediaItems_ItemsSourceChanged(object sender, System.EventArgs e) { SortDescriptions.Clear(); foreach (SortDescription sortDescription in previousSortDescriptions) { DataGridColumn column = Columns.SingleOrDefault(p => p.SortMemberPath == sortDescription.PropertyName); if (column != null) { column.SortDirection = sortDescription.Direction; } SortDescriptions.Add(sortDescription); } }
public SortViewModel(ICollectionView source, SortData[] columns, IEnumerable <SortDescription> existing = null, SortData[] requiredColumns = null) { View = source; Columns = columns; _requiredColumns = requiredColumns ?? new SortData[0]; if (existing != null) { var d = View.DeferRefresh(); SortDescriptions.Clear(); foreach (var c in _requiredColumns) { SortDescriptions.Add(c.ToSortDescription()); } var item = existing .FirstOrDefault(x => Columns.Select(y => y.Value).Contains(x.PropertyName)); if (item != default(SortDescription)) { SelectedSort = Columns.First(x => x.Value == item.PropertyName); SelectedSort.SortDirection = item.Direction; SortDescriptions.Add(item); } d.Dispose(); } else { var item = SortDescriptions.FirstOrDefault(x => Columns.Select(y => y.Value).Contains(x.PropertyName)); if (item != default(SortDescription)) { SelectedSort = Columns.First(x => x.Value == item.PropertyName); SelectedSort.SortDirection = item.Direction; } } OldSelectedSort = SelectedSort; this.WhenAnyValue(x => x.SelectedSort) .Skip(1) .Subscribe(x => SortColumn()); this.SetCommand(x => x.SortCommand).Subscribe(x => SortColumn()); this.SetCommand(x => x.ToggleVisibilityCommand).Subscribe(x => ToggleVisibility()); }
void SortColumn() { var data = SelectedSort; var d = View.DeferRefresh(); _requiredColumns.Select(x => x.ToSortDescription()).SyncCollection(SortDescriptions); if (data != null) { if (OldSelectedSort == data) { data.SortDirection = data.SortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending; } SortDescriptions.Add(data.ToSortDescription()); } OldSelectedSort = data; d.Dispose(); }
/// <summary> /// Determines whether a view refresh is needed. /// </summary> /// <param name = "propertyName">The name of the changed property.</param> /// <returns> /// <c>True</c> if a view refresh needed; otherwise, <c>false</c>. /// </returns> private bool IsViewRefreshNeeded(string propertyName) { return(SortDescriptions.Any(sort => string.Equals(sort.PropertyName, propertyName)) || GroupDescriptions.OfType <PropertyGroupDescription>().Where(g => string.Equals(g.PropertyName, propertyName)).Any()); }