private static void UpdateColumnsForeignKeyConfigurationsFromFieldDescriptors(
            Dictionary <string, ColumnBase> columns,
            Dictionary <string, ItemsSourceHelper.FieldDescriptor> fieldDescriptors,
            bool autoCreateForeignKeyConfigurations)
        {
            if (columns == null)
            {
                return;
            }

            if (fieldDescriptors == null)
            {
                return;
            }

            foreach (ItemsSourceHelper.FieldDescriptor fieldDescriptor in fieldDescriptors.Values)
            {
                DataGridForeignKeyDescription description = fieldDescriptor.ForeignKeyDescription;

                if (description == null)
                {
                    continue;
                }

                ColumnBase column;
                columns.TryGetValue(fieldDescriptor.Name, out column);

                ForeignKeyConfiguration.SynchronizeForeignKeyConfigurationFromForeignKeyDescription(
                    column as Column,
                    description,
                    autoCreateForeignKeyConfigurations);
            }
        }
        // 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 void SetForeignKeyDescription(DataGridForeignKeyDescription description)
 {
     if (m_foreignKeyDescription != description)
     {
         m_foreignKeyDescription = description;
         this.OnPropertyChanged(DataGridItemPropertyBase.ForeignKeyDescriptionPropertyName);
     }
 }
 internal void SetForeignKeyDescription(DataGridForeignKeyDescription description)
 {
     if (m_foreignKeyDescription != description)
     {
         m_foreignKeyDescription = description;
         this.OnPropertyChanged("ForeignKeyDescription");
     }
 }
        private IEnumerable m_itemsSource; // = null;

        private static void OnItemsSourceChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DataGridForeignKeyDescription foreignKeyDescription = sender as DataGridForeignKeyDescription;

            if (foreignKeyDescription != null)
            {
                foreignKeyDescription.m_itemsSource = e.NewValue as IEnumerable;
            }
        }
            public SortInfo(DataGridForeignKeyDescription foreignKeyDescription, ListSortDirection sortDirection, IComparer sortComparer)
            {
                if (sortComparer == null)
                {
                    throw new ArgumentNullException("sortComparer");
                }

                this.ForeignKeyDescription = foreignKeyDescription;
                this.SortDirection         = sortDirection;
                this.SortComparer          = sortComparer;
            }
        internal static void SynchronizeForeignKeyConfigurationFromForeignKeyDescription(
            Column column,
            DataGridForeignKeyDescription description,
            bool autoCreateForeignKeyConfigurations)
        {
            if ((description == null) || (column == null))
            {
                return;
            }

            var configuration = column.ForeignKeyConfiguration;

            if (configuration == null)
            {
                if (!autoCreateForeignKeyConfigurations)
                {
                    return;
                }

                configuration = new ForeignKeyConfiguration();
                configuration.IsAutoCreated    = true;
                column.ForeignKeyConfiguration = configuration;
            }

            // ValuePath will be affected to the FieldName when the configuration is auto-created to be able to modify local source using foreign key value
            if (configuration.IsAutoCreated)
            {
                if (string.IsNullOrEmpty(configuration.ValuePath))
                {
                    configuration.ValuePath = description.ValuePath;
                }

                if (string.IsNullOrEmpty(configuration.DisplayMemberPath))
                {
                    configuration.DisplayMemberPath = description.DisplayMemberPath;
                }
            }

            // Affect the ItemsSource on the configuration if it is not already set
            if ((configuration.ItemsSource == null) && (description.ItemsSource != null))
            {
                configuration.ItemsSource = description.ItemsSource;
            }

            // Set the Converter if it was not locally set
            if (configuration.ForeignKeyConverter == null)
            {
                configuration.ForeignKeyConverter = description.ForeignKeyConverter;
            }
        }
Esempio n. 8
0
        public override object GetValueFromKey(object key, DataGridForeignKeyDescription description)
        {
            var itemsSource = description.ItemsSource;

            if (itemsSource == null)
            {
                return(key);
            }

            if ((itemsSource is DataView) || (itemsSource is DataTable))
            {
                return(new DataTableForeignKeyConverter().GetValueFromKey(key, description));
            }

            return(this.GetValueFromKeyCore(key, itemsSource, description.ValuePath, description.DisplayMemberPath));
        }
        internal DataGridItemProperty(
            string name,
            PropertyDescriptor propertyDescriptor,
            string title,
            string valueXPath,
            string valuePath,
            Type dataType,
            bool isAutoCreated,
            Nullable <bool> isReadOnly,
            Nullable <bool> overrideReadOnlyForInsertion,
            Nullable <bool> isDisplayable,
            Nullable <bool> isASubRelationship,
            DataGridForeignKeyDescription foreignKeyDescription)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("name cannot be null or empty.", "name");
            }

            if ((string.IsNullOrEmpty(valuePath)) && (string.IsNullOrEmpty(valueXPath)) && (propertyDescriptor == null))
            {
                throw new ArgumentException("The valuePath, valueXPath, or propertyDescriptor must be provided.");
            }

            this.Initialize(
                name,
                propertyDescriptor,
                title,
                valueXPath,
                valuePath,
                dataType,
                isAutoCreated,
                isReadOnly,
                overrideReadOnlyForInsertion,
                isDisplayable,
                isASubRelationship,
                foreignKeyDescription);
        }
