示例#1
0
        /// <inheritdoc/>
        public virtual void AddItems(IOptionBuilderContext context, Type subjectType, object subject)
        {
            DefaultBrushOptionBuilder brushOptionBuilder = new DefaultBrushOptionBuilder();

            brushOptionBuilder.AllowNullValue = AllowNullValue;
            brushOptionBuilder.AddItems(context, typeof(Brush), null);

            FloatOptionItem widthItem      = new FloatOptionItem(DefaultPenPropertyMapBuilder.Width);
            bool            widthItemAdded = context.BindItem(widthItem, DefaultPenPropertyMapBuilder.Width);
            GenericOptionItem <DashStyle> dashStyleItem =
                new GenericOptionItem <DashStyle>(DefaultPenPropertyMapBuilder.DashStyle, OptionItem.VALUE_UNDEFINED);

            dashStyleItem.SetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE, true);
            dashStyleItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false);
//      dashStyleItem.SetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR, typeof(PenDashStyleUITypeEditor));
            EnumUITypeEditor <DashStyle> editor = new EnumUITypeEditor <DashStyle>();

            editor.Renderer = new DashStyleItemRenderer();

            dashStyleItem.SetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR, editor);
//      dashStyleItem.SetAttribute(OptionItem.CUSTOM_CELLRENDERER, typeof(DashStyleItemRenderer));
            bool dashStyleItemAdded = context.BindItem(dashStyleItem, DefaultPenPropertyMapBuilder.DashStyle);

            IOptionGroup parent = context.Lookup <IOptionGroup>();

            if (parent != null)
            {
                IOptionItem       fillTypeItem = parent[DefaultBrushPropertyMapBuilder.FillType];
                ConstraintManager cm           = parent.Lookup <ConstraintManager>();
                if (cm != null && fillTypeItem != null)
                {
                    ICondition cond = ConstraintManager.LogicalCondition.Not(cm.CreateValueEqualsCondition(fillTypeItem, null));
                    if (widthItemAdded)
                    {
                        cm.SetEnabledOnCondition(cond, widthItem);
                    }
                    if (dashStyleItemAdded)
                    {
                        cm.SetEnabledOnCondition(cond, dashStyleItem);
                    }
                }
            }
        }
示例#2
0
        /// <inheritdoc/>
        public virtual void AddItems(IOptionBuilderContext context, Type subjectType, object subject)
        {
//      CollectionOptionItem<string> fillTypeItem =
//        new CollectionOptionItem<string>(DefaultBrushPropertyMapBuilder.FillType,
//        new string[] {
//                       DefaultBrushPropertyMapBuilder.SolidBrushFillType,
//      DefaultBrushPropertyMapBuilder.HatchBrushFillType,
//      DefaultBrushPropertyMapBuilder.LinearGradientBrushFillType,
//      DefaultBrushPropertyMapBuilder.TextureBrushFillType
//    });
            GenericOptionItem <BrushTypes> fillTypeItem =
                new GenericOptionItem <BrushTypes>(DefaultBrushPropertyMapBuilder.FillType);

            fillTypeItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, AllowNullValue);
