internal ItemPropertyNameMap( DataGridItemPropertyCollection itemProperties )
    {
      if( itemProperties == null )
        throw new ArgumentNullException( "itemProperties" );

      m_dataGridItemPropertyCollection = new WeakReference( itemProperties );

      CollectionChangedEventManager.AddListener( itemProperties, this );
    }
    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 );
    }
    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;
    }
Пример #4
0
    private static Dictionary<string, FieldDescriptor> GetFieldsForDataGridCollectionViewBase(
      DataGridCollectionViewBase dataGridCollectionViewBase,
      DataGridItemPropertyCollection itemProperties )
    {
      int fieldCount = itemProperties.Count;

      Dictionary<string, FieldDescriptor> fieldDescriptors =
        new Dictionary<string, FieldDescriptor>( fieldCount );

      for( int i = 0; i < fieldCount; i++ )
      {
        DataGridItemPropertyBase itemProperty = itemProperties[ i ];
        fieldDescriptors[ itemProperty.Name ] = ItemsSourceHelper.CreateFieldFromDataGridItemProperty( itemProperty );
      }

      return fieldDescriptors;
    }
Пример #5
0
    public static void UpdateColumnsOnItemsPropertiesChanged( 
      DataGridControl dataGridControl, 
      ColumnCollection columns,
      bool autoCreateForeignKeyConfigurations,
      NotifyCollectionChangedEventArgs e,
      DataGridItemPropertyCollection itemProperties )
    {
      if( dataGridControl == null )
        return;

      switch( e.Action )
      {
        case NotifyCollectionChangedAction.Add:
          {
            foreach( DataGridItemPropertyBase itemProperty in e.NewItems )
            {
              string name = itemProperty.Name;

              if( columns[ name ] == null )
              {
                Column column = ItemsSourceHelper.CreateColumnFromItemsSourceField(
                  dataGridControl, dataGridControl.DefaultCellEditors,
                  ItemsSourceHelper.CreateFieldFromDataGridItemProperty( itemProperty ),
                  autoCreateForeignKeyConfigurations );

                if( column != null )
                {
                  columns.Add( column );
                  ItemsSourceHelper.ApplySettingsRepositoryToColumn( column );
                }
              }
            }
          }

          break;

        case NotifyCollectionChangedAction.Remove:
          {
            foreach( DataGridItemPropertyBase itemProperty in e.OldItems )
            {
              string name = itemProperty.Name;
              Column column = columns[ name ] as Column;

              if( ( column != null ) && ( column.IsAutoCreated ) )
              {
                columns.Remove( column );
              }
            }

            break;
          }

        case NotifyCollectionChangedAction.Replace:
          {
            foreach( DataGridItemPropertyBase itemProperty in e.OldItems )
            {
              string name = itemProperty.Name;
              Column column = columns[ name ] as Column;

              if( ( column != null ) && ( column.IsAutoCreated ) )
              {
                columns.Remove( column );
              }
            }

            foreach( DataGridItemPropertyBase itemProperty in e.NewItems )
            {
              string name = itemProperty.Name;

              if( columns[ name ] == null )
              {
                Column column = ItemsSourceHelper.CreateColumnFromItemsSourceField(
                  dataGridControl, dataGridControl.DefaultCellEditors,
                  ItemsSourceHelper.CreateFieldFromDataGridItemProperty( itemProperty ),
                  autoCreateForeignKeyConfigurations );

                if( column != null )
                {
                  columns.Add( column );
                  ItemsSourceHelper.ApplySettingsRepositoryToColumn( column );
                }
              }
            }

            break;
          }

        case NotifyCollectionChangedAction.Reset:
          {
            for( int i = columns.Count - 1; i >= 0; i-- )
            {
              Column dataColumn = columns[ i ] as Column;

              if( ( dataColumn != null ) && ( dataColumn.IsAutoCreated ) )
              {
                columns.Remove( dataColumn );
              }
            }

            foreach( DataGridItemPropertyBase itemProperty in itemProperties )
            {
              string name = itemProperty.Name;

              if( columns[ name ] == null )
              {
                Column column = ItemsSourceHelper.CreateColumnFromItemsSourceField(
                  dataGridControl, dataGridControl.DefaultCellEditors,
                  ItemsSourceHelper.CreateFieldFromDataGridItemProperty( itemProperty ),
                  autoCreateForeignKeyConfigurations );

                if( column != null )
                {
                  columns.Add( column );
                  ItemsSourceHelper.ApplySettingsRepositoryToColumn( column );
                }
              }
            }

            break;
          }

        //case NotifyCollectionChangedAction.Move:
        default:
          break;

      }
    }
    private void SetupDefaultItemProperties()
    {
      m_itemProperties = new DataGridItemPropertyCollection();
      m_itemProperties.ItemType = m_itemType;

      // Listen for ItemProperties changes to be able to refresh when AutoFilterValues changes
      m_itemProperties.CollectionChanged += this.ItemProperties_CollectionChanged;
      m_itemProperties.FilterCriterionChanged += this.ItemProperties_FilterCriterionChanged;

      // Calling GetDefaultItemProperties will also cache the result in m_defaultItemProperties
      // if able to detect properties
      List<DataGridItemPropertyBase> defaultItemProperties = this.GetDefaultItemProperties();

      if( this.AutoCreateItemProperties )
      {
        // Add new auto created item properties
        foreach( DataGridItemPropertyBase defaultProperty in defaultItemProperties )
        {
          this.AddValidItemProperty( defaultProperty );
        }
      }

      if( ( m_itemProperties.DefaultItemProperties == null ) && ( m_defaultItemProperties != null ) )
        m_itemProperties.DefaultItemProperties = new List<DataGridItemPropertyBase>( m_defaultItemProperties );

      //no need to cycle through the content of the ItemProperties collection to update them since
      //they originate from the default anyway.
    }
    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;
            }
          }
        }
      }
    }
    // 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 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;
      }
    }
 internal virtual void SetUnspecifiedPropertiesValues( DataGridItemPropertyCollection itemPropertyCollection )
 {
 }
        /// <summary>
        /// Finds property by name.
        /// </summary>
        /// <param name="name">Property name.</param>
        /// <param name="properties">Properties collection.</param>
        /// <returns>Property or null if property is not found.</returns>
        private DataGridItemPropertyBase _FindItemProperty(string name,
            DataGridItemPropertyCollection properties)
        {
            DataGridItemPropertyBase resultProp = null;
            foreach (DataGridItemPropertyBase prop in properties)
            {
                if (prop.Name == name)
                {
                    resultProp = prop;
                    break;
                }
            }

            return resultProp;
        }
 public static void RemoveListener( DataGridItemPropertyCollection source, IWeakEventListener listener )
 {
   CurrentManager.ProtectedRemoveListener( source, listener );
 }