Esempio n. 10
0
      public FieldDescriptor(
        string name,
        string displayName,
        Type dataType,
        PropertyDescriptor propertyDescriptor,
        string bindingXPath,
        string bindingPath,
        bool readOnly,
        bool overrideReadOnlyForInsertion,
        bool supportDBNull,
        bool browsable,
        bool isASubRelationship,
        bool isDataGridUnboundItemProperty,
        DataGridForeignKeyDescription foreignKeyDescription )
      {
        if( name == null )
          throw new ArgumentNullException( "name" );

        if( displayName == null )
          throw new ArgumentNullException( "displayName" );

        if( dataType == null )
          throw new ArgumentNullException( "dataType" );

        this.ReadOnly = readOnly;
        this.OverrideReadOnlyForInsertion = overrideReadOnlyForInsertion;
        m_name = name;
        m_displayName = displayName;
        m_dataType = dataType;
        m_propertyDescriptor = propertyDescriptor;
        m_bindingPath = bindingPath;
        m_bindingXPath = bindingXPath;
        this.SupportDBNull = supportDBNull;
        this.Browsable = browsable;
        this.IsASubRelationship = isASubRelationship;
        this.IsDataGridUnboundItemProperty = isDataGridUnboundItemProperty;
        this.ForeignKeyDescription = foreignKeyDescription;
      }
Esempio n. 11
0
    internal static DataGridForeignKeyDescription GetDataGridForeignKeyDescriptionForEnum( Type enumType )
    {
      DataGridForeignKeyDescription foreignKeyDescription = null;

      if( ( enumType != null ) && ( enumType.IsEnum ) )
      {
        foreignKeyDescription = new DataGridForeignKeyDescription();

        // Using "." as default value path will revert to Self when used as 
        // SelectedValuePath when bound to a DataGridForeignKeyDictionary or
        // ComboBox (default editor)
        foreignKeyDescription.ValuePath = ".";
        foreignKeyDescription.ItemsSource = Enum.GetValues( enumType );
        foreignKeyDescription.IsAutoCreated = true;
      }

      return foreignKeyDescription;
    }
    private void Initialize(
      string name,
      PropertyDescriptor propertyDescriptor,
      string title,
      string valueXPath,
      string valuePath,
      Type dataType,
      bool isAutoCreated,
      Nullable<bool> isReadOnly,
      Nullable<bool> overrideReadOnlyForInsertion,
      Nullable<bool> isASubRelationship,
      DataGridForeignKeyDescription foreignKeyDescription )
    {
      this.IsAutoCreated = isAutoCreated;
      m_valueXPath = valueXPath;
      m_valuePath = valuePath;
      m_propertyDescriptor = propertyDescriptor;

      if( m_propertyDescriptor == null )
      {
        if( ( string.IsNullOrEmpty( m_valueXPath ) ) && ( m_valuePath == "." ) )
          m_propertyDescriptor = new SelfPropertyDescriptor( dataType );
      }

      if( m_propertyDescriptor != null )
      {
        this.Browsable = m_propertyDescriptor.IsBrowsable;

        if( m_propertyDescriptor.IsReadOnly )
          isReadOnly = m_propertyDescriptor.IsReadOnly;
      }

      if( title == null )
      {
        if( m_propertyDescriptor != null )
        {
          title = m_propertyDescriptor.DisplayName;
        }
      }

      if( isReadOnly == null )
      {
        if( m_propertyDescriptor != null )
        {
          isReadOnly = m_propertyDescriptor.IsReadOnly;
        }
      }

      if( dataType == null )
      {
        if( m_propertyDescriptor != null )
        {
          dataType = m_propertyDescriptor.PropertyType;
        }
      }

      this.ForeignKeyDescription = foreignKeyDescription;

      base.Initialize( name, title, dataType, isReadOnly, overrideReadOnlyForInsertion, isASubRelationship );
    }
    internal DataGridItemProperty(
      string name,
      PropertyDescriptor propertyDescriptor,
      string title,
      string valueXPath,
      string valuePath,
      Type dataType,
      bool isAutoCreated,
      Nullable<bool> isReadOnly,
      Nullable<bool> overrideReadOnlyForInsertion,
      Nullable<bool> isASubRelationship,
      DataGridForeignKeyDescription foreignKeyDescription )
    {
      if( string.IsNullOrEmpty( name ) )
        throw new ArgumentException( "name cannot be null or empty.", "name" );

      if( ( string.IsNullOrEmpty( valuePath ) ) && ( string.IsNullOrEmpty( valueXPath ) ) && ( propertyDescriptor == null ) )
        throw new ArgumentException( "The valuePath, valueXPath, or propertyDescriptor must be provided." );

      this.Initialize(
        name,
        propertyDescriptor,
        title,
        valueXPath,
        valuePath,
        dataType,
        isAutoCreated,
        isReadOnly,
        overrideReadOnlyForInsertion,
        isASubRelationship,
        foreignKeyDescription );
    }
