Example #1
0
        internal QueryGroupsEventArgs(
            DataGridVirtualizingCollectionView collectionView,
            DataGridVirtualizingCollectionViewGroup parentGroup,
            GroupDescription childGroupDescription)
        {
            m_dataGridVirtualizingCollectionView = collectionView;
            m_readonlyGroupPath         = parentGroup.GroupPath.AsReadOnly();
            m_childGroupDescription     = childGroupDescription;
            this.ChildGroupPropertyName = DataGridCollectionViewBase.GetPropertyNameFromGroupDescription(childGroupDescription);

            m_sortDirection = SortDirection.None;

            SortDescriptionCollection sortDescriptions = m_dataGridVirtualizingCollectionView.SortDescriptions;

            int sortDescriptionCount = (sortDescriptions == null) ? 0 : sortDescriptions.Count;

            for (int i = 0; i < sortDescriptions.Count; i++)
            {
                SortDescription sortDescription = sortDescriptions[i];

                if (string.Equals(sortDescription.PropertyName, this.ChildGroupPropertyName))
                {
                    m_sortDirection = (sortDescription.Direction == ListSortDirection.Ascending) ? SortDirection.Ascending : SortDirection.Descending;
                    break;
                }
            }

            m_childGroupNameCountPairs = new List <GroupNameCountPair>();
        }
Example #2
0
        private static IDisposable DeferResortHelper(
            IEnumerable itemsSourceCollection,
            CollectionView collectionView,
            SortDescriptionCollection sortDescriptions)
        {
            IDisposable resortDisposable = null;
            DataGridSortDescriptionCollection dataGridSortDescriptions = sortDescriptions as DataGridSortDescriptionCollection;

            if (dataGridSortDescriptions != null)
            {
                // We are in a detail
                resortDisposable = dataGridSortDescriptions.DeferResort();
            }
            else
            {
                Debug.Assert(collectionView != null, "We must have a CollectionView when we are not processing a Detail");

                DataGridCollectionViewBase dataGridCollectionView = itemsSourceCollection as DataGridCollectionViewBase;

                if (dataGridCollectionView != null)
                {
                    resortDisposable = dataGridCollectionView.DataGridSortDescriptions.DeferResort();
                }
                else
                {
                    resortDisposable = collectionView.DeferRefresh();
                }
            }
            Debug.Assert(resortDisposable != null);

            return(resortDisposable);
        }
 internal override DataGridCollectionViewBase CreateDetailDataGridCollectionViewBase(
     IEnumerable detailDataSource,
     DataGridDetailDescription parentDetailDescription,
     DataGridCollectionViewBase rootDataGridCollectionViewBase)
 {
     throw new NotImplementedException();
 }
Example #4
0
        protected override void CancelEditCore()
        {
            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            DataGridCollectionViewBase dataGridCollectionViewBase =
                (dataGridContext == null) ? null : dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

            if (dataGridCollectionViewBase != null)
            {
                // We do not want to call EditItem when the item is the one in the insertionrow
                if (dataGridCollectionViewBase.CurrentEditItem == this.DataContext)
                {
                    dataGridCollectionViewBase.CancelEdit();
                }
            }
            else
            {
                IEditableObject editableObject = this.EditableObject;

                // editableObject can be equal to this when the datarow is directly inserted as Items in the DataGridControl.
                if ((editableObject != null) && (editableObject != this))
                {
                    editableObject.CancelEdit();
                }
            }

            base.CancelEditCore();
        }
Example #5
0
        internal virtual void ApplyExtraPropertiesToView(DataGridCollectionViewBase currentView)
        {
            var currentViewItemProperties = currentView.ItemProperties;

            foreach (var itemProperty in m_itemProperties)
            {
                currentViewItemProperties[itemProperty.Name] = itemProperty;
            }

            var defaultCalculateDistinctValues = this.DefaultCalculateDistinctValues;

            foreach (var itemProperty in currentViewItemProperties)
            {
                // Set default value for CalculateDistinctValues if not explicitly set
                if (!itemProperty.IsCalculateDistinctValuesInitialized)
                {
                    itemProperty.CalculateDistinctValues = defaultCalculateDistinctValues;
                }
            }

            var autoCreateForeignKeyDescriptions = this.AutoCreateForeignKeyDescriptions;

            for (int i = 0; i < m_dataGridDetailDescriptions.Count; i++)
            {
                DataGridDetailDescription detailDescription = m_dataGridDetailDescriptions[i];

                // We assume we want to auto-create ForeignKeyDescriptions for DetailDescriptions
                // if this.AutoCreateForeignKeyDescriptions is true and it was auto-created
                if (detailDescription.IsAutoCreated)
                {
                    detailDescription.AutoCreateForeignKeyDescriptions = autoCreateForeignKeyDescriptions;
                }
            }
        }