//      fillTypeItem.SetAttribute(OptionItem.NULL_VALUE_OBJECT, BrushTypes.Nothing);
            fillTypeItem.SetAttribute(OptionItem.NULL_VALUE_STRING_ATTRIBUTE, "Nothing");
            bool fillTypeAdded =
                context.BindItem(fillTypeItem,
                                 DefaultBrushPropertyMapBuilder.FillType
                                 );

            ColorOptionItem foreColorItem  = new ColorOptionItem(DefaultBrushPropertyMapBuilder.ForegroundColor);
            bool            foreColorAdded = context.BindItem(foreColorItem, DefaultBrushPropertyMapBuilder.ForegroundColor);

            ColorOptionItem backColorOptionItem = new ColorOptionItem(DefaultBrushPropertyMapBuilder.BackgroundColor);
            bool            backColorAdded      = context.BindItem(backColorOptionItem, DefaultBrushPropertyMapBuilder.BackgroundColor);

            GenericOptionItem <HatchStyle> hatchStyleItem =
                new GenericOptionItem <HatchStyle>(DefaultBrushPropertyMapBuilder.HatchStyle, OptionItem.VALUE_UNDEFINED);

            hatchStyleItem.SetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE, true);
            hatchStyleItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false);


            bool hatchItemAdded =
                context.BindItem(hatchStyleItem, DefaultBrushPropertyMapBuilder.HatchStyle);

            if (hatchItemAdded)
            {
                EnumUITypeEditor <HatchStyle> hatchEditor = new EnumUITypeEditor <HatchStyle>();
                hatchEditor.Renderer = new HatchStyleItemRenderer();
                hatchStyleItem.SetAttribute(OptionItem.CUSTOM_TABLEITEM_EDITOR, hatchEditor);
            }

            FloatOptionItem rotationItem   = new FloatOptionItem(DefaultBrushPropertyMapBuilder.Rotation);
            bool            floatItemAdded = context.BindItem(rotationItem, DefaultBrushPropertyMapBuilder.Rotation);

            GenericOptionItem <Image> imageItem =
                new GenericOptionItem <Image>(DefaultBrushPropertyMapBuilder.Image, OptionItem.VALUE_UNDEFINED);

            imageItem.SetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE, true);
            imageItem.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false);
            bool imageItemAdded = context.BindItem(imageItem, DefaultBrushPropertyMapBuilder.Image);

            if (fillTypeAdded)
            {
                ConstraintManager cm = context.Lookup <ConstraintManager>();
                if (cm != null)
                {
                    if (foreColorAdded)
                    {
                        ICondition cond = cm.CreateValueIsOneOfCondition(fillTypeItem, BrushTypes.SolidBrush, BrushTypes.HatchBrush, BrushTypes.LinearGradientBrush);
                        cm.SetEnabledOnCondition(cond, foreColorItem);
                    }
                    if (backColorAdded)
                    {
                        ICondition cond = cm.CreateValueIsOneOfCondition(fillTypeItem, BrushTypes.HatchBrush, BrushTypes.LinearGradientBrush);
                        cm.SetEnabledOnCondition(cond, backColorOptionItem);
                    }
                    if (hatchItemAdded)
                    {
                        cm.SetEnabledOnValueEquals(fillTypeItem, BrushTypes.HatchBrush, hatchStyleItem);
                    }
                    if (imageItemAdded)
                    {
                        cm.SetEnabledOnValueEquals(fillTypeItem, BrushTypes.TextureBrush, imageItem);
                    }
                    if (floatItemAdded)
                    {
                        cm.SetEnabledOnValueEquals(fillTypeItem, BrushTypes.LinearGradientBrush, rotationItem);
                    }
                }
            }
        }
        /// <summary>
        /// Factory method that creates the option item using the provided parameters.
        /// </summary>
        protected virtual IOptionItem CreateItem(IOptionBuilderContext context, PropertyInfo propertyInfo, Type type,
                                                 string description, object value)
        {
            IOptionItem item = null;

            if (type.IsEnum)
            {
                Type genericType = typeof(GenericOptionItem <>);
                Type newType     = genericType.MakeGenericType(type);
                item = newType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { description }) as IOptionItem;
            }
            else if (type == typeof(Color))
            {
                item = new ColorOptionItem(description);
            }
            else if (type.IsGenericType && type.GetGenericTypeDefinition().IsAssignableFrom((typeof(ICollection <>))))
            {
                Type[] types = type.GetGenericArguments();
                if (types.Length == 1)
                {
                    Type collectionItemType       = types[0];
                    Type collectionBaseType       = typeof(ICollection <>);
                    Type collectionType           = collectionBaseType.MakeGenericType(collectionItemType);
                    Type collectionOptionItemType = typeof(CollectionOptionItem <>);
                    item = collectionOptionItemType.MakeGenericType(collectionItemType).GetConstructor(
                        new Type[] { typeof(string), collectionType }).Invoke(new object[] { description, value }) as
                           IOptionItem;
                }
            }

            if (item == null)
            {
                if (type == typeof(double))
                {
                    item = new DoubleOptionItem(description);
                }
                else if (type == typeof(int))
                {
                    item = new IntOptionItem(description);
                }
                else if (type == typeof(float))
                {
                    item = new FloatOptionItem(description);
                }
                else if (type == typeof(bool))
                {
                    item = new BoolOptionItem(description);
                }
                else if (type == typeof(string))
                {
                    item = new StringOptionItem(description);
                }
                else
                {
                    Type genericType = typeof(GenericOptionItem <>);
                    Type newType     = genericType.MakeGenericType(type);
                    item =
                        newType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { description }) as IOptionItem;
                }
            }
            if (item != null)
            {
                TypeConverterAttribute converter = GetAttribute <TypeConverterAttribute>(propertyInfo);
                if (converter != null && !converter.IsDefaultAttribute())
                {
                    try {
                        Type typeConverter = Type.GetType(converter.ConverterTypeName);
                        if (typeConverter != null)
                        {
                            item.SetAttribute(OptionItem.CUSTOM_CONVERTER_ATTRIBUTE, typeConverter);
                        }
                    } catch (Exception e) {
                        Trace.WriteLine("Could not load custom type converter " + e.Message);
                    }
                }
                //by default, value types are not nullable
                if (type.IsValueType)
                {
                    item.SetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE, false);
                }
            }


            return(item);
        }