Exemple #1
0
        public static void AddNewGroupFromColumnManagerCell(ColumnManagerCell cell, GroupLevelDescription draggedOverDescription, DropMarkAlignment alignment, DataGridControl parentDataGridControl)
        {
            if (cell == null)
            {
                return;
            }

            DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext(cell);
            DataGridControl cellParentGrid      = cellDataGridContext.DataGridControl;

            if ((cellDataGridContext == null) ||
                (parentDataGridControl == null) ||
                (parentDataGridControl != cellParentGrid))
            {
                return;
            }

            // By default, add it at the end
            int newPos = cellDataGridContext.GroupLevelDescriptions.Count;

            if (draggedOverDescription != null)
            {
                newPos = GroupingHelper.GetGroupDescriptionIndexFromFieldName(cellDataGridContext, draggedOverDescription.FieldName, alignment);
            }

            ColumnBase column = cell.ParentColumn;

            if (column != null)
            {
                GroupingHelper.AddNewGroupFromColumn(column, cellDataGridContext.Items.GroupDescriptions, newPos);
            }
        }
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if ((draggedCell == null) || (this == draggedCell))
            {
                return(false);
            }

            ColumnManagerRow parentRow = this.ParentRow as ColumnManagerRow;

            if ((parentRow == null) || !parentRow.AllowColumnReorder)
            {
                return(false);
            }

            if (!ColumnManagerCell.CanMove(draggedCell) || !ColumnManagerCell.CanMove(this))
            {
                return(false);
            }

            DataGridContext draggedDetailContext = draggedCell.DataGridContext;
            DataGridContext sourceDetailContext  = this.DataGridContext;

            Debug.Assert((draggedDetailContext != null) && (sourceDetailContext != null));

            return((sourceDetailContext.SourceDetailConfiguration == draggedDetailContext.SourceDetailConfiguration) &&
                   (sourceDetailContext.GroupLevelDescriptions == draggedDetailContext.GroupLevelDescriptions));
        }
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            bool canDrop = false;

            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell == null)
            {
                return(false);
            }

            ColumnReorderingDragSourceManager manager =
                draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                ColumnManagerCell cell = draggedElement as ColumnManagerCell;

                if ((cell != null) &&
                    (cell.IsBeingDragged))
                {
                    DataGridContext rowDataGridContext = DataGridControl.GetDataGridContext(this);

                    if ((rowDataGridContext != null) &&
                        (rowDataGridContext.Columns.Contains(cell.ParentColumn)))
                    {
                        canDrop = true;
                    }
                }
            }

            return(canDrop);
        }
        void IDropTarget.DragLeave(UIElement draggedElement)
        {
            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell != null)
            {
                HierarchicalGroupByControlNode hierarchicalGroupByControlNode = this.GetHierarchicalGroupByControlNodeFromColumnManagerCell(cell);

                // It may not be visible
                if (hierarchicalGroupByControlNode != null)
                {
                    hierarchicalGroupByControlNode.HideFarDropMark();
                }
            }
            else
            {
                HierarchicalGroupByItem hierarchicalGroupByItem = draggedElement as HierarchicalGroupByItem;
                if (hierarchicalGroupByItem == null)
                {
                    return;
                }

                HierarchicalGroupByControlNode hierarchicalGroupByControlNode = this.GetHierarchicalGroupByControlNodeFromHierarchicalGroupByItem(hierarchicalGroupByItem);

                Debug.Assert(hierarchicalGroupByControlNode != null, "CanDrop should have returned false");
                if (hierarchicalGroupByControlNode == null)
                {
                    throw new DataGridInternalException("A HierarchicalGroupByControlNode must exist for every level.");
                }

                hierarchicalGroupByControlNode.HideFarDropMark();
            }
        }
        void IDropTarget.Drop(UIElement draggedElement)
        {
            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell == null)
            {
                return;
            }

            HierarchicalGroupByControlNode hierarchicalGroupByControlNode = this.GetHierarchicalGroupByControlNodeFromColumnManagerCell(cell);

            // It may not be visible
            if (hierarchicalGroupByControlNode != null)
            {
                hierarchicalGroupByControlNode.HideFarDropMark(cell);
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            DataGridControl parentGrid = (dataGridContext != null)
        ? dataGridContext.DataGridControl
        : null;

            GroupingHelper.AppendNewGroupFromColumnManagerCell(cell, parentGrid);

            // Notify groups have changed for NoGroupContent
            this.UpdateHasGroups();
        }