Example #6
0
 public DataGridItemEventArgs(
     DataGridCollectionViewBase collectionView,
     object item)
 {
     m_collectionView = collectionView;
     m_item           = item;
 }
Example #7
0
        private void EnsureDataGridCollectionViewBase()
        {
            var success = false;

            try
            {
                var newView = this.EnsureDataGridCollectionViewBaseCore();
                if (newView != m_currentView)
                {
                    this.ClearView();

                    m_currentView = newView;

                    if (m_currentView != null)
                    {
                        m_currentView.ParentCollectionViewSourceBase = m_parentSource;
                    }
                }

                Debug.Assert((m_currentView == null) || (m_currentView.ParentCollectionViewSourceBase == m_parentSource));

                success = true;
            }
            finally
            {
                if (!success)
                {
                    this.ClearView();
                }
            }
        }
        protected internal override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {
            if (this.PropertyDescriptor == null)
            {
                throw new InvalidOperationException("An attempt was made to obtain details of a PropertyDetailDescription object whose PropertyDescriptor property has not been set.");
            }

            this.Seal();

            object value = this.PropertyDescriptor.GetValue(parentItem);

            if (value == null)
            {
                return(null);
            }

            IEnumerable enumeration = value as IEnumerable;

            if (enumeration == null)
            {
                IListSource listSource = value as IListSource;
                if (listSource != null)
                {
                    enumeration = listSource.GetList();
                }
            }

            return(enumeration);
        }
Example #9
0
        private void EnsurePosition(DataGridContext dataGridContext)
        {
            // In the case the ItemsSource is a DataGridCollectionView
            // we notify the item that correspond to the DataRow for the possible modification
            // of his data, and should then check if is position is still the same.
            if (dataGridContext == null)
            {
                throw new ArgumentNullException("dataGridContext");
            }

            if (this.IsBeingEdited)
            {
                this.RepositionPending = true;
                return;
            }

            this.RepositionPending = false;

            DataGridCollectionViewBase dataGridCollectionViewBase =
                dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

            if (dataGridCollectionViewBase != null)
            {
                int globalSortedIndex = dataGridCollectionViewBase.IndexOf(this.DataContext);

                if (globalSortedIndex == -1)
                {
                    return;
                }

                dataGridCollectionViewBase.EnsurePosition(globalSortedIndex);
            }
        }
 public DataGridItemCancelEventArgs(
     DataGridCollectionViewBase collectionView,
     object item,
     bool cancel)
     : base(collectionView, item)
 {
     m_cancel = cancel;
 }
        protected internal override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {
            EntityObject entityObject = parentItem as EntityObject;

            if (entityObject == null)
            {
                return(null);
            }

            // Even if EntityObject is not in a loadable state, we must still return the IList
            // so that the ItemProperties can be extracted based on the elements type.
            bool entityObjectLoadable = ItemsSourceHelper.IsEntityObjectLoadable(entityObject);

            // We let the user take charge of handling the details.
            QueryEntityDetailsEventArgs args = new QueryEntityDetailsEventArgs(entityObject);

            if (entityObjectLoadable)
            {
                this.OnQueryDetails(args);
            }

            // The parentItem must implement IEntityWithRelationships
            Type parentItemType = parentItem.GetType();

            if (typeof(IEntityWithRelationships).IsAssignableFrom(parentItemType))
            {
                // Since the relationship was based on the the property
                // name, we must find that property using reflection.
                PropertyInfo propertyInfo = parentItemType.GetProperty(this.RelationName);

                if (propertyInfo != null)
                {
                    RelatedEnd relatedEnd = propertyInfo.GetValue(parentItem, null) as RelatedEnd;

                    if (relatedEnd != null)
                    {
                        // Make sure that the details are loaded
                        // except if the user already handled it.
                        if (!relatedEnd.IsLoaded &&
                            !args.Handled &&
                            entityObjectLoadable)
                        {
                            relatedEnd.Load();
                        }

                        IListSource listSource = relatedEnd as IListSource;

                        // Returns an IList to have proper change notification events.
                        if (listSource != null)
                        {
                            return(listSource.GetList());
                        }
                    }
                }
            }

            return(null);
        }
