Beispiel #1
0
 /// <summary>
 /// Sets up i18n resources
 /// </summary>
 internal void ConfigureResources()
 {
     if (Handler != null)
     {
         I18NFactory.AddResourceManager(ModuleName, ResourceManager);
     }
 }
        /// <summary>
        /// Callback that is triggered once the <see cref="OptionHandler"/> property changes.
        /// </summary>
        /// <param name="oldValue">The old value.</param>
        /// <param name="newValue">The new value.</param>
        protected virtual void OnOptionHandlerChanged(OptionHandler oldValue, OptionHandler newValue)
        {
            if (oldValue != null)
            {
                IModelView view = View;
                if (view is CopiedOptionHandler && view.Handler == oldValue)
                {
                    CopiedOptionHandler oldView = (CopiedOptionHandler)view;
                    if (newValue != null)
                    {
                        View = CreateView(newValue);
                    }
                    else
                    {
                        View = null;
                    }
                    oldView.Dispose();
                }
                else
                {
                    if (newValue != null)
                    {
                        View = CreateView(newValue);
                    }
                    else
                    {
                        View = null;
                    }
                }
            }
            else
            {
                if (newValue != null)
                {
                    View = CreateView(newValue);
                }
                else
                {
                    View = null;
                }
            }

            if (newValue != null)
            {
                if (I18NFactory != null)
                {
                    Title = I18NFactory.GetString(newValue.Name, newValue.Name);
                }
                else
                {
                    Title = newValue.Name;
                }
            }
            else
            {
                Title = string.Empty;
            }
        }
        public ListTypeConverter(IEnumerable domain, Type t, bool listValuesExclusive,
                                 I18NFactory i18NFactory, string i18nprefix, string context)
        {
            this.t  = t;
            i18nMap = new Dictionary <string, object>();

            this.listValuesExclusive = listValuesExclusive;
            this.i18NFactory         = i18NFactory;
            this.i18nPrefix          = i18nprefix;
            this.context             = context;

            TypeConverter coreConverter = TypeDescriptor.GetConverter(t);

            foreach (object o in domain)
            {
                if (coreConverter != null && coreConverter.CanConvertTo(typeof(string)))
                {
                    //we need this for a  human readable description
                    string interpretedValue;
                    if (i18NFactory != null && !string.IsNullOrEmpty(i18nprefix))
                    {
                        interpretedValue = PropertyModelView.GetLocalizedString(i18NFactory, context, i18nprefix + ".VALUE.", coreConverter.ConvertToString(o));
                    }
                    else
                    {
                        interpretedValue = coreConverter.ConvertToString(o);
                    }
                    i18nList.Add(interpretedValue);
                    i18nMap[interpretedValue] = o;
                }
                else
                {
                    i18nList.Add(o);
                }
            }
            //return new StandardValuesCollection(tmp);

            cachedStandardValues = new StandardValuesCollection(i18nList);
        }
Beispiel #4
0
        internal virtual TypeConverter CreateConverter(PropertyModelView.OptionItemPropertyDescriptor desc,
                                                       I18NFactory i18NFactory, string context)
        {
            OptionItem             item          = desc.Item;
            TypeConverterAttribute converterAttr =
                TypeDescriptor.GetProperties(item, false)["Value"].Attributes[typeof(TypeConverterAttribute)]
                as TypeConverterAttribute;

            TypeConverter coreConverter;

            if (desc is PropertyModelView.ListPropertyDescriptor && converterAttr.ConverterTypeName == "")
            {
                //special handling for the list converter
                coreConverter =
                    new I18NTypeConverter(((PropertyModelView.ListPropertyDescriptor)desc).GetStringRepresentation(),
                                          (bool)
                                          item.GetAttribute(
                                              CollectionOptionItem <object> .USE_ONLY_DOMAIN_ATTRIBUTE));
            }
            else if (item is ICollectionSupport && converterAttr.ConverterTypeName == "")
            {
                //special handling for the list converter
                coreConverter = new ListTypeConverter(((ICollectionSupport)item).Domain,
                                                      ((ICollectionSupport)item).EntryType,
                                                      (bool)
                                                      item.GetAttribute(
                                                          CollectionOptionItem <object> .USE_ONLY_DOMAIN_ATTRIBUTE),
                                                      i18NFactory, desc.I18nKey, context);
            }
            else if (converterAttr.ConverterTypeName != "")
            {
                //attribute set, get the converter that is set by the attribute
                coreConverter = TypeDescriptor.GetProperties(item, false)["Value"].Converter;
            }
            else
            {
                //no attribute, delegate to base
                coreConverter = TypeDescriptor.GetConverter(item.Type);
            }

            //TypeConverter coreConverter = converterAttr.ConverterTypeName != "" ? itemConverter : base.Converter;
            //todo: make this dependent on item attribute
            bool   supportNull             = (bool)item.GetAttribute(OptionItem.SUPPORT_NULL_VALUE_ATTRIBUTE);
            bool   supportUndefined        = (bool)item.GetAttribute(OptionItem.SUPPORT_UNDEFINED_VALUE_ATTRIBUTE);
            string nullValueRepresentation = item.GetAttribute(OptionItem.NULL_VALUE_STRING_ATTRIBUTE) as string;

            if (i18NFactory != null)
            {
                nullValueRepresentation = PropertyModelView.GetLocalizedString(
                    i18NFactory, context, desc.I18nKey + ".VALUE.", nullValueRepresentation);
            }
            //test for overrides
            object converterOverride = item.GetAttribute(OptionItem.CUSTOM_CONVERTER_ATTRIBUTE);

            if (converterOverride != null)
            {
                if (converterOverride is TypeConverter)
                {
                    return((TypeConverter)converterOverride);
                }
                if (converterOverride is Type)
                {
                    try {
                        TypeConverter o = System.Activator.CreateInstance((Type)converterOverride) as TypeConverter;
                        if (o != null)
                        {
                            coreConverter = o;
                        }
                    } catch {
                        Trace.WriteLine("Cannot create converter instance");
                    }
                }
                else if (converterOverride is string)
                {
                    try {
                        TypeConverter o =
                            System.Activator.CreateInstance(Type.GetType((string)converterOverride)) as TypeConverter;
                        if (o != null)
                        {
                            coreConverter = o;
                        }
                    } catch {
                        Trace.WriteLine("Cannot create converter instance");
                    }
                }
                else
                {
                    Trace.WriteLine("Invalid type for converter attribute");
                }
            }
            if (supportNull || supportUndefined)
            {
                //custom conversions needed...
                if (coreConverter is ExpandableObjectConverter ||
                    coreConverter is FontConverter ||
                    coreConverter is PointConverter
                    )
                {
                    return(new ExpandableNullableTypeConverter(coreConverter,
                                                               supportNull,
                                                               supportUndefined,
                                                               nullValueRepresentation == null
                                                       ? ""
                                                       : nullValueRepresentation));
                }
                else
                {
                    return(new NullableTypeConverter(coreConverter,
                                                     supportNull,
                                                     supportUndefined,
                                                     nullValueRepresentation == null ? "" : nullValueRepresentation));
                }
            }
            return(coreConverter);
        }
Beispiel #5
0
 static OptionHandler()
 {
     fallBackI18NFactory = new InternalFallBackI18NFactory();
 }