Esempio n. 14
0
        private void Initialize(
            string name,
            PropertyDescriptor propertyDescriptor,
            string title,
            string valueXPath,
            string valuePath,
            Type dataType,
            bool isAutoCreated,
            Nullable <bool> isReadOnly,
            Nullable <bool> overrideReadOnlyForInsertion,
            Nullable <bool> isASubRelationship,
            DataGridForeignKeyDescription foreignKeyDescription)
        {
            this.IsAutoCreated   = isAutoCreated;
            m_valueXPath         = valueXPath;
            m_valuePath          = valuePath;
            m_propertyDescriptor = propertyDescriptor;

            if (m_propertyDescriptor == null)
            {
                if ((string.IsNullOrEmpty(m_valueXPath)) && (m_valuePath == "."))
                {
                    m_propertyDescriptor = new SelfPropertyDescriptor(dataType);
                }
            }

            if (m_propertyDescriptor != null)
            {
                this.Browsable = m_propertyDescriptor.IsBrowsable;

                if (m_propertyDescriptor.IsReadOnly)
                {
                    isReadOnly = m_propertyDescriptor.IsReadOnly;
                }
            }

            if (title == null)
            {
                if (m_propertyDescriptor != null)
                {
                    title = m_propertyDescriptor.DisplayName;
                }
            }

            if (isReadOnly == null)
            {
                if (m_propertyDescriptor != null)
                {
                    isReadOnly = m_propertyDescriptor.IsReadOnly;
                }
            }

            if (dataType == null)
            {
                if (m_propertyDescriptor != null)
                {
                    dataType = m_propertyDescriptor.PropertyType;
                }
            }

            this.ForeignKeyDescription = foreignKeyDescription;

            base.Initialize(name, title, dataType, isReadOnly, overrideReadOnlyForInsertion, isASubRelationship);
        }
    internal static void SynchronizeForeignKeyConfigurationFromForeignKeyDescription(
      Column column,
      DataGridForeignKeyDescription description,
      bool autoCreateForeignKeyConfigurations )
    {
      if( ( description == null ) || ( column == null ) )
        return;

      ForeignKeyConfiguration configuration = column.ForeignKeyConfiguration;

      if( configuration == null )
      {
        if( !autoCreateForeignKeyConfigurations )
          return;

        configuration = new ForeignKeyConfiguration();
        configuration.IsAutoCreated = true;
        column.ForeignKeyConfiguration = configuration;
      }

      // ValuePath will be affected to the FieldName when the 
      // configuration is auto-created to be able to modify 
      // local source using foreign key value
      if( configuration.IsAutoCreated )
      {
        if( string.IsNullOrEmpty( configuration.ValuePath ) )
        {
          configuration.ValuePath = description.ValuePath;
        }
      }

      // Affect the ItemsSource on the configuration if it is not
      // already set
      if( ( configuration.ItemsSource == null )
        && ( description.ItemsSource != null ) )
      {
        configuration.ItemsSource = description.ItemsSource;
      }

      // Set the Converter if it was not locally set
      if( configuration.ForeignKeyConverter == null )
      {
        configuration.ForeignKeyConverter = description.ForeignKeyConverter;
      }
    }
 internal void SetForeignKeyDescription( DataGridForeignKeyDescription description )
 {
   if( m_foreignKeyDescription != description )
   {
     m_foreignKeyDescription = description;
     this.OnPropertyChanged( "ForeignKeyDescription" );
   }
 }
Esempio n. 17
0
 public virtual object GetValueFromKey(object key, DataGridForeignKeyDescription description)
 {
     return(key);
 }
 public override object GetValueFromKey(object key, DataGridForeignKeyDescription description)
 {
     return(this.GetValueFromKeyCore(key, description.ItemsSource, description.ValuePath, description.DisplayMemberPath, false));
 }