Example #12
0
        internal override void ApplyExtraPropertiesToView(DataGridCollectionViewBase currentView)
        {
            base.ApplyExtraPropertiesToView(currentView);

            DataGridVirtualizingCollectionViewBase dataGridVirtualizingCollectionView = currentView as DataGridVirtualizingCollectionViewBase;

            dataGridVirtualizingCollectionView.PreemptivePageQueryRatio = this.PreemptivePageQueryRatio;
            dataGridVirtualizingCollectionView.CommitMode = this.CommitMode;
        }
Example #13
0
 public DataGridCreatingNewItemEventArgs(
     DataGridCollectionViewBase collectionView,
     object newItem,
     bool cancel)
     : base(cancel)
 {
     m_collectionView = collectionView;
     m_newItem        = newItem;
 }
        internal void InternalInitialize(DataGridCollectionViewBase parentCollectionView)
        {
            if (string.IsNullOrEmpty(this.RelationName))
            {
                throw new InvalidOperationException("An attempt was made to initialize a detail description that does not have a relation name.");
            }

            this.Initialize(parentCollectionView);
        }
        public DistinctValuesDictionary(DataGridCollectionViewBase dataGridCollectionViewBase)
        {
            if (dataGridCollectionViewBase == null)
            {
                throw new DataGridInternalException("dataGridCollectionView is null.");
            }

            m_dataGridCollectionViewBase = dataGridCollectionViewBase;
        }
Example #16
0
        protected override void EndEditCore()
        {
            DataGridContext dataGridContext = DataGridControl.GetDataGridContext(this);

            base.EndEditCore();

            DataGridCollectionViewBase dataGridCollectionViewBase =
                (dataGridContext == null) ? null : dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

            try
            {
                if (dataGridCollectionViewBase != null)
                {
                    if (dataGridCollectionViewBase.CurrentEditItem == this.DataContext)
                    {
                        dataGridCollectionViewBase.CommitEdit();
                    }
                }
                else
                {
                    IEditableObject editableObject = this.EditableObject;

                    // editableObject can be equal to this when the datarow is directly inserted as Items in the DataGridControl.
                    if ((editableObject != null) && (editableObject != this))
                    {
                        editableObject.EndEdit();
                    }
                }
            }
            catch (Exception exception)
            {
                // Note that we do not update the created cell's Content from the source in case the IEditableObject EndEdit implementation
                // throwed an exception.  This is mainly due because we want to make sure that we do not lose all of the edited cells values.
                // This way, the end user will have the chance to correct the mistakes without loosing everything he typed.

                // If EndEdit throwed, call BeginEdit on the IEditableObject to make sure that it stays in edit mode.
                // We don't have to do this when bound to a DataGridCollectionView since it will take care of it.
                if (dataGridCollectionViewBase == null)
                {
                    IEditableObject editableObject = this.EditableObject;

                    // editableObject can be equal to this when the datarow is directly inserted as Items in the DataGridControl.
                    if ((editableObject != null) && (editableObject != this))
                    {
                        editableObject.BeginEdit();
                    }
                }

                // This method will set a validation error on the row and throw back a DataGridValidationException so that
                // the row stays in edition.
                Row.SetRowValidationErrorOnException(this, exception);
            }

            // Update the created cell's Content from the source in case the IEditableObject EndEdit implementation rectified
            // some values.
            this.UpdateCellsContentBindingTarget();
        }
        internal override void RefreshDistinctValuesForField(DataGridItemPropertyBase dataGridItemProperty)
        {
            if (dataGridItemProperty == null)
            {
                return;
            }

            if (dataGridItemProperty.CalculateDistinctValues == false)
            {
                return;
            }

            // List containing current column distinct values
            HashSet <object> currentColumnDistinctValues = new HashSet <object>();

            ReadOnlyObservableHashList readOnlyColumnDistinctValues = null;

            // If the key is not set in DistinctValues yet, do not calculate distinct values for this field
            if (!(( DistinctValuesDictionary )this.DistinctValues).InternalTryGetValue(dataGridItemProperty.Name, out readOnlyColumnDistinctValues))
            {
                return;
            }

            ObservableHashList columnDistinctValues = readOnlyColumnDistinctValues.InnerObservableHashList;

            // We use the DistinctValuesSortComparer if present, else the SortComparer for the DataGridItemProperty, else,
            // the Comparer used is the one of the base class.
            IComparer distinctValuesSortComparer = dataGridItemProperty.DistinctValuesSortComparer;

            if (distinctValuesSortComparer == null)
            {
                distinctValuesSortComparer = dataGridItemProperty.SortComparer;
            }

            using (columnDistinctValues.DeferINotifyCollectionChanged())
            {
                DataGridVirtualizingQueryableCollectionViewGroupRoot rootGroup = this.RootGroup as DataGridVirtualizingQueryableCollectionViewGroupRoot;

                Debug.Assert(rootGroup != null);

                object[] distinctValues = rootGroup.GetItemPropertyDistinctValues(dataGridItemProperty);

                foreach (object distinctValue in distinctValues)
                {
                    // Compute current value to be able to remove unused values
                    currentColumnDistinctValues.Add(distinctValue);
                }

                DataGridCollectionViewBase.RemoveUnusedDistinctValues(
                    distinctValuesSortComparer, currentColumnDistinctValues, columnDistinctValues, null);
            }
        }