Exemple #6
0
        void IDropTarget.DragLeave(UIElement draggedElement)
        {
            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell == null)
            {
                return;
            }

            DataGridContext draggedDetailContext = DataGridControl.GetDataGridContext(draggedElement);

            int lastIndex = draggedDetailContext.GroupLevelDescriptions.Count - 1;

            if (lastIndex > -1)
            {
                GroupByItem groupByItem = this.ItemContainerGenerator.ContainerFromIndex(lastIndex) as GroupByItem;

                Debug.Assert(groupByItem != null);
                if (groupByItem == null)
                {
                    throw new DataGridInternalException();
                }

                groupByItem.HideDropMark();
            }
            else
            {
                this.HideDropMark();
            }
        }
        private static bool CanMove(ColumnManagerCell cell)
        {
            if (cell == null)
            {
                return(false);
            }

            var dataGridContext = cell.DataGridContext;

            if (dataGridContext == null)
            {
                return(false);
            }

            if (dataGridContext.AreDetailsFlatten)
            {
                // Column reordering is not allowed for a ColumnManagerCell that is located at a detail level
                // when details are flatten.
                if (dataGridContext.SourceDetailConfiguration != null)
                {
                    return(false);
                }

                // The main column is not allowed to be reordered when details are flatten.
                var parentColumn = cell.ParentColumn;
                if ((parentColumn == null) || (parentColumn.IsMainColumn))
                {
                    return(false);
                }
            }

            return(true);
        }
        internal void ProcessDrop(ColumnManagerCell draggedCell, RelativePoint mousePosition)
        {
            var manager = default(ColumnReorderingDragSourceManager);

            if (draggedCell != null)
            {
                manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;
            }

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                manager.CommitReordering();
            }
            else
            {
                this.HideDropMark();

                var dataGridContext = this.DataGridContext;
                Debug.Assert(dataGridContext != null);

                if (dataGridContext != null)
                {
                    var targetColumn = draggedCell.ParentColumn;
                    var pivotColumn  = this.ParentColumn;

                    Debug.Assert(targetColumn != null);
                    Debug.Assert(pivotColumn != null);

                    var relativePosition = mousePosition.GetPoint(this);
                    var offset           = Point.Subtract(mousePosition.GetPoint(draggedCell), relativePosition);
                    var moveBefore       = true;

                    // We assumme the cells are layouted horizontally.
                    if (Math.Abs(offset.X) >= Math.Abs(offset.Y))
                    {
                        // Consider the case where the columns are layouted from left to right in reverse order.
                        var reverse = ((offset.X > 0d) == (targetColumn.VisiblePosition >= pivotColumn.VisiblePosition));

                        moveBefore = ((relativePosition.X < this.ActualWidth / 2d) != reverse);
                    }
                    // We assume the cells are layouted vertically.
                    else
                    {
                        // Consider the case where the columns are layouted from top to bottom in reverse order.
                        var reverse = ((offset.Y > 0d) == (targetColumn.VisiblePosition >= pivotColumn.VisiblePosition));

                        moveBefore = ((relativePosition.Y < this.ActualHeight / 2d) != reverse);
                    }

                    var success = (moveBefore)
                          ? dataGridContext.MoveColumnBefore(targetColumn, pivotColumn)
                          : dataGridContext.MoveColumnAfter(targetColumn, pivotColumn);

                    Debug.Assert(success);
                }
            }
        }
        void IDropTarget.Drop(UIElement draggedElement)
        {
            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell == null)
            {
                return;
            }

            this.ProcessDrop(draggedCell);
        }
        internal void ProcessDrop(ColumnManagerCell draggedCell)
        {
            ColumnReorderingDragSourceManager manager = null;

            if (draggedCell != null)
            {
                manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;
            }

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                manager.CommitReordering();
            }
            else
            {
                int oldPosition = draggedCell.ParentColumn.VisiblePosition;
                int newPosition = this.ParentColumn.VisiblePosition;

                if (m_dropMarkAdorner != null)
                {
                    DropMarkAlignment alignment = m_dropMarkAdorner.Alignment;

                    this.HideDropMark();

                    if (draggedCell.ParentColumn.VisiblePosition < newPosition)
                    {
                        if (alignment == DropMarkAlignment.Near)
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition - 1;
                        }
                        else
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition;
                        }
                    }
                    else
                    {
                        if (alignment == DropMarkAlignment.Near)
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition;
                        }
                        else
                        {
                            draggedCell.ParentColumn.VisiblePosition = newPosition + 1;
                        }
                    }

                    // This will force every Rows to update there layout
                    ColumnReorderingEventArgs e = new ColumnReorderingEventArgs(ColumnManagerCell.ColumnReorderingEvent, oldPosition, newPosition);
                    this.RaiseEvent(e);
                }
            }
        }
