// If a DataGridCollectionViewBase is used, get the ItemProperties it defines // to be able to retreive DataGridForeignKeyDescription for each of them // to get the auto-detected ForeignKey ItemsSource (if any). // If a DataGridCollectionViewBase is not used, the ItemsSource must be // manually specified on each Column in order to correctly display/edit the Data internal static void UpdateColumnsForeignKeyConfigurationsFromDataGridCollectionView( Dictionary <string, ColumnBase> columns, DataGridItemPropertyCollection itemProperties, bool autoCreateForeignKeyConfigurations) { if (itemProperties == null) { return; } foreach (DataGridItemPropertyBase itemProperty in itemProperties) { DataGridForeignKeyDescription description = itemProperty.ForeignKeyDescription; if (description == null) { continue; } ColumnBase column; columns.TryGetValue(itemProperty.Name, out column); ForeignKeyConfiguration.SynchronizeForeignKeyConfigurationFromForeignKeyDescription( column as Column, description, autoCreateForeignKeyConfigurations); } }
internal override void OnEditCanceled(DataGridItemEventArgs e) { object item = e.Item; DataGridPageManagerBase pageManager = this.RootGroup.GetVirtualPageManager(); // Compare cached values with current values. If they are the same, we can clear the old values which in turn will // make the item non dirty. bool clearIsDirty = true; VirtualizedItemValueCollection cachedValues = pageManager.GetCachedValuesForItem(item); Debug.Assert(cachedValues != null); DataGridItemPropertyCollection itemProperties = this.ItemProperties; foreach (DataGridItemPropertyBase itemProperty in itemProperties) { object currentValue = itemProperty.GetValue(item); if (!(object.Equals(currentValue, cachedValues[itemProperty.Name]))) { clearIsDirty = false; break; } } if (clearIsDirty) { pageManager.ClearCachedValuesForItem(item); } base.OnEditCanceled(e); }
// If a DataGridCollectionViewBase is used, get the ItemProperties it defines to be able to retreive DataGridForeignKeyDescription for each of them // to get the auto-detected ForeignKey ItemsSource (if any). // If a DataGridCollectionViewBase is not used, the ItemsSource must be manually specified on each Column in order to correctly display/edit the Data internal static void UpdateColumnsForeignKeyConfigurationsFromDataGridCollectionView( ObservableColumnCollection columns, DataGridItemPropertyCollection itemProperties, bool autoCreateForeignKeyConfigurations) { if (itemProperties == null) { return; } foreach (var itemProperty in itemProperties) { var description = itemProperty.ForeignKeyDescription; if (description != null) { var columnName = PropertyRouteParser.Parse(itemProperty); var column = (columnName != null) ? columns[columnName] as Column : null; if (column != null) { ForeignKeyConfiguration.SynchronizeForeignKeyConfigurationFromForeignKeyDescription(column, description, autoCreateForeignKeyConfigurations); } } if (itemProperty.ItemPropertiesInternal != null) { ForeignKeyConfiguration.UpdateColumnsForeignKeyConfigurationsFromDataGridCollectionView( columns, itemProperty.ItemPropertiesInternal, autoCreateForeignKeyConfigurations); } } }
private void OnCollectionChanged(NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Reset) { throw new NotSupportedException(); } var handler = this.CollectionChanged; if (handler == null) { return; } lock (this.SyncRoot) { if (m_deferCollectionChangedCount != 0) { m_deferCollectionChangedEventArgs = DataGridItemPropertyCollection.Combine(m_deferCollectionChangedEventArgs, e); return; } } handler.Invoke(this, e); }
internal override void OnEditBegun(DataGridItemEventArgs e) { object item = e.Item; DataGridPageManagerBase pageManager = this.RootGroup.GetVirtualPageManager(); if (!pageManager.IsItemDirty(item)) { // First time we enter edit on this item. DataGridItemPropertyCollection itemProperties = this.ItemProperties; int count = itemProperties.Count; string[] propertyNames = new string[count]; object[] cachedValues = new object[count]; for (int i = 0; i < count; i++) { DataGridItemPropertyBase itemProperty = itemProperties[i]; propertyNames[i] = itemProperty.Name; cachedValues[i] = itemProperty.GetValue(item); } // Cache the values of the never edited before row. This will help the developer find the corresponding row // in the source when times comes to commit the changes to the data source. pageManager.SetCachedValuesForItem(item, propertyNames, cachedValues); } base.OnEditBegun(e); }
private static NotifyCollectionChangedEventArgs Combine(NotifyCollectionChangedEventArgs x, NotifyCollectionChangedEventArgs y) { if (x == null) { return(y); } if (y == null) { return(x); } var addedItems = DataGridItemPropertyCollection.GetAddedItems(x).ToList(); var removedItems = DataGridItemPropertyCollection.GetRemovedItems(x).ToList(); foreach (var item in DataGridItemPropertyCollection.GetAddedItems(y)) { if (!removedItems.Remove(item)) { Debug.Assert(!addedItems.Contains(item)); addedItems.Add(item); } } foreach (var item in DataGridItemPropertyCollection.GetRemovedItems(y)) { if (!addedItems.Remove(item)) { Debug.Assert(!removedItems.Contains(item)); removedItems.Add(item); } } var addedItemsCount = addedItems.Count; var removedItemsCount = removedItems.Count; if ((addedItemsCount > 0) && (removedItemsCount > 0)) { if ((x.Action != NotifyCollectionChangedAction.Replace) || (y.Action != NotifyCollectionChangedAction.Replace) || (addedItemsCount != removedItemsCount)) { throw new NotSupportedException(); } return(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, addedItems, removedItems)); } if (addedItemsCount > 0) { return(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, addedItems)); } if (removedItemsCount > 0) { return(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removedItems)); } return(null); }
internal void AttachToContainingCollection(DataGridItemPropertyCollection collection) { if (collection == null) { throw new ArgumentNullException("collection"); } this.ContainingCollection = collection; }
internal ItemPropertyNameMap(DataGridItemPropertyCollection itemProperties) { if (itemProperties == null) { throw new ArgumentNullException("itemProperties"); } m_dataGridItemPropertyCollection = new WeakReference(itemProperties); CollectionChangedEventManager.AddListener(itemProperties, this); }
private void MapItemProperties(DataGridItemPropertyCollection masterItemProperties, DataGridItemPropertyCollection detailItemProperties) { if ((masterItemProperties == null) || (masterItemProperties.Count <= 0)) { return; } foreach (var masterItemProperty in masterItemProperties) { this.MapMasterItemProperty(masterItemProperty); } }
private void UnmapDetailItemProperties(DataGridItemPropertyCollection itemProperties) { if (itemProperties == null) { return; } foreach (var itemProperty in itemProperties) { this.UnmapDetailItemProperty(itemProperty); } }
public static void RemoveListener(DataGridItemPropertyCollection source, IWeakEventListener listener) { if (source == null) { throw new ArgumentNullException("source"); } if (listener == null) { throw new ArgumentNullException("listener"); } CurrentManager.ProtectedRemoveListener(source, listener); }
private void UnregisterItemProperties(DataGridItemPropertyCollection itemProperties) { if (itemProperties == null) { return; } foreach (var itemProperty in itemProperties) { this.UnregisterItemProperty(itemProperty); } CollectionChangedEventManager.RemoveListener(itemProperties, this); }
protected DataGridDetailDescription() { m_itemProperties = new DataGridItemPropertyCollection(); m_detailDescriptions = new DataGridDetailDescriptionCollection(); m_defaultPropertyDescriptions = new PropertyDescriptionRouteDictionary(); m_groupDescriptions = new GroupDescriptionCollection(); m_sortDescriptions = new DataGridSortDescriptionCollection(); this.AutoCreateDetailDescriptions = true; this.AutoCreateItemProperties = true; this.DefaultCalculateDistinctValues = true; CollectionChangedEventManager.AddListener(m_itemProperties, this); InitializeItemPropertyEventManager.AddListener(m_itemProperties, this); CollectionChangedEventManager.AddListener(m_detailDescriptions, this); }
internal override void SetUnspecifiedPropertiesValues(DataGridItemPropertyCollection itemPropertyCollection) { if (this.DataType == null) { throw new InvalidOperationException("An attempt was made to add an item without specifying its data type."); } if (string.IsNullOrEmpty(this.Title)) { this.Title = this.Name; } if (!this.OverrideReadOnlyForInsertion.HasValue) { this.OverrideReadOnlyForInsertion = false; } }
protected DataGridDetailDescription() { m_detailDescriptions = new DataGridDetailDescriptionCollection(); m_detailDescriptions.CollectionChanged += this.OnDetailDescriptionsCollectionChanged; m_itemProperties = new DataGridItemPropertyCollection(); m_itemProperties.CollectionChanged += this.OnItemPropertiesCollectionChanged; m_groupDescriptions = new GroupDescriptionCollection(); m_sortDescriptions = new DataGridSortDescriptionCollection(); m_statFunctions = new StatFunctionCollection(); m_autoFilterValues = new ReadOnlyDictionary <string, IList>(); m_autoFilteredItems = new ObservableCollection <DataGridItemPropertyBase>(); m_registeredFieldNamesToAutoFilterValues = new Dictionary <string, INotifyCollectionChanged>(); m_registeredAutoFilterValuesToFieldNames = new Dictionary <INotifyCollectionChanged, string>(); this.AutoCreateDetailDescriptions = true; this.AutoCreateItemProperties = true; this.DefaultCalculateDistinctValues = true; }
public int Compare(RawItem xRawItem, RawItem yRawItem) { if (xRawItem == null) { if (yRawItem == null) { return(0); } else { return(-1); } } else { if (yRawItem == null) { return(1); } } ListSortDirection lastSortDirection = ListSortDirection.Ascending; SortDescriptionCollection sortDescriptions = m_collectionView.SortDescriptions; int sortDescriptionCount = sortDescriptions.Count; if (sortDescriptionCount > 0) { int result; DataGridItemPropertyCollection itemProperties = m_collectionView.ItemProperties; for (int i = 0; i < sortDescriptionCount; i++) { SortDescription sortDescription = sortDescriptions[i]; lastSortDirection = sortDescription.Direction; DataGridItemPropertyBase dataProperty = itemProperties[sortDescription.PropertyName]; if (dataProperty == null) { continue; } ISupportInitialize supportInitialize = dataProperty as ISupportInitialize; object xData = null; object yData = null; if (supportInitialize != null) { supportInitialize.BeginInit(); } try { xData = dataProperty.GetValue(xRawItem.DataItem); yData = dataProperty.GetValue(yRawItem.DataItem); } finally { if (supportInitialize != null) { supportInitialize.EndInit(); } } IComparer sortComparer = dataProperty.SortComparer; if (sortComparer != null) { result = sortComparer.Compare(xData, yData); } else { result = ObjectDataStore.CompareData(xData, yData); } if (result != 0) { if (lastSortDirection == ListSortDirection.Descending) { result = -result; } return(result); } } } if (lastSortDirection == ListSortDirection.Descending) { return(yRawItem.Index - xRawItem.Index); } return(xRawItem.Index - yRawItem.Index); }
internal virtual void SetUnspecifiedPropertiesValues(DataGridItemPropertyCollection itemPropertyCollection) { }
internal static void AddListener(DataGridItemPropertyCollection source, IWeakEventListener listener) { CurrentManager.ProtectedAddListener(source, listener); }
public static void RemoveListener(DataGridItemPropertyCollection source, IWeakEventListener listener) { CurrentManager.ProtectedRemoveListener(source, listener); }
internal DeferState(DataGridItemPropertyCollection target) { Debug.Assert(target != null); m_target = target; }
private Expression GetFilterCriterionsExpression(IQueryable queryable, ParameterExpression sharedParameterExpression) { if (queryable == null) { throw new ArgumentNullException("queryable"); } FilterCriteriaMode filterCriteriaMode = m_parentCollectionView.FilterCriteriaMode; if (filterCriteriaMode == FilterCriteriaMode.None) { return(null); } DataGridItemPropertyCollection itemProperties = m_parentCollectionView.ItemProperties; int itemPropertiesCount = itemProperties.Count; Expression filterCriterionsExpression = null; for (int i = 0; i < itemPropertiesCount; i++) { DataGridItemPropertyBase itemProperty = itemProperties[i]; string itemPropertyName = itemProperty.Name; FilterCriterion filterCriterion = itemProperty.FilterCriterion; if (filterCriterion == null) { continue; } Expression propertyFilterCriterionExpression = filterCriterion.ToLinqExpression(queryable, sharedParameterExpression, itemPropertyName); if (propertyFilterCriterionExpression == null) { continue; } if (filterCriterionsExpression == null) { filterCriterionsExpression = propertyFilterCriterionExpression; } else { Debug.Assert((filterCriteriaMode == FilterCriteriaMode.And) || (filterCriteriaMode == FilterCriteriaMode.Or)); // Merge this DataGridItemProperty FilterCriterionExpressions if (filterCriteriaMode == FilterCriteriaMode.And) { filterCriterionsExpression = Expression.And(filterCriterionsExpression, propertyFilterCriterionExpression); } else { filterCriterionsExpression = Expression.Or(filterCriterionsExpression, propertyFilterCriterionExpression); } } // Loop to next DataGridItemProperty. } return(filterCriterionsExpression); }
internal override void SetUnspecifiedPropertiesValues(DataGridItemPropertyCollection itemPropertyCollection) { // ContainingCollection.ItemType and ContainingCollection.DefaultItemProperties can be null at first when this is // the ItemProperties of a DetailGrid. // the SetUnspecifiedPropertiesValues will be recall when both this.ItemType and this.DefaultItemProperties are affected. if (itemPropertyCollection == null) { return; } DataGridItemProperty defaultItemProperty = null; bool itemIsXceedDataRow = (itemPropertyCollection.ItemType != null) ? typeof(DataRow).IsAssignableFrom(itemPropertyCollection.ItemType) : false; if ((string.IsNullOrEmpty(this.ValueXPath)) && (string.IsNullOrEmpty(this.ValuePath)) && (this.PropertyDescriptor == null)) { if (itemIsXceedDataRow) { this.PropertyDescriptor = new UnboundDataRowPropertyDescriptor(this.Name, this.DataType); } else { defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty; if (defaultItemProperty == null) { if (this.Name == ".") { this.SetPropertyDescriptor(new SelfPropertyDescriptor(this.DataType)); this.SetValuePath("."); this.SetIsReadOnly(true); this.SetOverrideReadOnlyForInsertion(false); } else if (itemPropertyCollection.DefaultItemProperties != null) { // I have to add this particular exception case to make sure that when the ItemProperty is "re-normalized" when the first DataGridCollectionView // is created for it, then the ValuePath is still null or empty (allowing it to be re-normalized) this.SetValuePath(this.Name); } } else { this.SetPropertyDescriptor(defaultItemProperty.PropertyDescriptor); this.SetValuePath(defaultItemProperty.ValuePath); this.SetValueXPath(defaultItemProperty.ValueXPath); } } } if (this.DataType == null) { //only try to affect the DataType if the DefaultItemProperties were set. (will not be the case when XAML parsing DetailDescriptions) if (itemPropertyCollection.DefaultItemProperties != null) { if (defaultItemProperty == null) { defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty; } if (defaultItemProperty == null) { throw new InvalidOperationException("An attempt was made to add an item (" + this.Name + ") without specifying its data type."); } this.SetDataType(defaultItemProperty.DataType); } } if (string.IsNullOrEmpty(this.Title)) { if (itemIsXceedDataRow) { this.Title = this.Name; } else { if (defaultItemProperty == null) { defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty; } if (defaultItemProperty == null) { this.Title = this.Name; } else { this.Title = defaultItemProperty.Title; } } } if (!this.IsReadOnly) { if (defaultItemProperty == null) { defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty; } if (defaultItemProperty != null) { this.SetIsReadOnly(defaultItemProperty.IsReadOnly); } } if (this.OverrideReadOnlyForInsertion == null) { //only try to affect the DataType if the DefaultItemProperties were set. (will not be the case when XAML parsing DetailDescriptions) if (itemPropertyCollection.DefaultItemProperties != null) { if (defaultItemProperty == null) { defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty; } this.SetOverrideReadOnlyForInsertion((defaultItemProperty != null) && (defaultItemProperty.OverrideReadOnlyForInsertion.HasValue) ? defaultItemProperty.OverrideReadOnlyForInsertion.Value : false); } } if ((!string.IsNullOrEmpty(this.ValueXPath)) && (string.IsNullOrEmpty(this.ValuePath))) { this.SetValuePath("InnerText"); } bool foreignKeyDescriptionIsNull = (this.ForeignKeyDescription == null); bool foreignKeyDescriptionItemsSourceIsNull = false; if (!foreignKeyDescriptionIsNull) { foreignKeyDescriptionItemsSourceIsNull = (this.ForeignKeyDescription.ItemsSource == null); } // Update the ForeignKeyDescription if not set if (foreignKeyDescriptionIsNull || foreignKeyDescriptionItemsSourceIsNull) { if (defaultItemProperty == null) { defaultItemProperty = itemPropertyCollection.FindDefaultItemProperty(this.Name) as DataGridItemProperty; } if ((defaultItemProperty != null) && (defaultItemProperty.ForeignKeyDescription != null)) { if (foreignKeyDescriptionIsNull) { this.SetForeignKeyDescription(defaultItemProperty.ForeignKeyDescription); } else { if (foreignKeyDescriptionItemsSourceIsNull) { this.ForeignKeyDescription.ItemsSource = defaultItemProperty.ForeignKeyDescription.ItemsSource; } } } } }
internal void DetachFromContainingCollection() { this.ContainingCollection = null; }
internal virtual void ApplyExtraPropertiesToView(DataGridCollectionViewBase currentView) { DataGridItemPropertyCollection currentViewItemProperties = currentView.ItemProperties; int count = m_itemProperties.Count; for (int i = 0; i < count; i++) { DataGridItemPropertyBase itemProperty = m_itemProperties[i]; int index = currentViewItemProperties.IndexOf(itemProperty.Name); if (index == -1) { currentViewItemProperties.Add(itemProperty); } else { currentViewItemProperties[index] = itemProperty; } } count = currentView.ItemProperties.Count; bool defaultCalculateDistinctValues = this.DefaultCalculateDistinctValues; for (int i = 0; i < count; i++) { DataGridItemPropertyBase dataGridItemProperty = currentView.ItemProperties[i]; // Set default value for CalculateDistinctValues if not explicitly set if (!dataGridItemProperty.IsCalculateDistinctValuesInitialized) { dataGridItemProperty.CalculateDistinctValues = defaultCalculateDistinctValues; } } count = m_dataGridDetailDescriptions.Count; bool autoCreateForeignKeyDescriptions = this.AutoCreateForeignKeyDescriptions; DataGridDetailDescriptionCollection currentViewDetailDescriptions = currentView.DetailDescriptions; for (int i = 0; i < count; i++) { DataGridDetailDescription detailDescription = m_dataGridDetailDescriptions[i]; int index = currentViewDetailDescriptions.IndexOf(detailDescription.RelationName); if (index == -1) { currentViewDetailDescriptions.Add(detailDescription); } else { currentViewDetailDescriptions[index] = detailDescription; } // 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; } } currentView.AutoFilterMode = this.AutoFilterMode; currentView.DistinctValuesConstraint = this.DistinctValuesConstraint; currentView.DistinctValuesUpdateMode = this.DistinctValuesUpdateMode; currentView.FilterCriteriaMode = this.FilterCriteriaMode; }
protected override void StopListening(object source) { DataGridItemPropertyCollection itemProperties = source as DataGridItemPropertyCollection; itemProperties.CollectionChanged -= new NotifyCollectionChangedEventHandler(ItemProperties_CollectionChanged); }
private void OnItemPropertyCollectionChanged(DataGridItemPropertyCollection collection, NotifyCollectionChangedEventArgs e) { var rootCollection = ItemsSourceHelper.GetRootCollection(collection); if (rootCollection == null) { return; } if (rootCollection == m_masterItemProperties) { if (e.Action == NotifyCollectionChangedAction.Reset) { throw new NotSupportedException(); } if (e.Action == NotifyCollectionChangedAction.Move) { return; } using (this.DeferMappingChanged()) { if (e.OldItems != null) { foreach (DataGridItemPropertyBase itemProperty in e.OldItems) { this.UnregisterItemProperty(itemProperty); this.UnmapMasterItemProperty(itemProperty); } } if (e.NewItems != null) { foreach (DataGridItemPropertyBase itemProperty in e.NewItems) { this.RegisterItemProperty(itemProperty); this.MapMasterItemProperty(itemProperty); } } } } else if (rootCollection == m_detailItemProperties) { if (e.Action == NotifyCollectionChangedAction.Reset) { throw new NotSupportedException(); } if (e.Action == NotifyCollectionChangedAction.Move) { return; } using (this.DeferMappingChanged()) { if (e.OldItems != null) { foreach (DataGridItemPropertyBase itemProperty in e.OldItems) { this.UnregisterItemProperty(itemProperty); this.UnmapDetailItemProperty(itemProperty); } } if (e.NewItems != null) { foreach (DataGridItemPropertyBase itemProperty in e.NewItems) { this.RegisterItemProperty(itemProperty); this.MapDetailItemProperty(itemProperty); } } } } else { Debug.Fail("The collection should have been either for the master or the detail item properties."); CollectionChangedEventManager.RemoveListener(collection, this); } }
private Expression GetAutoFilterValuesExpression(IQueryable queryable, ParameterExpression sharedParameterExpression) { if (queryable == null) { throw new ArgumentNullException("queryable"); } AutoFilterMode autoFilterMode = m_parentCollectionView.AutoFilterMode; if (autoFilterMode == AutoFilterMode.None) { return(null); } DataGridItemPropertyCollection itemProperties = m_parentCollectionView.ItemProperties; int itemPropertiesCount = itemProperties.Count; Expression autoFilterValuesExpression = null; for (int i = 0; i < itemPropertiesCount; i++) { DataGridItemPropertyBase itemProperty = itemProperties[i]; string itemPropertyName = itemProperty.Name; IList itemPropertyAutoFilterValues; if (m_parentCollectionView.AutoFilterValues.TryGetValue(itemPropertyName, out itemPropertyAutoFilterValues)) { int itemPropertyAutoFilterValuesCount = itemPropertyAutoFilterValues.Count; if (itemPropertyAutoFilterValuesCount == 0) { continue; } object[] itemPropertyAutoFilterValuesArray = new object[itemPropertyAutoFilterValuesCount]; itemPropertyAutoFilterValues.CopyTo(itemPropertyAutoFilterValuesArray, 0); Expression itemPropertyAutoFilterExpression = queryable.CreateEqualExpression(sharedParameterExpression, itemPropertyName, itemPropertyAutoFilterValuesArray); if (autoFilterValuesExpression == null) { autoFilterValuesExpression = itemPropertyAutoFilterExpression; } else { Debug.Assert((autoFilterMode == AutoFilterMode.And) || (autoFilterMode == AutoFilterMode.Or)); // Merge this DataGridItemProperty AutoFilterExpressions if (autoFilterMode == AutoFilterMode.And) { autoFilterValuesExpression = Expression.And(autoFilterValuesExpression, itemPropertyAutoFilterExpression); } else { autoFilterValuesExpression = Expression.Or(autoFilterValuesExpression, itemPropertyAutoFilterExpression); } } } // Loop to next DataGridItemProperty. } return(autoFilterValuesExpression); }