Example #18
0
        internal DeferredOperationManager(DataGridCollectionViewBase collectionView, Dispatcher dispatcher, bool postPendingRefreshWithoutDispatching)
        {
            m_collectionView     = collectionView;
            m_deferredOperations = new List <DeferredOperation>(1000);
            m_invalidatedGroups  = new HashSet <DataGridCollectionViewGroup>();

            if (postPendingRefreshWithoutDispatching)
            {
                this.Add(new DeferredOperation(DeferredOperation.DeferredOperationAction.Refresh, -1, null));
            }

            m_dispatcher = dispatcher;
        }
Example #19
0
        private void ClearView()
        {
            if (m_currentView == null)
            {
                return;
            }

            var view = m_currentView;

            m_currentView = null;

            view.Dispose();
        }
        protected internal override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {
            IListSource listSource = parentItem as IListSource;

            if (listSource == null)
            {
                return(null);
            }

            this.Seal();

            return(listSource.GetList());
        }
Example #21
0
        protected internal override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {
            IEnumerable enumerable = parentItem as IEnumerable;

            if (enumerable == null)
            {
                return(null);
            }

            this.Seal();

            return(enumerable);
        }
Example #22
0
        public DeferredOperationManager(
            DataGridCollectionViewBase collectionViewToUpdate,
            Dispatcher dispatcher,
            bool postPendingRefreshWithoutDispatching)
        {
            m_collectionViewToUpdate = collectionViewToUpdate;

            if (postPendingRefreshWithoutDispatching)
            {
                this.Add(new DeferredOperation(DeferredOperation.DeferredOperationAction.Refresh, -1, null));
            }

            m_dispatcher = dispatcher;
        }
Example #23
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        protected override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {
            Debug.Assert(parentItem is Route);

            IEnumerable <Stop> details = new List <Stop>();

            if (null != parentItem)
            {
                _route  = (Route)parentItem;
                details = new SortedDataObjectCollection <Stop>(_route.Stops, new StopsComparer());
            }

            return(details);
        }
        internal static void UpdateColumnsForeignKeyConfigurations(Dictionary <string, ColumnBase> columns, IEnumerable itemsSourceCollection,
                                                                   Dictionary <string, ItemsSourceHelper.FieldDescriptor> fieldDescriptors, bool autoCreateForeignKeyConfigurations)
        {
            DataGridCollectionViewBase collectionViewBase = itemsSourceCollection as DataGridCollectionViewBase;

            if (collectionViewBase != null)
            {
                ForeignKeyConfiguration.UpdateColumnsForeignKeyConfigurationsFromDataGridCollectionView(columns, collectionViewBase.ItemProperties, autoCreateForeignKeyConfigurations);
            }
            else
            {
                ForeignKeyConfiguration.UpdateColumnsForeignKeyConfigurationsFromFieldDescriptors(columns, fieldDescriptors, autoCreateForeignKeyConfigurations);
            }
        }