Exemple #11
0
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            bool           allowGroupingModification = true;
            GroupByControl parentGBC = this.GetParentGroupByControl();

            if (parentGBC != null)
            {
                allowGroupingModification = parentGBC.IsGroupingModificationAllowed;
            }

            // We don't accept any ColumnManagerCell from Details
            DataGridContext context = DataGridControl.GetDataGridContext(draggedElement);

            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            bool isAlreadyGroupedBy = false;

            if (cell != null)
            {
                isAlreadyGroupedBy = GroupingHelper.IsAlreadyGroupedBy(cell);
                ColumnBase parentColumn = cell.ParentColumn;

                if ((parentColumn == null) || (!parentColumn.AllowGroup))
                {
                    return(false);
                }
            }

            DataGridContext sourceDetailContext = DataGridControl.GetDataGridContext(this);

            Debug.Assert(sourceDetailContext != null);
            DetailConfiguration sourceDetailConfig = (sourceDetailContext != null) ? sourceDetailContext.SourceDetailConfiguration : null;

            DataGridContext draggedDetailContext = DataGridControl.GetDataGridContext(draggedElement);

            Debug.Assert(draggedDetailContext != null);
            DetailConfiguration draggedDetailConfig = (draggedDetailContext != null) ? draggedDetailContext.SourceDetailConfiguration : null;


            bool canDrop = (sourceDetailConfig == draggedDetailConfig) &&
                           (allowGroupingModification) &&
                           ((draggedElement is ColumnManagerCell) || (draggedElement is GroupByItem)) &&
                           (draggedElement != this) &&
                           (isAlreadyGroupedBy == false);

            if (canDrop && (cell != null))
            {
                canDrop = GroupingHelper.ValidateMaxGroupDescriptions(draggedDetailContext);
            }

            return(canDrop);
        }
        internal void ShowFarDropMark(ColumnManagerCell cell, Point mousePosition)
        {
            Debug.Assert(cell != null);
            if (cell == null)
            {
                return;
            }

            DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext(cell);

            Debug.Assert(cellDataGridContext != null);
            if (cellDataGridContext == null)
            {
                throw new DataGridInternalException("DataGridContext cannot be null on ColumnManagerCell.");
            }

            // We already have GroupLevelDescriptions for this level, we should show DropMark on the last HierarchicalGroupByItem
            if (cellDataGridContext.GroupLevelDescriptions.Count > 0)
            {
                Debug.Assert(cellDataGridContext.GroupLevelDescriptions == this.GroupLevelDescriptions);

                if (cellDataGridContext.GroupLevelDescriptions != this.GroupLevelDescriptions)
                {
                    return;
                }

                int lastIndex = this.GroupLevelDescriptions.Count - 1;

                // If there
                if (lastIndex > -1)
                {
                    HierarchicalGroupByItem hierarchicalGroupByItem = this.ItemContainerGenerator.ContainerFromItem(this.GroupLevelDescriptions[lastIndex]) as HierarchicalGroupByItem;

                    Debug.Assert(hierarchicalGroupByItem != null);
                    if (hierarchicalGroupByItem == null)
                    {
                        return;
                    }

                    hierarchicalGroupByItem.ShowFarDropMark(mousePosition);
                }
                else
                {
                    this.ShowFarDropMark(mousePosition);
                }
            }
            else
            {
                this.ShowFarDropMark(mousePosition);
            }
        }
        void IDropTarget.Drop(UIElement draggedElement)
        {
            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell == null)
            {
                return;
            }

            ColumnReorderingDragSourceManager manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

            if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
            {
                manager.CommitReordering();
            }
        }
        void IDropTarget.DragOver(UIElement draggedElement, Point mousePosition)
        {
            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell != null)
            {
                ColumnReorderingDragSourceManager manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

                // No need for drop mark when performing animated Column reordering
                if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
                {
                    return;
                }
            }

            this.ShowDropMark(mousePosition);
        }
        void IDropTarget.DragLeave(UIElement draggedElement)
        {
            ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

            if (draggedCell != null)
            {
                ColumnReorderingDragSourceManager manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;

                // No need for drop mark when performing animated Column reordering
                if ((manager != null) && (manager.IsAnimatedColumnReorderingEnabled))
                {
                    return;
                }
            }

            this.HideDropMark();
        }
        private void SetColumnBinding(DependencyProperty targetProperty, string sourceProperty)
        {
            if (BindingOperations.GetBinding(this, targetProperty) != null)
            {
                return;
            }

            var binding = ColumnManagerCell.CreateColumnBinding(sourceProperty);

            if (binding != null)
            {
                BindingOperations.SetBinding(this, targetProperty, binding);
            }
            else
            {
                BindingOperations.ClearBinding(this, targetProperty);
            }
        }
        private void SetColumnBinding(DependencyProperty targetProperty, ColumnBase parentColumn, DependencyProperty sourceProperty)
        {
            if (this.HasColumnBinding(targetProperty, parentColumn, sourceProperty))
            {
                return;
            }

            var binding = ColumnManagerCell.CreateColumnBinding(parentColumn, sourceProperty);

            if (binding != null)
            {
                BindingOperations.SetBinding(this, targetProperty, binding);
            }
            else
            {
                BindingOperations.ClearBinding(this, targetProperty);
            }
        }
Exemple #18
0
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            bool isAlreadyGroupedBy = false;

            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell != null)
            {
                isAlreadyGroupedBy = GroupingHelper.IsAlreadyGroupedBy(cell);
                ColumnBase parentColumn = cell.ParentColumn;

                if ((parentColumn == null) || (!parentColumn.AllowGroup))
                {
                    return(false);
                }
            }

            DataGridContext sourceDetailContext = DataGridControl.GetDataGridContext(this);

            Debug.Assert(sourceDetailContext != null);
            DetailConfiguration sourceDetailConfig = (sourceDetailContext != null) ? sourceDetailContext.SourceDetailConfiguration : null;

            DataGridContext draggedDetailContext = DataGridControl.GetDataGridContext(draggedElement);

            Debug.Assert(draggedDetailContext != null);
            DetailConfiguration draggedDetailConfig = (draggedDetailContext != null) ? draggedDetailContext.SourceDetailConfiguration : null;


            bool canDrop = (sourceDetailConfig == draggedDetailConfig) &&
                           (sourceDetailContext != null) &&
                           (draggedDetailContext != null) &&
                           (sourceDetailContext.GroupLevelDescriptions == draggedDetailContext.GroupLevelDescriptions) &&
                           (this.IsGroupingModificationAllowed) &&
                           ((draggedElement is ColumnManagerCell) || (draggedElement is GroupByItem)) &&
                           (!isAlreadyGroupedBy);

            if (canDrop && (cell != null))
            {
                canDrop = GroupingHelper.ValidateMaxGroupDescriptions(draggedDetailContext);
            }

            return(canDrop);
        }
