Inheritance: System.Web.UI.WebControls.TextBox, IEditorPartField
Beispiel #1
0
        internal static Control CreateEditorControl(PropertyDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            var    propertyType = descriptor.PropertyType;
            object editor       = null;

            try
            {
                editor = descriptor.GetEditor(typeof(IEditorPartField));
            }
            catch (Exception e)
            {
                Logger.WriteException(e);
            }

            var propName = descriptor.Name;

            if (editor != null)
            {
                var partField = editor as IEditorPartField;
                if (partField != null)
                {
                    partField.Options = GetEditorOptionsAttribute(descriptor.Attributes);
                    partField.TitleContainerCssClass = "sn-iu-label";
                    partField.TitleCssClass          = "sn-iu-title";
                    partField.DescriptionCssClass    = "sn-iu-desc";
                    partField.ControlWrapperCssClass = "sn-iu-control";
                    partField.Title              = GetDisplayName(descriptor);
                    partField.Description        = GetDescription(descriptor);
                    partField.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-text sn-editorpart-" + propName;
                    partField.PropertyName       = propName;

                    if (propertyType == typeof(bool))
                    {
                        partField.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-boolean sn-editorpart-" + propName;
                    }
                    if (typeof(Enum).IsAssignableFrom(propertyType))
                    {
                        // TODO: fill the instance of the EditorPart control with datas. Best solution is extend the IEditorPartField interface with Fill method
                    }
                    var result = partField as Control;
                    result.ID = "Custom" + propName;
                    return(result);
                }
            }

            if (propertyType == typeof(bool))
            {
                var checkBox = new CheckBoxEditorPartField();
                checkBox.ID                     = "CheckBox" + propName;
                checkBox.Options                = GetEditorOptionsAttribute(descriptor.Attributes);
                checkBox.EditorPartCssClass     = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-boolean sn-editorpart-" + propName;
                checkBox.Title                  = GetDisplayName(descriptor);
                checkBox.Description            = GetDescription(descriptor);
                checkBox.TitleContainerCssClass = "sn-iu-label";
                checkBox.TitleCssClass          = "sn-iu-title";
                checkBox.DescriptionCssClass    = "sn-iu-desc";
                checkBox.ControlWrapperCssClass = "sn-iu-control";
                checkBox.PropertyName           = propName;

                return(checkBox);
            }

            if (typeof(Enum).IsAssignableFrom(propertyType))
            {
                ICollection standardValues = descriptor.Converter.GetStandardValues();
                if (standardValues != null)
                {
                    var list = new DropDownPartField();
                    list.ID                     = "DropDown" + propName;
                    list.Options                = GetEditorOptionsAttribute(descriptor.Attributes);
                    list.EditorPartCssClass     = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-enum sn-editorpart-" + propName;
                    list.Title                  = GetDisplayName(descriptor);
                    list.Description            = GetDescription(descriptor);
                    list.TitleContainerCssClass = "sn-iu-label";
                    list.TitleCssClass          = "sn-iu-title";
                    list.DescriptionCssClass    = "sn-iu-desc";
                    list.ControlWrapperCssClass = "sn-iu-control";
                    list.PropertyName           = propName;
                    foreach (object value in standardValues)
                    {
                        var resourceKey = String.Concat("Enum-", propName, "-", value.ToString());
                        var text        = SenseNetResourceManager.Current.GetStringOrNull("PortletFramework", resourceKey) as string;
                        if (string.IsNullOrEmpty(text))
                        {
                            text = descriptor.Converter.ConvertToString(value);
                        }
                        list.Items.Add(new ListItem(text, value.ToString()));
                    }
                    return(list);
                }

                return(null);
            }

            var textBox = new TextEditorPartField();

            textBox.ID                     = "TextBox" + propName;
            textBox.Options                = GetEditorOptionsAttribute(descriptor.Attributes);
            textBox.EditorPartCssClass     = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-text sn-editorpart-" + propName;
            textBox.Title                  = GetDisplayName(descriptor);
            textBox.Description            = GetDescription(descriptor);
            textBox.TitleContainerCssClass = "sn-iu-label";
            textBox.TitleCssClass          = "sn-iu-title";
            textBox.DescriptionCssClass    = "sn-iu-desc";
            textBox.ControlWrapperCssClass = "sn-iu-control";
            textBox.Columns                = 30;
            textBox.PropertyName           = propName;
            return(textBox);
        }
        internal static Control CreateEditorControl(PropertyDescriptor descriptor)
        {
            if (descriptor == null)
                throw new ArgumentNullException("descriptor");

            var propertyType = descriptor.PropertyType;
            object editor = null;
            
            try
            {
                editor = descriptor.GetEditor(typeof(IEditorPartField));
            }
            catch (Exception e)
            {
                Logger.WriteException(e);
            }

            var propName = descriptor.Name;

            if (editor != null)
            {
                var partField = editor as IEditorPartField;
                if (partField != null)
                {
                    partField.Options = GetEditorOptionsAttribute(descriptor.Attributes);
                    partField.TitleContainerCssClass = "sn-iu-label";
                    partField.TitleCssClass = "sn-iu-title";
                    partField.DescriptionCssClass = "sn-iu-desc";
                    partField.ControlWrapperCssClass = "sn-iu-control";
                    partField.Title = GetDisplayName(descriptor);
                    partField.Description = GetDescription(descriptor);
                    partField.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-text sn-editorpart-" + propName;
                    partField.PropertyName = propName;

                    if (propertyType == typeof (bool))
                        partField.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-boolean sn-editorpart-" + propName;
                    if (typeof (Enum).IsAssignableFrom(propertyType))
                    {
                        // TODO: fill the instance of the EditorPart control with datas. Best solution is extend the IEditorPartField interface with Fill method 
                    }
                    var result = partField as Control;
                    result.ID = "Custom" + propName;
                    return result;
                }
            }

            if (propertyType == typeof (bool))
            {
                var checkBox = new CheckBoxEditorPartField();
                checkBox.ID = "CheckBox" + propName;
                checkBox.Options = GetEditorOptionsAttribute(descriptor.Attributes);
                checkBox.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-boolean sn-editorpart-" + propName;
                checkBox.Title = GetDisplayName(descriptor);
                checkBox.Description = GetDescription(descriptor);
                checkBox.TitleContainerCssClass = "sn-iu-label";
                checkBox.TitleCssClass = "sn-iu-title";
                checkBox.DescriptionCssClass = "sn-iu-desc";
                checkBox.ControlWrapperCssClass = "sn-iu-control";
                checkBox.PropertyName = propName;

                return checkBox;
            }

            if (typeof (Enum).IsAssignableFrom(propertyType))
            {
                ICollection standardValues = descriptor.Converter.GetStandardValues();
                if (standardValues != null)
                {
                    var list = new DropDownPartField();
                    list.ID = "DropDown" + propName;
                    list.Options = GetEditorOptionsAttribute(descriptor.Attributes);
                    list.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-enum sn-editorpart-" + propName;
                    list.Title = GetDisplayName(descriptor);
                    list.Description = GetDescription(descriptor);
                    list.TitleContainerCssClass = "sn-iu-label";
                    list.TitleCssClass = "sn-iu-title";
                    list.DescriptionCssClass = "sn-iu-desc";
                    list.ControlWrapperCssClass = "sn-iu-control";
                    list.PropertyName = propName;
                    foreach (object value in standardValues)
                    {
                        var resourceKey = String.Concat("Enum-", propName, "-", value.ToString());
                        var text = SenseNetResourceManager.Current.GetStringOrNull("PortletFramework", resourceKey) as string;
                        if (string.IsNullOrEmpty(text))
                            text = descriptor.Converter.ConvertToString(value);
                        list.Items.Add(new ListItem(text, value.ToString()));
                    }
                    return list;
                }

                return null;
            }

            var textBox = new TextEditorPartField();
            textBox.ID = "TextBox" + propName;
            textBox.Options = GetEditorOptionsAttribute(descriptor.Attributes);
            textBox.EditorPartCssClass = "sn-inputunit ui-helper-clearfix sn-custom-editorpart-text sn-editorpart-" + propName;
            textBox.Title = GetDisplayName(descriptor);
            textBox.Description = GetDescription(descriptor);
            textBox.TitleContainerCssClass = "sn-iu-label";
            textBox.TitleCssClass = "sn-iu-title";
            textBox.DescriptionCssClass = "sn-iu-desc";
            textBox.ControlWrapperCssClass = "sn-iu-control";
            textBox.Columns = 30;
            textBox.PropertyName = propName;
            return textBox;
        }