コード例 #1
0
        // 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);
                }
            }
        }
        internal override void OnEditCanceled(DataGridItemEventArgs e)
        {
            var item        = e.Item;
            var 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.
            var clearIsDirty = true;

            var cachedValues = pageManager.GetCachedValuesForItem(item);

            Debug.Assert(cachedValues != null);

            var itemProperties = this.ItemProperties;

            foreach (var itemProperty in itemProperties)
            {
                var currentValue = ItemsSourceHelper.GetValueFromItemProperty(itemProperty, item);

                if (!(object.Equals(currentValue, cachedValues[PropertyRouteParser.Parse(itemProperty)])))
                {
                    clearIsDirty = false;
                    break;
                }
            }

            if (clearIsDirty)
            {
                pageManager.ClearCachedValuesForItem(item);
            }

            base.OnEditCanceled(e);
        }
        internal override void OnEditBegun(DataGridItemEventArgs e)
        {
            var item        = e.Item;
            var pageManager = this.RootGroup.GetVirtualPageManager();

            if (!pageManager.IsItemDirty(item))
            {
                // First time we enter edit on this item.
                var itemProperties = this.ItemProperties;
                var count          = itemProperties.Count;

                var propertyNames = new string[count];
                var cachedValues  = new object[count];

                for (int i = 0; i < count; i++)
                {
                    var itemProperty = itemProperties[i];

                    propertyNames[i] = PropertyRouteParser.Parse(itemProperty);
                    cachedValues[i]  = ItemsSourceHelper.GetValueFromItemProperty(itemProperty, 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);
        }
コード例 #4
0
        internal virtual PropertyRouteSegment ToPropertyRouteSegment()
        {
            var route = PropertyRouteParser.Parse(this.Name);

            if ((route == null) || (route.Parent != null))
            {
                return(new PropertyRouteSegment(PropertyRouteSegmentType.Property, this.Name));
            }

            return(route.Current);
        }
コード例 #5
0
        internal static PropertyRoute Combine(PropertyRouteSegment segment, PropertyRoute ancestors)
        {
            if (ancestors == null)
            {
                return(new PropertyRoute(segment));
            }

            if (ancestors.Current.Type != PropertyRouteSegmentType.Other)
            {
                return(new PropertyRoute(segment, ancestors));
            }

            var path = PropertyRouteParser.Parse(new PropertyRoute(segment, new PropertyRoute(ancestors.Current)));

            Debug.Assert(!string.IsNullOrEmpty(path));

            return(new PropertyRoute(new PropertyRouteSegment(PropertyRouteSegmentType.Other, path), ancestors.Parent));
        }
コード例 #6
0
        private static PropertyRouteSegment ToSegment(DataGridItemPropertyBase itemProperty)
        {
            Debug.Assert(itemProperty != null);

            var route = PropertyRouteParser.Parse(itemProperty.Name);

            if (route == null)
            {
                throw new ArgumentException("Unexpected DataGridItemPropertyBase.Name property value.", "itemProperty");
            }

            if (route.Parent == null)
            {
                return(route.Current);
            }

            return(new PropertyRouteSegment(PropertyRouteSegmentType.Other, itemProperty.Name));
        }
コード例 #7
0
        private static void UpdateColumnsForeignKeyConfigurationsFromPropertyDescriptions(
            ObservableColumnCollection columns,
            PropertyDescriptionRouteDictionary propertyDescriptions,
            bool autoCreateForeignKeyConfigurations)
        {
            if ((columns == null) || (propertyDescriptions == null))
            {
                return;
            }

            foreach (var column in columns)
            {
                var targetColumn = column as Column;
                if (targetColumn == null)
                {
                    continue;
                }

                var key = PropertyRouteParser.Parse(targetColumn.FieldName);
                if (key == null)
                {
                    continue;
                }

                var propertyDescription = propertyDescriptions[key];
                if (propertyDescription == null)
                {
                    continue;
                }

                var foreignKeyDescription = propertyDescription.Current.ForeignKeyDescription;
                if (foreignKeyDescription == null)
                {
                    continue;
                }

                ForeignKeyConfiguration.SynchronizeForeignKeyConfigurationFromForeignKeyDescription(targetColumn, foreignKeyDescription, autoCreateForeignKeyConfigurations);
            }
        }
コード例 #8
0
        internal static PropertyRoute Parse(string path)
        {
            path = (path != null) ? path.Trim() : string.Empty;

            var length = path.Length;

            if (length <= 0)
            {
                return(null);
            }

            var builder = new PropertyRouteBuilder();
            var state   = ParserState.Start;
            var index   = 0;

            while (index < length)
            {
                var c = path[index];

                if (char.IsWhiteSpace(c))
                {
                    index++;
                }
                else
                {
                    switch (state)
                    {
                    case ParserState.Start:
                    {
                        switch (c)
                        {
                        case '.':
                            index++;
                            break;

                        default:
                            state = ParserState.Property;
                            break;
                        }
                    }
                    break;

                    case ParserState.Separator:
                    {
                        switch (c)
                        {
                        case '.':
                            index++;
                            break;

                        case '[':
                            break;

                        default:
                        {
                            PropertyRouteParser.AddOther(path, length, ref index, builder);
                            Debug.Assert(index >= length);
                        }
                        break;
                        }

                        state = ParserState.Property;
                    }
                    break;

                    case ParserState.Property:
                    {
                        switch (c)
                        {
                        case '[':
                        {
                            if (PropertyRouteParser.AddIndexer(path, length, ref index, builder))
                            {
                                state = ParserState.Separator;
                            }
                            else
                            {
                                PropertyRouteParser.AddOther(path, length, ref index, builder);
                                Debug.Assert(index >= length);
                            }
                        }
                        break;

                        default:
                        {
                            if (PropertyRouteParser.AddProperty(path, length, ref index, builder))
                            {
                                state = ParserState.Separator;
                            }
                            else
                            {
                                PropertyRouteParser.AddOther(path, length, ref index, builder);
                                Debug.Assert(index >= length);
                            }
                        }
                        break;
                        }
                    }
                    break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }

            if (builder.IsEmpty)
            {
                builder.PushDescendant(PropertyRouteSegment.Self);
            }

            return(builder.ToPropertyRoute());
        }
コード例 #9
0
 internal static string Parse(DataGridItemPropertyBase itemProperty)
 {
     return(PropertyRouteParser.Parse(PropertyRouteBuilder.ToPropertyRoute(DataGridItemPropertyRoute.Create(itemProperty))));
 }