internal void ShowFarDropMark(Point mousePosition)
        {
            int itemsCount = this.Items.Count;

            if (itemsCount < 1)
            {
                if (m_dropMarkAdorner == null)
                {
                    DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

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

                    Pen pen = UIViewBase.GetDropMarkPen(this);

                    if ((pen == null) && (grid != null))
                    {
                        UIViewBase uiViewBase = grid.GetView() as UIViewBase;
                        pen = uiViewBase.DefaultDropMarkPen;
                    }

                    DropMarkOrientation orientation = UIViewBase.GetDropMarkOrientation(this);

                    if ((orientation == DropMarkOrientation.Default) && (grid != null))
                    {
                        UIViewBase uiViewBase = grid.GetView() as UIViewBase;

                        orientation = uiViewBase.DefaultDropMarkOrientation;
                    }

                    m_dropMarkAdorner = new DropMarkAdorner(this, pen, orientation);

                    AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);

                    if (adornerLayer != null)
                    {
                        adornerLayer.Add(m_dropMarkAdorner);
                    }
                }
                // We Only want the drop mark to be displayed at the end of the HierarchicalGroupByControlNode
                m_dropMarkAdorner.ForceAlignment(DropMarkAlignment.Far);
            }
            else
            {
                HierarchicalGroupByItem hierarchicalGroupByItem = this.ItemContainerGenerator.ContainerFromIndex(itemsCount - 1) as HierarchicalGroupByItem;

                Debug.Assert(hierarchicalGroupByItem != null);

                GroupLevelDescription groupLevelDescription = hierarchicalGroupByItem.Content as GroupLevelDescription;

                Debug.Assert(groupLevelDescription != null);

                // Show Far DropMark only if not already grouped
                if (this.Items.Contains(groupLevelDescription) == false)
                {
                    hierarchicalGroupByItem.ShowFarDropMark(mousePosition);
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            bool isMouseCaptured = this.IsMouseCaptured;
            bool isPressed       = this.IsPressed;

            if (m_dragSourceManager != null)
            {
                m_dragSourceManager.ProcessMouseLeftButtonUp(e);
            }

            if (isMouseCaptured)
            {
                bool click = isPressed;

                if (click)
                {
                    bool           allowSort = true;
                    GroupByControl parentGBC = this.GetParentGroupByControl();

                    if (parentGBC != null)
                    {
                        allowSort = parentGBC.AllowSort;
                    }

                    if (allowSort)
                    {
                        DataGridContext       dataGridContext = DataGridControl.GetDataGridContext(this);
                        GroupLevelDescription groupInfo       = this.Content as GroupLevelDescription;
                        Debug.Assert((dataGridContext != null) && (groupInfo != null));

                        if ((dataGridContext != null) && (groupInfo != null))
                        {
                            ColumnBase column = dataGridContext.Columns[groupInfo.FieldName];

                            if ((column != null) && (column.AllowSort))
                            {
                                bool shiftUnpressed = ((Keyboard.Modifiers & ModifierKeys.Shift) != ModifierKeys.Shift);

                                var toggleColumnSort = dataGridContext.ToggleColumnSortCommand;
                                if (toggleColumnSort.CanExecute(column, shiftUnpressed))
                                {
                                    toggleColumnSort.Execute(column, shiftUnpressed);
                                }

                                e.Handled = true;
                            }
                        }
                    }
                }
            }

            base.OnMouseLeftButtonUp(e);
        }
        private bool TryGetGroupLevelDescription(out GroupLevelDescription result)
        {
            result = m_groupLevelDescription;
            if (result != null)
            {
                return(true);
            }

            m_raiseEventOnGroupLevelDescriptionFound = true;

            return(false);
        }
Exemplo n.º 4
0
        private void DragSourceManager_DroppedOutside(object sender, EventArgs e)
        {
            HierarchicalGroupByControlNode hierarchicalGroupByControlNode = HierarchicalGroupByItem.GetParentHierarchicalGroupByControlNode(this);

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

            bool allowGroupingModification = hierarchicalGroupByControlNode.IsGroupingModificationAllowed;

            if (!allowGroupingModification)
            {
                return;
            }

            ObservableCollection <GroupDescription> groupDescriptions = this.ParentGroupDescriptions;

            if (groupDescriptions != null)
            {
                // Get the HierarchicalGroupByControl before removing us from it
                HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

                GroupLevelDescription groupLevelDescription = this.Content as GroupLevelDescription;

                DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

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

                GroupingHelper.RemoveGroupDescription(groupDescriptions, groupLevelDescription, parentDataGridControl);

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

                // Update the HasGroups property
                Debug.Assert(parentGBC != null);
                if (parentGBC == null)
                {
                    throw new DataGridInternalException("The hierarchical group-by item must be rooted by a HierarchicalGroupByControl.");
                }
            }
        }
Exemplo n.º 5
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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void InitSortDirection()
        {
            ColumnCollection      columns   = this.ParentColumns;
            GroupLevelDescription groupInfo = this.Content as GroupLevelDescription;

            Debug.Assert((columns != null) && (groupInfo != null) || (DesignerProperties.GetIsInDesignMode(this)));
            if ((columns != null) && (groupInfo != null))
            {
                ColumnBase column = columns[groupInfo.FieldName];

                if (column != null)
                {
                    Binding sortBinding = new Binding();
                    sortBinding.Path = new PropertyPath(ColumnBase.SortDirectionProperty);
                    sortBinding.Mode = BindingMode.OneWay;
                    sortBinding.NotifyOnSourceUpdated = true;
                    sortBinding.Source = column;
                    sortBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

                    BindingOperations.SetBinding(this, HierarchicalGroupByItem.SortDirectionInternalProperty, sortBinding);
                }
            }
        }
Exemplo n.º 7
0
        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);
                }
            }
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            bool isMouseCaptured = this.IsMouseCaptured;
            bool isPressed       = this.IsPressed;

            if (m_dragSourceManager != null)
            {
                m_dragSourceManager.ProcessMouseLeftButtonUp(e);
            }

            if (isMouseCaptured)
            {
                bool click = isPressed;

                if (click)
                {
                    // DataGridCollectionView always return true for CanSort
                    bool allowSort = true;

                    // Use the ParentDataGridContext to be sure to get a
                    // DataGridContext of the correct detail level since
                    // all the HierarchicalGroupByItem will share the same DataGridContext
                    // which is the one of the level where the HierarchicalGroupByControl
                    // is located
                    DataGridContext dataGridContext = this.ParentDataGridContext;

                    if ((dataGridContext != null) && (dataGridContext.SourceDetailConfiguration == null))
                    {
                        allowSort = dataGridContext.Items.CanSort;
                    }

                    if (allowSort)
                    {
                        ColumnCollection      columns   = this.ParentColumns;
                        GroupLevelDescription groupInfo = this.Content as GroupLevelDescription;

                        Debug.Assert((columns != null) && (groupInfo != null));

                        if ((columns != null) && (groupInfo != null))
                        {
                            ColumnBase column = columns[groupInfo.FieldName];

                            if ((column != null) && (column.AllowSort))
                            {
                                bool shiftUnpressed = ((Keyboard.Modifiers & ModifierKeys.Shift) != ModifierKeys.Shift);

                                var toggleColumnSort = new HierarchicalGroupByItemToggleColumnSortCommand(this);

                                if (toggleColumnSort.CanExecute(column, shiftUnpressed))
                                {
                                    toggleColumnSort.Execute(column, shiftUnpressed);
                                }

                                e.Handled = true;
                            }
                        }
                    }
                }
            }

            base.OnMouseLeftButtonUp(e);
        }