Example #25
0
        public static void RemoveListener(DataGridCollectionViewBase source, IWeakEventListener listener)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }

            CurrentManager.ProtectedRemoveListener(source, listener);
        }
Example #26
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        protected override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {
            IEnumerable <MessageDetailDataWrap> details = new List <MessageDetailDataWrap>();

            if (null != parentItem)
            {
                _parentDataObject = (MessageWindowDataWrapper?)parentItem;
                if (_parentDataObject.HasValue)
                {
                    details = _parentDataObject.Value.Details;
                }
            }

            return(details);
        }
        internal override void ApplyExtraPropertiesToView(DataGridCollectionViewBase currentView)
        {
            base.ApplyExtraPropertiesToView(currentView);

            DataGridCollectionView dataGridCollectionView = currentView as DataGridCollectionView;

            dataGridCollectionView.StatFunctions.Clear();

            foreach (var statFunction in m_statFunctions)
            {
                dataGridCollectionView.StatFunctions.Add(statFunction);
            }

            dataGridCollectionView.UpdateChangedPropertyStatsOnly = this.UpdateChangedPropertyStatsOnly;
        }
        protected internal override void Initialize(DataGridCollectionViewBase parentCollectionView)
        {
            base.Initialize(parentCollectionView);

            if (this.PropertyDescriptor != null)
            {
                return;
            }

            string relationName = this.RelationName;

            if (String.IsNullOrEmpty(relationName) == true)
            {
                throw new InvalidOperationException("An attempt was made to initialize a PropertyDetailDescription whose Name property has not been set.");
            }

            var enumeration = parentCollectionView as IEnumerable;

            if (enumeration != null)
            {
                // Try to get it from the first item in the DataGridCollectionView
                var firstItem = ItemsSourceHelper.GetFirstItemByEnumerable(enumeration);
                if (firstItem != null)
                {
                    var propertyDescriptor = this.GetPropertyDescriptorFromFirstItem(firstItem);
                    if (propertyDescriptor != null)
                    {
                        this.PropertyDescriptor = propertyDescriptor;
                        return;
                    }
                }
            }

            // If the list is empty, check if the SourceCollection is ITypedList
            var typedList = parentCollectionView.SourceCollection as ITypedList;

            if (typedList != null)
            {
                var propertyDescriptor = this.GetPropertyDescriptorFromITypedList(typedList);
                if (propertyDescriptor != null)
                {
                    this.PropertyDescriptor = propertyDescriptor;
                    return;
                }
            }

            throw new InvalidOperationException("An attempt was made to initialize a PropertyDetailDescription whose data source does not contain a property that corresponds to the specified relation name.");
        }
Example #29
0
        internal override void ApplyExtraPropertiesToView(DataGridCollectionViewBase currentView)
        {
            base.ApplyExtraPropertiesToView(currentView);

            DataGridCollectionView dataGridCollectionView = currentView as DataGridCollectionView;

            dataGridCollectionView.StatFunctions.Clear();
            int count = m_statFunctions.Count;

            for (int i = 0; i < count; i++)
            {
                dataGridCollectionView.StatFunctions.Add(m_statFunctions[i]);
            }

            dataGridCollectionView.UpdateChangedPropertyStatsOnly = this.UpdateChangedPropertyStatsOnly;
        }
        internal DataGridGroupInfo(GroupDescription groupDescription, CollectionViewGroup collectionViewGroup)
        {
            if (groupDescription == null)
            {
                throw new ArgumentNullException("groupDescription");
            }

            if (collectionViewGroup == null)
            {
                throw new ArgumentNullException("collectionViewGroup");
            }

            this.GroupDescription = groupDescription;
            this.PropertyName     = DataGridCollectionViewBase.GetPropertyNameFromGroupDescription(groupDescription);
            this.Value            = collectionViewGroup.Name;
        }