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);
        }
        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);
        }
示例#3
0
        internal ItemPropertyNameMap(DataGridItemPropertyCollection itemProperties)
        {
            if (itemProperties == null)
            {
                throw new ArgumentNullException("itemProperties");
            }

            m_dataGridItemPropertyCollection = new WeakReference(itemProperties);

            CollectionChangedEventManager.AddListener(itemProperties, this);
        }
示例#4
0
        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);
        }
        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 Nequeo.Wpf.Collections.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;
        }
示例#7
0
        protected override void StopListening(object source)
        {
            DataGridItemPropertyCollection itemProperties = source as DataGridItemPropertyCollection;

            itemProperties.CollectionChanged -= new NotifyCollectionChangedEventHandler(ItemProperties_CollectionChanged);
        }
示例#8
0
 public static void RemoveListener(DataGridItemPropertyCollection source, IWeakEventListener listener)
 {
     CurrentManager.ProtectedRemoveListener(source, listener);
 }
        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;
        }
 internal virtual void SetUnspecifiedPropertiesValues(DataGridItemPropertyCollection itemPropertyCollection)
 {
 }
        // 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);
            }
        }
        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);
        }
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        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 itemIsNequeoDataRow = (itemPropertyCollection.ItemType != null) ? typeof(DataRow).IsAssignableFrom(itemPropertyCollection.ItemType) : false;

            if ((string.IsNullOrEmpty(this.ValueXPath)) &&
                (string.IsNullOrEmpty(this.ValuePath)) &&
                (this.PropertyDescriptor == null))
            {
                if (itemIsNequeoDataRow)
                {
                    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 (itemIsNequeoDataRow)
                {
                    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;
                        }
                    }
                }
            }
        }