[JEDI.NET-commits] main/run Jedi.Collections.pas,1.4,1.5
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2004-08-26 09:46:13
|
Update of /cvsroot/jedidotnet/main/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27169/main/run Modified Files: Jedi.Collections.pas Log Message: * Override the typeconverter for the 'new' item so it suppresses the child properties (which are useless in that scenario) * Minor corrections in one of the overloaded methods to create the 'new' item. Index: Jedi.Collections.pas =================================================================== RCS file: /cvsroot/jedidotnet/main/run/Jedi.Collections.pas,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Jedi.Collections.pas 25 Aug 2004 18:56:12 -0000 1.4 --- Jedi.Collections.pas 26 Aug 2004 09:45:46 -0000 1.5 *************** *** 210,213 **** --- 210,214 ---- NewItemPropertyDescriptor = class (SimplePropertyDescriptor) strict private + FOrgConverter: TypeConverter; FPropertyId: System.Object; strict protected *************** *** 218,228 **** function GetValue(component: System.Object): System.Object; override; procedure SetValue(component, value: System.Object); override; end; constructor NewItemPropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; propertyId: System.Object); begin ! inherited Create(componentType, name, propertyType, attributes); FPropertyId := propertyId; end; --- 219,364 ---- function GetValue(component: System.Object): System.Object; override; procedure SetValue(component, value: System.Object); override; + property OrgConverter: TypeConverter read FOrgConverter; end; + {$REGION 'NewPropertyTypeConverter'} + type + NewPropertyTypeConverter = class (TypeConverter) + strict private + FRealConverter: TypeConverter; + strict protected + function RealConverter(context: ITypeDescriptorContext): TypeConverter; + public + function CanConvertFrom(context: ITypeDescriptorContext; sourceType: System.Type): Boolean; override; + function CanConvertTo(context: ITypeDescriptorContext; destinationType: System.Type): Boolean; override; + function ConvertFrom(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object): System.Object; override; + function ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; value: System.Object; destinationType: System.Type): System.Object; override; + function CreateInstance(context: ITypeDescriptorContext; propertyValues: IDictionary): System.Object; override; + function GetCreateInstanceSupported(context: ITypeDescriptorContext): Boolean; override; + function GetProperties(context: ITypeDescriptorContext; value: System.Object; attributes: AttributeArray): PropertyDescriptorCollection; override; + function GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; override; + function GetStandardValues(context: ITypeDescriptorContext): TypeConverter.StandardValuesCollection; override; + function GetStandardValuesExclusive(context: ITypeDescriptorContext): Boolean; override; + function GetStandardValuesSupported(context: ITypeDescriptorContext): Boolean; override; + function IsValid(context: ITypeDescriptorContext; value: System.Object): Boolean; override; + end; + + function NewPropertyTypeConverter.RealConverter(context: ITypeDescriptorContext): TypeConverter; + begin + if not Assigned(FRealConverter) and Assigned(context) and + Assigned(NewItemPropertyDescriptor(context.PropertyDescriptor)) then + FRealConverter := NewItemPropertyDescriptor(context.PropertyDescriptor).OrgConverter; + Result := FRealConverter; + end; + + function NewPropertyTypeConverter.CanConvertFrom(context: ITypeDescriptorContext; sourceType: System.Type): Boolean; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.CanConvertFrom(context, sourceType) + else + Result := inherited CanConvertFrom(context, sourceType); + end; + + function NewPropertyTypeConverter.CanConvertTo(context: ITypeDescriptorContext; destinationType: System.Type): Boolean; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.CanConvertTo(context, destinationType) + else + Result := inherited CanConvertTo(context, destinationType); + end; + + function NewPropertyTypeConverter.ConvertFrom(context: ITypeDescriptorContext; culture: CultureInfo; + value: System.Object): System.Object; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.ConvertFrom(context, culture, value) + else + Result := inherited ConvertFrom(context, culture, value); + end; + + function NewPropertyTypeConverter.ConvertTo(context: ITypeDescriptorContext; culture: CultureInfo; + value: System.Object; destinationType: System.Type): System.Object; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.ConvertTo(context, culture, value, destinationType) + else + Result := inherited ConvertTo(context, culture, value, destinationType); + end; + + function NewPropertyTypeConverter.CreateInstance(context: ITypeDescriptorContext; + propertyValues: IDictionary): System.Object; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.CreateInstance(context, propertyValues) + else + Result := inherited CreateInstance(context, propertyValues); + end; + + function NewPropertyTypeConverter.GetCreateInstanceSupported(context: ITypeDescriptorContext): Boolean; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.GetCreateInstanceSupported(context) + else + Result := inherited GetCreateInstanceSupported(context); + end; + + function NewPropertyTypeConverter.GetProperties(context: ITypeDescriptorContext; value: System.Object; + attributes: AttributeArray): PropertyDescriptorCollection; + begin + Result := PropertyDescriptorCollection.Empty; + end; + + function NewPropertyTypeConverter.GetPropertiesSupported(context: ITypeDescriptorContext): Boolean; + begin + Result := False; + end; + + function NewPropertyTypeConverter.GetStandardValues( + context: ITypeDescriptorContext): TypeConverter.StandardValuesCollection; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.GetStandardValues(context) + else + Result := inherited GetStandardValues(context); + end; + + function NewPropertyTypeConverter.GetStandardValuesExclusive(context: ITypeDescriptorContext): Boolean; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.GetStandardValuesExclusive(context) + else + Result := inherited GetStandardValuesExclusive(context); + end; + + function NewPropertyTypeConverter.GetStandardValuesSupported(context: ITypeDescriptorContext): Boolean; + begin + if Assigned(RealConverter(context)) then + Result := FRealConverter.GetStandardValuesSupported(context) + else + Result := inherited GetStandardValuesSupported(context); + end; + + function NewPropertyTypeConverter.IsValid(context: ITypeDescriptorContext; value: System.Object): Boolean; + begin + if Assigned(RealConverter(context)) then + Result := FrealConverter.IsValid(context, value) + else + Result := inherited IsValid(context, value); + end; + {$ENDREGION} + constructor NewItemPropertyDescriptor.Create(componentType: System.Type; name: string; propertyType: System.Type; attributes: AttributeArray; propertyId: System.Object); + var + orgConvAttr: TypeConverterAttribute; begin ! inherited Create(componentType, name, propertyType, AttributeUtils.CombineAttributes( ! attributes, Jedi.System.AttributeArray.Create(TypeConverterAttribute.Create(TypeOf(NewPropertyTypeConverter))))); FPropertyId := propertyId; + orgConvAttr := TypeConverterAttribute(AttributeUtils.GetAttribute(attributes, TypeOf(TypeConverterAttribute))); + if Assigned(orgConvAttr) then + FOrgConverter := TypeConverter(Activator.CreateInstance(&Type.GetType(orgConvAttr.ConverterTypeName), True)) + else + FOrgConverter := TypeDescriptor.GetConverter(propertyType); end; *************** *** 917,922 **** class function InlineCollectionUtils.CreateNewItemProperty(baseDescriptor: PropertyDescriptor; name, description: string; propertyId: System.Object): PropertyDescriptor; - var - attrs: ArrayList; begin if not Assigned(baseDescriptor) then --- 1053,1056 ---- *************** *** 925,938 **** name := baseDescriptor.Name; ! attrs := ArrayList.Create(baseDescriptor.Attributes); ! Result := NewItemPropertyDescriptor.Create(baseDescriptor.ComponentType, name, baseDescriptor.PropertyType, ! AttributeArray(attrs.ToArray(TypeOf(Attribute))), propertyId); end; class function InlineCollectionUtils.CreateNewItemProperty(info: PropertyInfo; name, description: string; propertyId: System.Object): PropertyDescriptor; - var - mattrs: array of System.Object; - attrs: AttributeArray; begin if not Assigned(info) then --- 1059,1069 ---- name := baseDescriptor.Name; ! Result := CreateNewItemProperty(baseDescriptor.ComponentType, baseDescriptor.PropertyType, ! AttributeArray(ArrayList.Create(baseDescriptor.Attributes).ToArray(TypeOf(Attribute))), name, description, ! propertyId); end; class function InlineCollectionUtils.CreateNewItemProperty(info: PropertyInfo; name, description: string; propertyId: System.Object): PropertyDescriptor; begin if not Assigned(info) then *************** *** 940,948 **** if not Assigned(name) or (name = '') then name := info.Name; ! mattrs := info.GetCustomAttributes(True); ! attrs := new(AttributeArray, Length(mattrs)); ! System.Array.Copy(mattrs, attrs, Length(mattrs)); ! Result := InlineCollectionUtils.CreateNewItemProperty(info.DeclaringType, info.PropertyType, attrs, name, description, ! propertyId); end; --- 1071,1076 ---- if not Assigned(name) or (name = '') then name := info.Name; ! Result := CreateNewItemProperty(info.DeclaringType, info.PropertyType, ! AttributeArray(&Array(info.GetCustomAttributes(True))), name, description, propertyId); end; |