Exemple #19
0
        void IDropTarget.Drop(UIElement draggedElement)
        {
            if (m_dropMarkAdorner != null)
            {
                DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                Debug.Assert(dataGridContext != null);
                if (dataGridContext != null)
                {
                    GroupLevelDescription draggedOverGroupLevelDescription = this.Content as GroupLevelDescription;

                    Debug.Assert(draggedOverGroupLevelDescription != null);
                    if (draggedOverGroupLevelDescription != null)
                    {
                        DropMarkAlignment alignment = m_dropMarkAdorner.Alignment;

                        this.HideDropMark();

                        ColumnManagerCell draggedCell = draggedElement as ColumnManagerCell;

                        if (draggedCell != null)
                        {
                            GroupingHelper.AddNewGroupFromColumnManagerCell(draggedCell, draggedOverGroupLevelDescription, alignment, dataGridContext.DataGridControl);
                        }
                        else
                        {
                            GroupByItem draggedGroupBy = draggedElement as GroupByItem;

                            Debug.Assert(draggedGroupBy != null);

                            if (draggedGroupBy != null)
                            {
                                GroupLevelDescription draggedGroupLevelDescription = draggedGroupBy.Content as GroupLevelDescription;

                                GroupingHelper.MoveGroupDescription(dataGridContext.Columns, dataGridContext.Items.GroupDescriptions, draggedOverGroupLevelDescription, alignment, draggedGroupLevelDescription, dataGridContext.DataGridControl);
                            }
                        }
                    }
                }
            }
        }
    public static bool IsAlreadyGroupedBy( ColumnManagerCell cell )
    {
      DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext( cell );

      GroupLevelDescriptionCollection cellGroupLevelDescriptions = cellDataGridContext.GroupLevelDescriptions;

      bool isAlreadyGroupedBy = false;
      if( cellDataGridContext != null )
      {
        foreach( GroupLevelDescription description in cellGroupLevelDescriptions )
        {
          if( description.FieldName == cell.FieldName )
          {
            isAlreadyGroupedBy = true;
            break;
          }
        }
      }

      return isAlreadyGroupedBy;
    }
        public static bool IsAlreadyGroupedBy(ColumnManagerCell cell)
        {
            DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext(cell);

            GroupLevelDescriptionCollection cellGroupLevelDescriptions = cellDataGridContext.GroupLevelDescriptions;

            bool isAlreadyGroupedBy = false;

            if (cellDataGridContext != null)
            {
                foreach (GroupLevelDescription description in cellGroupLevelDescriptions)
                {
                    if (description.FieldName == cell.FieldName)
                    {
                        isAlreadyGroupedBy = true;
                        break;
                    }
                }
            }

            return(isAlreadyGroupedBy);
        }