Exemplo n.º 10
0
        internal HierarchicalGroupByControlNode GetHierarchicalGroupByControlNodeFromHierarchicalGroupByItem(HierarchicalGroupByItem hierarchicalGroupByItem)
        {
            Debug.Assert(hierarchicalGroupByItem != null);
            if (hierarchicalGroupByItem == null)
            {
                return(null);
            }

            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;

            if (rootItem == null)
            {
                throw new DataGridInternalException("The root item is null.");
            }

            GroupLevelDescription detailGroupLevelDescription = hierarchicalGroupByItem.Content as GroupLevelDescription;

            Debug.Assert(detailGroupLevelDescription != null);

            TreeViewItem dropMarkedTreeViewItem = null;

            DataGridContext rootDataGridContext = rootItem.Header as DataGridContext;

            Debug.Assert(rootDataGridContext != null);

            if (rootDataGridContext.GroupLevelDescriptions.Contains(detailGroupLevelDescription))
            {
                dropMarkedTreeViewItem = rootItem;
            }
            else
            {
                dropMarkedTreeViewItem = HierarchicalGroupByControl.GetTreeViewItemFromGroupLevelDescription(rootItem, detailGroupLevelDescription);
            }


            // 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;

            Debug.Assert(treeViewItemHeader != null);
            if (treeViewItemHeader == null)
            {
                throw new DataGridInternalException("An error occurred while retrieving the PART_Header template part of an item containing a HierarchicalGroupByControlNode.");
            }

            HierarchicalGroupByControlNode hierarchicalGroupByControlNode = HierarchicalGroupByControl.GetHierarchicalGroupByControlNode(treeViewItemHeader);

            return(hierarchicalGroupByControlNode);
        }
