private void HandleDetailReset( object masterItem, DetailGeneratorNode detailNode ) { GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 ); int masterIndex = nodeHelper.FindItem( masterItem ); // -1 means either taht the master item is below a collapsed group node, or that the item does not exists, validate. if( masterIndex == -1 ) { nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 ); if( !nodeHelper.Contains( masterItem ) ) throw new DataGridInternalException(); } ItemsGeneratorNode masterNode = nodeHelper.CurrentNode as ItemsGeneratorNode; Debug.Assert( masterNode != null, "masterNode != null" ); #if LOG Log.Assert( this, masterNode != null, "masterNode != null" ); #endif //start index will be ignored later on if the masterIndex is -1!! int startIndex = nodeHelper.Index + masterNode.IndexOf( masterItem ) + 1; //details start a master index + 1 List<DetailGeneratorNode> detailsForMaster = null; //edge case, it is possible to receive a Reset from Floating details! if( masterNode.Details == null ) { //check for floating details, if not present, throw, this is an abnormal case. if( !m_floatingDetails.Contains( masterItem ) ) { throw new DataGridInternalException(); } } else { masterNode.Details.TryGetValue( masterNode.Items.IndexOf( masterItem ), out detailsForMaster ); Debug.Assert( detailsForMaster != null, "detailsForMaster != null" ); #if LOG Log.Assert( this, detailsForMaster != null, "detailsForMaster != null" ); #endif } if( detailsForMaster != null ) { //this is required to ensure that if the details that resets is not the first one, the index is calculated appropriatly. foreach( DetailGeneratorNode node in detailsForMaster ) { if( node == detailNode ) { break; } else { startIndex += node.ItemCount; } } //if there were 'items' in the detail node, process the remove of them int oldDetailCount = detailNode.ItemCount; if( oldDetailCount > 0 ) { int endIndex = startIndex + oldDetailCount - 1; //last detail index GeneratorPosition removeGenPos = ( masterIndex != -1 ) ? this.GeneratorPositionFromIndex( startIndex ) : new GeneratorPosition( -1, 1 ); int genRemCount = 0; List<DependencyObject> removedContainers = new List<DependencyObject>(); //this has no uses if the masterIndex is -1 ( collapsed master item ) if( masterIndex != -1 ) { genRemCount = this.RemoveGeneratedItems( startIndex, endIndex, removedContainers ); } masterNode.AdjustItemCount( -oldDetailCount ); this.IncrementCurrentGenerationCount(); //this has no uses if the masterIndex is -1 ( collapsed master item ) if( masterIndex != -1 ) { this.SendRemoveEvent( removeGenPos, masterIndex + 1, oldDetailCount, genRemCount, removedContainers ); } } detailNode.UpdateItemCount(); int newDetailCount = detailNode.ItemCount; if( newDetailCount > 0 ) { GeneratorPosition addGenPos = new GeneratorPosition( -1, 1 ); //this has no uses if the masterIndex is -1 ( collapsed master item ) if( masterIndex != -1 ) { addGenPos = this.GeneratorPositionFromIndex( startIndex ); } masterNode.AdjustItemCount( newDetailCount ); this.IncrementCurrentGenerationCount(); //this has no uses if the masterIndex is -1 ( collapsed master item ) if( masterIndex != -1 ) { this.SendAddEvent( addGenPos, masterIndex + 1, newDetailCount ); } } } }
public Group GetGroupFromItem( object item ) { Group retval = null; GeneratorNode nodeForItem = null; this.EnsureNodeTreeCreated(); //item might be in the "generated" list... much quicker to find-out if it is! int itemGenPosIndex = this.FindFirstGeneratedIndexForLocalItem( item ); if( itemGenPosIndex != -1 ) { //item is generated... nodeForItem = m_genPosToNode[ itemGenPosIndex ]; } else { //only try to find the item is the generator has some content... if( m_startNode != null ) { GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 ); if( nodeHelper.Contains( item ) ) //NOTE: this will only return items directly contained in this generator (not from details ) { //if the nodeHelper was able to locate the content, use the nodeHelper's CurrentNode as the node for the item. nodeForItem = nodeHelper.CurrentNode; } else { throw new InvalidOperationException( "An attempt was made to retrieve the group of an item that does not belong to the generator." ); } } } if( nodeForItem != null ) { GroupGeneratorNode parentGroup = nodeForItem.Parent as GroupGeneratorNode; if( parentGroup != null ) { retval = parentGroup.UIGroup; } } return retval; }
private void HandleDetailMoveRemove( object masterItem, DetailGeneratorNode detailNode, CustomGeneratorChangedEventArgs e ) { GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 ); int masterIndex = nodeHelper.FindItem( masterItem ); //If the masterItem is part of an ItemsGeneratorNode which is below a collapsed group, masterIndex will be -1 if( masterIndex == -1 ) { //in that case, I need to determine the appropriate masterNode another way nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 ); if( !nodeHelper.Contains( masterItem ) ) throw new DataGridInternalException(); } ItemsGeneratorNode masterNode = nodeHelper.CurrentNode as ItemsGeneratorNode; Debug.Assert( masterNode != null, "masterNode != null" ); #if LOG Log.Assert( this, masterNode != null, "masterNode != null" ); #endif int globalIndex = -1; GeneratorPosition convertedGeneratorPosition = ( masterIndex != -1 ) ? this.ConvertDetailGeneratorPosition( e.OldPosition, masterItem, detailNode, out globalIndex ) : new GeneratorPosition( -1, 1 ); if( masterIndex != -1 ) { this.RemoveDetailContainers( convertedGeneratorPosition, e.ItemUICount ); } if( e.Action == NotifyCollectionChangedAction.Remove ) { masterNode.AdjustItemCount( -e.ItemCount ); detailNode.UpdateItemCount(); } this.IncrementCurrentGenerationCount(); if( masterIndex != -1 ) { this.SendRemoveEvent( convertedGeneratorPosition, globalIndex, e.ItemCount, e.ItemUICount, e.RemovedContainers ); } }
public bool Contains( object item ) { this.EnsureNodeTreeCreated(); GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 ); return nodeHelper.Contains( item ); }