Exemple #22
0
        void IDropTarget.Drop(UIElement draggedElement)
        {
            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell == null)
            {
                return;
            }

            DataGridContext draggedDetailContext = DataGridControl.GetDataGridContext(draggedElement);

            int lastIndex = draggedDetailContext.GroupLevelDescriptions.Count - 1;

            if (lastIndex > -1)
            {
                GroupByItem groupByItem = this.ItemContainerGenerator.ContainerFromIndex(lastIndex) as GroupByItem;

                Debug.Assert(groupByItem != null);
                if (groupByItem == null)
                {
                    throw new DataGridInternalException("groupByItem is null.");
                }

                groupByItem.HideDropMark();
            }
            else
            {
                this.HideDropMark();
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            DataGridControl parentGrid = (dataGridContext != null)
        ? dataGridContext.DataGridControl
        : null;

            GroupingHelper.AppendNewGroupFromColumnManagerCell(cell, parentGrid);
        }
        void IDropTarget.Drop(UIElement draggedElement)
        {
            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell == null)
            {
                return;
            }

            HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

            if (parentGBC == null)
            {
                throw new DataGridInternalException("The hierarchical group-by control node must be rooted by a HierarchicalGroupByControl.");
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            DataGridControl parentGrid = (dataGridContext != null)
        ? dataGridContext.DataGridControl
        : null;

            GroupingHelper.AppendNewGroupFromColumnManagerCell(cell, parentGrid);

            // Notify groups have changed for NoGroupContent
            parentGBC.UpdateHasGroups();

            HierarchicalGroupByControlNode hierarchicalGroupByControlNode = parentGBC.GetHierarchicalGroupByControlNodeFromColumnManagerCell(cell);

            if (hierarchicalGroupByControlNode == null)
            {
                return;
            }

            hierarchicalGroupByControlNode.HideFarDropMark(cell);

            this.HideFarDropMark();
        }
        public static void AddNewGroupFromColumnManagerCell(ColumnManagerCell cell, GroupLevelDescription draggedOverDescription, DropMarkAlignment alignment, DataGridControl parentDataGridControl)
        {
            if (cell == null)
            {
                return;
            }

            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(cell);
            ColumnBase      column          = cell.ParentColumn;

            if ((dataGridContext == null) ||
                (parentDataGridControl == null) ||
                (column == null) ||
                (parentDataGridControl != dataGridContext.DataGridControl))
            {
                return;
            }

            var addGroupCommand = dataGridContext.AddGroupCommand;

            if (draggedOverDescription != null)
            {
                var position = GroupingHelper.GetGroupDescriptionIndexFromFieldName(dataGridContext, draggedOverDescription.FieldName, alignment);

                if (addGroupCommand.CanExecute(column, position))
                {
                    addGroupCommand.Execute(column, position);
                }
            }
            else
            {
                if (addGroupCommand.CanExecute(column))
                {
                    addGroupCommand.Execute(column);
                }
            }
        }
        public static bool IsColumnManagerCellInDataGridContext(DataGridContext dataGridContext, ColumnManagerCell cell)
        {
            DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext(cell);

            Debug.Assert(cellDataGridContext != null);

            if ((dataGridContext != null) &&
                (cellDataGridContext != null) &&
                (dataGridContext.GroupLevelDescriptions == cellDataGridContext.GroupLevelDescriptions))
            {
                return(true);
            }

            return(GroupingHelper.IsGroupLevelDescriptionsInDetailConfigurations(dataGridContext.DetailConfigurations, cellDataGridContext.GroupLevelDescriptions));
        }
    public static bool IsColumnManagerCellInDataGridContext( DataGridContext dataGridContext, ColumnManagerCell cell )
    {
      DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext( cell );

      Debug.Assert( cellDataGridContext != null );

      if( ( dataGridContext != null ) &&
          ( cellDataGridContext != null ) &&
          ( dataGridContext.GroupLevelDescriptions == cellDataGridContext.GroupLevelDescriptions ) )
        return true;

      return GroupingHelper.IsGroupLevelDescriptionsInDetailConfigurations( dataGridContext.DetailConfigurations, cellDataGridContext.GroupLevelDescriptions );
    }
    public static void AddNewGroupFromColumnManagerCell( ColumnManagerCell cell, GroupLevelDescription draggedOverDescription, DropMarkAlignment alignment, DataGridControl parentDataGridControl )
    {
      if( cell == null )
        return;

      DataGridContext dataGridContext = DataGridControl.GetDataGridContext( cell );
      ColumnBase column = cell.ParentColumn;

      if( ( dataGridContext == null ) ||
          ( parentDataGridControl == null ) ||
          ( column == null ) ||
          ( parentDataGridControl != dataGridContext.DataGridControl ) )
        return;

      var addGroupCommand = dataGridContext.AddGroupCommand;

      if( draggedOverDescription != null )
      {
        var position = GroupingHelper.GetGroupDescriptionIndexFromFieldName( dataGridContext, draggedOverDescription.FieldName, alignment );

        if( addGroupCommand.CanExecute( column, position ) )
        {
          addGroupCommand.Execute( column, position );
        }
      }
      else
      {
        if( addGroupCommand.CanExecute( column ) )
        {
          addGroupCommand.Execute( column );
        }
      }
    }
 public static void AppendNewGroupFromColumnManagerCell( ColumnManagerCell cell, DataGridControl parentDataGridControl )
 {
   GroupingHelper.AddNewGroupFromColumnManagerCell( cell, null, DropMarkAlignment.Far, parentDataGridControl );
 }
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            bool canDrop = this.AllowGroupingModification;

            ColumnManagerCell       cell = null;
            HierarchicalGroupByItem hierarchicalGroupByItem = null;

            if (canDrop)
            {
                cell = draggedElement as ColumnManagerCell;

                if (cell != null)
                {
                    ColumnBase parentColumn = cell.ParentColumn;

                    if ((parentColumn == null) || (!parentColumn.AllowGroup))
                    {
                        return(false);
                    }

                    // Check if already grouped using the cell's DataGridContext
                    canDrop = !GroupingHelper.IsAlreadyGroupedBy(cell);

                    if (canDrop)
                    {
                        DataGridContext thisDataGridContext = DataGridControl.GetDataGridContext(this);

                        if (thisDataGridContext.Items != null)
                        {
                            canDrop = thisDataGridContext.Items.CanGroup;
                        }

                        if (canDrop)
                        {
                            canDrop = GroupingHelper.IsColumnManagerCellInDataGridContext(thisDataGridContext, cell);

                            if (canDrop == true)
                            {
                                canDrop = GroupingHelper.ValidateMaxGroupDescriptions(DataGridControl.GetDataGridContext(draggedElement));
                            }
                        }
                    }
                }
                else
                {
                    hierarchicalGroupByItem = draggedElement as HierarchicalGroupByItem;

                    if (hierarchicalGroupByItem == null)
                    {
                        canDrop = false;
                    }

                    if (canDrop)
                    {
                        // Try to get the HierarchicalGroupByControlNode in which this HierarchicalGroupByItem can be added using the parent HierarchicalGroupByControl => null it can't
                        HierarchicalGroupByControlNode draggedHierarchicalGroupByControlNode = this.GetHierarchicalGroupByControlNodeFromHierarchicalGroupByItem(hierarchicalGroupByItem);

                        if (draggedHierarchicalGroupByControlNode == null)
                        {
                            canDrop = false;
                        }
                    }
                }
            }

            bool returnedValue = ((cell != null) || (hierarchicalGroupByItem != null)) && // ColumnManagerCell or HierarchicalGroupByItem
                                 (canDrop);


            return(returnedValue);
        }
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            ColumnManagerCell       cell = null;
            HierarchicalGroupByItem hierarchicalGroupByItem = null;
            bool canDrop = this.AllowGroupingModification;

            if (canDrop)
            {
                cell = draggedElement as ColumnManagerCell;

                if (cell != null)
                {
                    ColumnBase parentColumn = cell.ParentColumn;

                    if ((parentColumn == null) || (!parentColumn.AllowGroup))
                    {
                        return(false);
                    }

                    // Check if already grouped using the cell's DataGridContext
                    canDrop = !GroupingHelper.IsAlreadyGroupedBy(cell);

                    if (canDrop)
                    {
                        // Get the HierarchicalGroupByControl for this HierarchicalGroupByControlNode
                        HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

                        if (parentGBC == null)
                        {
                            throw new DataGridInternalException("The hierarchical group-by control node must be rooted by a HierarchicalGroupByControl.");
                        }

                        DataGridContext parentGBCDataGridContext = DataGridControl.GetDataGridContext(parentGBC);

                        Debug.Assert(parentGBCDataGridContext != null);

                        if (parentGBCDataGridContext.Items != null)
                        {
                            canDrop = parentGBCDataGridContext.Items.CanGroup;
                        }

                        if (canDrop)
                        {
                            canDrop = GroupingHelper.IsColumnManagerCellInDataGridContext(parentGBCDataGridContext, cell);

                            if (canDrop == true)
                            {
                                canDrop = GroupingHelper.ValidateMaxGroupDescriptions(DataGridControl.GetDataGridContext(draggedElement));
                            }
                        }
                    }
                }
                else
                {
                    hierarchicalGroupByItem = draggedElement as HierarchicalGroupByItem;

                    if (hierarchicalGroupByItem == null)
                    {
                        canDrop = false;
                    }

                    if (canDrop)
                    {
                        HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

                        if (parentGBC == null)
                        {
                            throw new DataGridInternalException("The hierarchical group-by control node must be rooted by a HierarchicalGroupByControl.");
                        }

                        // Try to get the HierarchicalGroupByControlNode in which this HierarchicalGroupByItem can be added using the parent HierarchicalGroupByControl => null it can't
                        HierarchicalGroupByControlNode draggedHierarchicalGroupByControlNode = parentGBC.GetHierarchicalGroupByControlNodeFromHierarchicalGroupByItem(hierarchicalGroupByItem);

                        if (draggedHierarchicalGroupByControlNode == null)
                        {
                            canDrop = false;
                        }
                    }
                }
            }

            bool returnedValue = ((cell != null) || (hierarchicalGroupByItem != null)) &&// ColumnManagerCell or HierarchicalGroupByItem
                                 (canDrop);


            return(returnedValue);
        }