Exemplo n.º 11
0
        private static TreeViewItem GetTreeViewItemFromGroupLevelDescription(TreeViewItem rootItem, GroupLevelDescription groupLevelDescription)
        {
            TreeViewItem returned = null;

            Debug.Assert(rootItem != null);
            Debug.Assert(groupLevelDescription != null);

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

            foreach (object item in rootItem.Items)
            {
                TreeViewItem child = rootItem.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem;

                Debug.Assert(child != null);
                if (child == null)
                {
                    throw new DataGridInternalException("An item does not contain a valid item.");
                }

                DetailConfiguration detailConfiguration = child.Header as DetailConfiguration;

                if (detailConfiguration == null)
                {
                    throw new DataGridInternalException("An item's DataContext must be a DetailConfiguration except for the top-most HierarchicalGroupByControl, which contains a DataGridContext.");
                }

                if (detailConfiguration.GroupLevelDescriptions.Contains(groupLevelDescription))
                {
                    returned = child;
                    break;
                }

                returned = HierarchicalGroupByControl.GetTreeViewItemFromGroupLevelDescription(child, groupLevelDescription);

                if (returned != null)
                {
                    break;
                }
            }

            return(returned);
        }
Exemplo n.º 12
0
        public static void RemoveGroupDescription(ObservableCollection <GroupDescription> groupDescriptions, GroupLevelDescription groupLevelDescription, DataGridControl parentDataGridControl)
        {
            if ((groupLevelDescription == null) ||
                (parentDataGridControl == null))
            {
                return;
            }

            using (parentDataGridControl.SetQueueBringIntoViewRestrictions(AutoScrollCurrentItemSourceTriggers.CollectionViewCurrentItemChanged))
            {
                groupDescriptions.Remove(groupLevelDescription.GroupDescription);
            }
        }
Exemplo n.º 13
0
        public static void MoveGroupDescription(ColumnCollection targetColumns, ObservableCollection <GroupDescription> targetGroupDescriptions, GroupLevelDescription targetGroupLevelDescription, DropMarkAlignment targetAlignment, GroupLevelDescription movedGroupLevelDescription, DataGridControl parentDataGridControl)
        {
            Debug.Assert(targetColumns != null);
            Debug.Assert(targetGroupDescriptions != null);
            Debug.Assert(targetGroupLevelDescription != null);
            Debug.Assert(movedGroupLevelDescription != null);

            if ((parentDataGridControl == null) ||
                (targetColumns == null) ||
                (targetGroupDescriptions == null) ||
                (targetGroupLevelDescription == null) ||
                (movedGroupLevelDescription == null))
            {
                return;
            }

            int oldPos = GroupingHelper.GetGroupDescriptionIndex(targetGroupDescriptions, movedGroupLevelDescription, DropMarkAlignment.Near);
            int newPos = GroupingHelper.GetGroupDescriptionIndex(targetGroupDescriptions, targetGroupLevelDescription, targetAlignment);

            if (newPos > oldPos)
            {
                newPos--;
            }

            if (newPos != oldPos)
            {
                Debug.Assert(oldPos < targetGroupDescriptions.Count);

                using (parentDataGridControl.SetQueueBringIntoViewRestrictions(AutoScrollCurrentItemSourceTriggers.CollectionViewCurrentItemChanged))
                {
                    targetGroupDescriptions.Move(oldPos, newPos);
                }
            }
        }
Exemplo n.º 14
0
        public static int GetGroupDescriptionIndex(ObservableCollection <GroupDescription> groupDescriptions, GroupLevelDescription groupLevelDescription, DropMarkAlignment alignment)
        {
            int groupIndex = groupDescriptions.IndexOf(groupLevelDescription.GroupDescription);

            if (groupIndex > -1)
            {
                if (alignment == DropMarkAlignment.Far)
                {
                    groupIndex++;
                }

                return(groupIndex);
            }
            else
            {
                // return the size of the Collection if not found
                return(groupDescriptions.Count);
            }
        }
Exemplo n.º 15
0
            private static bool TryFind(IEnumerable <GroupLevelDescription> collection, GroupDescription description, out GroupLevelDescription result)
            {
                if ((collection == null) || (description == null))
                {
                    result = null;
                }
                else
                {
                    result = collection.Where(item => (item.GroupDescription == description)).FirstOrDefault();
                }

                return(result != null);
            }