Exemple #31
0
    public static void AddNewGroupFromColumnManagerCell( ColumnManagerCell cell, GroupLevelDescription draggedOverDescription, DropMarkAlignment alignment, DataGridControl parentDataGridControl )
    {
      if( cell == null )
        return;

      DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext( cell );
      DataGridControl cellParentGrid = cellDataGridContext.DataGridControl;

      if( ( cellDataGridContext == null ) ||
          ( parentDataGridControl == null ) ||
          ( parentDataGridControl != cellParentGrid ) )
        return;

      // By default, add it at the end
      int newPos = cellDataGridContext.GroupLevelDescriptions.Count;

      if( draggedOverDescription != null )
        newPos = GroupingHelper.GetGroupDescriptionIndexFromFieldName( cellDataGridContext, draggedOverDescription.FieldName, alignment );

      ColumnBase column = cell.ParentColumn;

      if( column != null )
      {
        GroupingHelper.AddNewGroupFromColumn( column, cellDataGridContext.Items.GroupDescriptions, newPos );
      }
    }
        void IDropTarget.DragOver(UIElement draggedElement, Point mousePosition)
        {
            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell != null)
            {
                DataGridContext draggedCellDataGridContext = DataGridControl.GetDataGridContext(cell);

                HierarchicalGroupByControlNode draggedOverHierarchicalGroupByControlNode = HierarchicalGroupByItem.GetParentHierarchicalGroupByControlNode(this);

                if (draggedCellDataGridContext == null)
                {
                    throw new DataGridInternalException("A ColumnManagerCell must have a DataGridContext.");
                }

                if (draggedOverHierarchicalGroupByControlNode == null)
                {
                    throw new DataGridInternalException();
                }

                if (draggedOverHierarchicalGroupByControlNode.GroupLevelDescriptions == draggedCellDataGridContext.GroupLevelDescriptions)
                {
                    this.ShowDropMark(mousePosition);
                }
                else
                {
                    // This ColumnManagerCell does not belong this parent HierarchicalGroupByControlNode, display the DropMark on the correct one
                    HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(draggedOverHierarchicalGroupByControlNode);

                    if (parentGBC == null)
                    {
                        throw new DataGridInternalException("The hierarchical group-by item must be rooted by a HierarchicalGroupByControl.");
                    }

                    HierarchicalGroupByControlNode hierarchicalGroupByControlNode = parentGBC.GetHierarchicalGroupByControlNodeFromColumnManagerCell(cell);

                    Debug.Assert(hierarchicalGroupByControlNode != null, "CanDrop should have returned false");
                    if (hierarchicalGroupByControlNode == null)
                    {
                        throw new DataGridInternalException("A HierarchicalGroupByControlNode must exist for every level.");
                    }

                    hierarchicalGroupByControlNode.ShowFarDropMark(cell, mousePosition);
                }
            }
            else
            {
                HierarchicalGroupByItem hierarchicalGroupByItem = draggedElement as HierarchicalGroupByItem;

                if (hierarchicalGroupByItem == null)
                {
                    return;
                }

                HierarchicalGroupByControlNode draggedHierarchicalGroupByControlNode = HierarchicalGroupByItem.GetParentHierarchicalGroupByControlNode(hierarchicalGroupByItem);

                HierarchicalGroupByControlNode draggedOverHierarchicalGroupByControlNode = HierarchicalGroupByItem.GetParentHierarchicalGroupByControlNode(this);

                if (draggedHierarchicalGroupByControlNode == null)
                {
                    throw new DataGridInternalException();
                }

                if (draggedOverHierarchicalGroupByControlNode == null)
                {
                    throw new DataGridInternalException();
                }

                if (draggedHierarchicalGroupByControlNode.GroupLevelDescriptions == draggedOverHierarchicalGroupByControlNode.GroupLevelDescriptions)
                {
                    this.ShowDropMark(mousePosition);
                }
                else
                {
                    // This HierarchicalGroupByItem does not belong this parent HierarchicalGroupByControlNode, display the DropMark on the correct one
                    HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(draggedOverHierarchicalGroupByControlNode);

                    if (parentGBC == null)
                    {
                        throw new DataGridInternalException("A hierarchical group-by item must be rooted by a HierarchicalGroupByControl.");
                    }

                    HierarchicalGroupByControlNode hierarchicalGroupByControlNode = parentGBC.GetHierarchicalGroupByControlNodeFromHierarchicalGroupByItem(hierarchicalGroupByItem);

                    Debug.Assert(hierarchicalGroupByControlNode != null, "CanDrop should have returned false");
                    if (hierarchicalGroupByControlNode == null)
                    {
                        throw new DataGridInternalException("A HierarchicalGroupByControlNode must exist for every level.");
                    }

                    hierarchicalGroupByControlNode.ShowFarDropMark(mousePosition);
                }
            }
        }
    internal void ProcessDrop( ColumnManagerCell draggedCell )
    {
      ColumnReorderingDragSourceManager manager = null;

      if( draggedCell != null )
      {
        manager = draggedCell.DragSourceManager as ColumnReorderingDragSourceManager;
      }

      if( ( manager != null ) && ( manager.IsAnimatedColumnReorderingEnabled ) )
      {
        manager.CommitReordering();
      }
      else
      {
        int oldPosition = draggedCell.ParentColumn.VisiblePosition;
        int newPosition = this.ParentColumn.VisiblePosition;

        if( m_dropMarkAdorner != null )
        {
          DropMarkAlignment alignment = m_dropMarkAdorner.Alignment;

          this.HideDropMark();

          if( draggedCell.ParentColumn.VisiblePosition < newPosition )
          {
            if( alignment == DropMarkAlignment.Near )
            {
              draggedCell.ParentColumn.VisiblePosition = newPosition - 1;
            }
            else
            {
              draggedCell.ParentColumn.VisiblePosition = newPosition;
            }
          }
          else
          {
            if( alignment == DropMarkAlignment.Near )
            {
              draggedCell.ParentColumn.VisiblePosition = newPosition;
            }
            else
            {
              draggedCell.ParentColumn.VisiblePosition = newPosition + 1;
            }
          }

          // This will force every Rows to update there layout
          ColumnReorderingEventArgs e = new ColumnReorderingEventArgs( ColumnManagerCell.ColumnReorderingEvent, oldPosition, newPosition );
          this.RaiseEvent( e );

        }
      }
    }
    internal HierarchicalGroupByControlNode GetHierarchicalGroupByControlNodeFromColumnManagerCell( ColumnManagerCell cell )
    {
      Debug.Assert( cell != null );
      if( cell == null )
        return null;

      DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext( cell );

      if( cellDataGridContext == null )
        throw new DataGridInternalException( "A DataGridContext cannot be null on ColumnManagerCell." );

      TreeView treeView = this.GetTemplateChild( @"PART_HierarchicalGroupByControlTreeView" ) as TreeView;

      if( treeView == null )
        return null;

      if( treeView.Items.Count == 0 )
        throw new DataGridInternalException( "The HierarchicalGroupByControl should contain at least one grouping level." );

      // The first item is always the top level HierarchicalGroupByControlNode
      TreeViewItem rootItem = treeView.ItemContainerGenerator.ContainerFromItem( treeView.Items[ 0 ] ) as TreeViewItem;

      // It may not be visible
      if( rootItem == null )
        return null;

      TreeViewItem dropMarkedTreeViewItem = null;

      DataGridContext rootDataGridContext = rootItem.Header as DataGridContext;

      if( ( rootDataGridContext != null ) && ( rootDataGridContext.GroupLevelDescriptions == cellDataGridContext.GroupLevelDescriptions ) )
      {
        dropMarkedTreeViewItem = rootItem;
      }
      else
      {
        GroupLevelDescriptionCollection groupLevelDescriptions = cellDataGridContext.GroupLevelDescriptions;

        dropMarkedTreeViewItem = HierarchicalGroupByControl.GetTreeViewItemFromGroupLevelDescriptionCollection( rootItem, groupLevelDescriptions );
      }

      // If null, it means the cell does not belong to this detail
      if( dropMarkedTreeViewItem == null )
        return null;

      ContentPresenter treeViewItemHeader = dropMarkedTreeViewItem.Template.FindName( "PART_Header", dropMarkedTreeViewItem ) as ContentPresenter;

      // It may not be visible
      if( treeViewItemHeader == null )
        return null;

      HierarchicalGroupByControlNode hierarchicalGroupByControlNode = HierarchicalGroupByControl.GetHierarchicalGroupByControlNode( treeViewItemHeader );

      return hierarchicalGroupByControlNode;
    }
    internal void HideFarDropMark( ColumnManagerCell cell )
    {
      Debug.Assert( cell != null );
      if( cell == null )
        return;

      DataGridContext cellDataGridContext = DataGridControl.GetDataGridContext( cell );

      Debug.Assert( cellDataGridContext != null );
      if( cellDataGridContext == null )
        throw new DataGridInternalException( "DataGridContext cannot be null on ColumnManagerCell." );

      this.HideFarDropMark();

      // We already have GroupLevelDescriptions for this level, we should show DropMark on the last HierarchicalGroupByItem
      if( cellDataGridContext.GroupLevelDescriptions.Count > 0 )
      {
        Debug.Assert( cellDataGridContext.GroupLevelDescriptions == this.GroupLevelDescriptions );

        if( cellDataGridContext.GroupLevelDescriptions != this.GroupLevelDescriptions )
          return;

        int lastIndex = this.GroupLevelDescriptions.Count - 1;

        if( lastIndex > -1 )
        {
          HierarchicalGroupByItem hierarchicalGroupByItem = this.ItemContainerGenerator.ContainerFromItem( this.GroupLevelDescriptions[ lastIndex ] ) as HierarchicalGroupByItem;

          Debug.Assert( hierarchicalGroupByItem != null );
          if( hierarchicalGroupByItem == null )
            return;

          hierarchicalGroupByItem.HideDropMark();
        }
      }
    }
 public static void AppendNewGroupFromColumnManagerCell(ColumnManagerCell cell, DataGridControl parentDataGridControl)
 {
     GroupingHelper.AddNewGroupFromColumnManagerCell(cell, null, DropMarkAlignment.Far, parentDataGridControl);
 }
        void IDropTarget.DragLeave(UIElement draggedElement)
        {
            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell != null)
            {
                HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

                if (parentGBC == null)
                {
                    throw new DataGridInternalException("The hierarchical group-by control node must be rooted by a HierarchicalGroupByControl.");
                }

                HierarchicalGroupByControlNode hierarchicalGroupByControlNode = parentGBC.GetHierarchicalGroupByControlNodeFromColumnManagerCell(cell);

                if (hierarchicalGroupByControlNode == null)
                {
                    throw new DataGridInternalException("A HierarchicalGroupByControlNode must exist for every level.");
                }

                hierarchicalGroupByControlNode.HideFarDropMark(cell);
            }
            else
            {
                HierarchicalGroupByItem hierarchicalGroupByItem = draggedElement as HierarchicalGroupByItem;
                if (hierarchicalGroupByItem == null)
                {
                    return;
                }

                HierarchicalGroupByControlNode draggedHierarchicalGroupByControlNode = HierarchicalGroupByItem.GetParentHierarchicalGroupByControlNode(hierarchicalGroupByItem);

                if (draggedHierarchicalGroupByControlNode == null)
                {
                    throw new DataGridInternalException("draggedHierarchicalGroupByControlNode is null.");
                }

                if (draggedHierarchicalGroupByControlNode.GroupLevelDescriptions == this.GroupLevelDescriptions)
                {
                    this.HideFarDropMark();
                }
                else
                {
                    // This HierarchicalGroupByItem does not belong this parent HierarchicalGroupByControlNode, display the DropMark on the correct one
                    HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

                    Debug.Assert(parentGBC != null);
                    if (parentGBC == null)
                    {
                        throw new DataGridInternalException("The hierarchical group-by control node must be rooted by a HierarchicalGroupByControl");
                    }

                    HierarchicalGroupByControlNode hierarchicalGroupByControlNode = parentGBC.GetHierarchicalGroupByControlNodeFromHierarchicalGroupByItem(hierarchicalGroupByItem);

                    Debug.Assert(hierarchicalGroupByControlNode != null, "CanDrop should have returned false");
                    if (hierarchicalGroupByControlNode == null)
                    {
                        throw new DataGridInternalException("A HierarchicalGroupByControlNode must exist for every level.");
                    }

                    hierarchicalGroupByControlNode.HideFarDropMark();
                }
            }
        }
        void IDropTarget.Drop(UIElement draggedElement)
        {
            ColumnManagerCell draggedColumnManagerCell = draggedElement as ColumnManagerCell;

            if (m_dropMarkAdorner != null)
            {
                GroupLevelDescription draggedOverGroupLevelDescription = this.Content as GroupLevelDescription;

                DropMarkAlignment alignment = m_dropMarkAdorner.Alignment;
                this.HideDropMark();

                if (draggedColumnManagerCell != null)
                {
                    DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                    DataGridControl parentGrid = (dataGridContext != null)
            ? dataGridContext.DataGridControl
            : null;

                    GroupingHelper.AddNewGroupFromColumnManagerCell(draggedColumnManagerCell, draggedOverGroupLevelDescription, alignment, parentGrid);
                }
                else
                {
                    HierarchicalGroupByItem draggedGroupByItem = draggedElement as HierarchicalGroupByItem;

                    if (draggedGroupByItem == null)
                    {
                        return;
                    }

                    GroupLevelDescription draggedGroupLevelDescription = draggedGroupByItem.Content as GroupLevelDescription;

                    DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                    DataGridControl parentDataGridControl = (dataGridContext != null)
            ? dataGridContext.DataGridControl
            : null;

                    GroupLevelDescription destinationGroupLevelDescription = this.Content as GroupLevelDescription;

                    GroupingHelper.MoveGroupDescription(this.ParentColumns, this.ParentGroupDescriptions,
                                                        destinationGroupLevelDescription, alignment,
                                                        draggedGroupLevelDescription, parentDataGridControl);
                }
            }
            else
            {
                // We try to add a new Group which is not in the current GroupLevelDescriptions
                if (draggedColumnManagerCell == null)
                {
                    return;
                }

                DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

                DataGridControl parentGrid = (dataGridContext != null)
          ? dataGridContext.DataGridControl
          : null;

                GroupingHelper.AppendNewGroupFromColumnManagerCell(draggedColumnManagerCell, parentGrid);
            }

            HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

            Debug.Assert(parentGBC != null);
            if (parentGBC == null)
            {
                throw new DataGridInternalException("A hierarchical group-by item must be rooted by a HierarchicalGroupByControl.");
            }

            // Notify groups have changed for NoGroupContent
            parentGBC.UpdateHasGroups();
        }
    private static bool CanMove( ColumnManagerCell cell )
    {
      if( cell == null )
        return false;

      var dataGridContext = cell.DataGridContext;
      if( dataGridContext == null )
        return false;

      if( dataGridContext.AreDetailsFlatten )
      {
        // Column reordering is not allowed for a ColumnManagerCell that is located at a detail level
        // when details are flatten.
        if( dataGridContext.SourceDetailConfiguration != null )
          return false;

        // The main column is not allowed to be reordered when details are flatten.
        var parentColumn = cell.ParentColumn;
        if( ( parentColumn == null ) || ( parentColumn.IsMainColumn ) )
          return false;
      }

      return true;
    }