コード例 #1
0
 protected override FormElement Build(IFormProperty property, Func <string, object> deserializer)
 {
     return(new StringField(property.Name)
     {
         IsPassword = property.GetCustomAttribute <Display.PasswordAttribute>() != null
     });
 }
コード例 #2
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            var attr = property.GetCustomAttribute <DirectContentAttribute>();

            return(attr == null
                ? null
                : new DirectContentField(property.Name, property.PropertyType));
        }
コード例 #3
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            if (property.GetCustomAttribute <CrudAttribute>() != null)
            {
                return(new CrudField(property.Name, property.PropertyType));
            }

            return(null);
        }
コード例 #4
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            if (property.PropertyType != typeof(T))
            {
                return(null);
            }

            return(Build(property, deserializer));
        }
コード例 #5
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            var isSwitch = property.GetCustomAttribute <Display.ToggleAttribute>() != null;

            return(new BooleanField(property.Name)
            {
                IsSwitch = isSwitch
            });
        }
コード例 #6
0
        protected override FormElement Build(IFormProperty property, Func <string, object> deserializer)
        {
            var maskAttr = property.GetCustomAttribute <MaskedAttribute>();

            if (property.GetCustomAttribute <MaskedAttribute>() != null)
            {
                return(new StringField(property.Name, maskAttr.Mask));
            }
            return(new StringField(property.Name));
        }
コード例 #7
0
        private FormElement Build(IFormProperty property, Func <string, object> deserializer)
        {
            var element = Build(property, deserializer, PropertyBuilders);

            if (element == null && TypeBuilders.TryGetValue(property.PropertyType, out var builders))
            {
                element = Build(property, deserializer, builders);
            }

            return(element);
        }
コード例 #8
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            var attribute = property.GetCustomAttribute <ProgressAttribute>();

            return(attribute != null
            ? new ProgressField(property.Name)
            {
                Maximum = Utilities.GetResource <object>(attribute.Maximum, 100d, Deserializers.Double)
            }
            : null);
        }
コード例 #9
0
        public void Initialize(FormElement element, IFormProperty property, Func <string, object> deserializer)
        {
            var attr = property.GetCustomAttribute <FieldAttribute>();

            if (attr == null)
            {
                if (element is FormField formField && formField.Name == null)
                {
                    formField.Name = new LiteralValue(property.Name.Humanize());
                }

                return;
            }

            element.IsVisible = Utilities.GetResource <bool>(attr.IsVisible, true, Deserializers.Boolean);

            if (element is FormField field)
            {
                field.Name = attr.HasName
                    ? Utilities.GetStringResource(attr.Name)
                    : new LiteralValue(property.Name.Humanize());
                field.ToolTip = Utilities.GetStringResource(attr.ToolTip);
                field.Icon    = Utilities.GetIconResource(attr.Icon);
            }

            if (element is DataFormField dataField)
            {
                if (property.CanWrite)
                {
                    dataField.IsReadOnly = Utilities.GetResource <bool>(attr.IsReadOnly, false, Deserializers.Boolean);
                }
                else
                {
                    dataField.IsReadOnly = LiteralValue.True;
                }

                var type = property.PropertyType;
                if (attr.DefaultValue != null)
                {
                    dataField.DefaultValue = Utilities.GetResource <object>(attr.DefaultValue, null, deserializer);
                }
                else if (!type.IsValueType)
                {
                    // Null for reference types and nullables.
                    dataField.DefaultValue = LiteralValue.Null;
                }
                else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    // Same for nullables.
                    dataField.DefaultValue = LiteralValue.Null;
                }
            }
        }
コード例 #10
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            var replacements = property
                               .GetCustomAttributes <ReplaceAttribute>()
                               .OrderBy(attr => attr.Position)
                               .Select(attr => attr.GetReplacement());

            return(new ConvertedField(
                       property.Name,
                       property.PropertyType,
                       new ReplacementPipe(Deserializer, replacements)));
        }
コード例 #11
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            var timeAttribute = property.GetCustomAttribute <TimeAttribute>();

            if (timeAttribute != null)
            {
                return(new TimeField(property.Name)
                {
                    Is24Hours = Utilities.GetResource <bool>(timeAttribute.Is24Hours, false, Deserializers.Boolean)
                });
            }

            return(new DateField(property.Name));
        }
コード例 #12
0
        public FormPropertyAdapter(IFormProperty formProperty)
        {
            this.FormProperty = formProperty;

            validationConstraints = new List <IFormFieldValidationConstraint>();
            if (formProperty.Required)
            {
                validationConstraints.Add(new FormFieldValidationConstraintImpl("required", null));
            }
            if (!formProperty.Writable)
            {
                validationConstraints.Add(new FormFieldValidationConstraintImpl("readonly", null));
            }
        }
コード例 #13
0
        private static FormElement Build(IFormProperty property, Func <string, object> deserializer,
                                         List <IFieldBuilder> builders)
        {
            foreach (var builder in builders)
            {
                var element = builder.TryBuild(property, deserializer);
                if (element != null)
                {
                    return(element);
                }
            }

            return(null);
        }
コード例 #14
0
        public void Initialize(FormElement element, IFormProperty property, Func <string, object> deserializer)
        {
            var attrs = property.GetCustomAttributes <MetaAttribute>();

            if (attrs == null)
            {
                return;
            }

            foreach (var attr in attrs)
            {
                if (!string.IsNullOrEmpty(attr.Name))
                {
                    element.Metadata[attr.Name] = attr.Value;
                }
            }
        }
コード例 #15
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            var attr = property.GetCustomAttribute <SliderAttribute>();

            if (attr == null)
            {
                return(null);
            }

            return(new SliderField(property.Name, property.PropertyType)
            {
                // Since WPF slider uses doubles, we have to guess a double stringified value.
                // Defaults to 0d-10d.
                Minimum = Utilities.GetResource <object>(attr.Minimum, 0d, Deserializers.Double),
                Maximum = Utilities.GetResource <object>(attr.Maximum, 10d, Deserializers.Double)
            });
        }
コード例 #16
0
        public void Initialize(FormElement element, IFormProperty property, Func <string, object> deserializer)
        {
            if (!(element is DataFormField field))
            {
                return;
            }

            var attr = property.GetCustomAttribute <BindingAttribute>();

            if (attr == null)
            {
                return;
            }

            attr.Apply(field.BindingOptions);
            if (attr.ConversionErrorMessage != null && element is ConvertedField convertedField)
            {
                var errorProvider = Utilities.GetErrorProvider(attr.ConversionErrorMessage, property.Name);
                convertedField.ConversionErrorMessage = errorProvider;
            }
        }
コード例 #17
0
        public void Initialize(FormElement element, IFormProperty property, Func <string, object> deserializer)
        {
            if (!(element is DataFormField dataField))
            {
                return;
            }

            var attributes = property.GetCustomAttributes <ValueAttribute>().ToArray();

            if (attributes.Length == 0)
            {
                return;
            }

            var modelType = property.DeclaringType;

            foreach (var attr in attributes)
            {
                dataField.Validators.Add(CreateValidator(modelType, dataField.Key, attr, deserializer));
            }
        }
コード例 #18
0
        public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
        {
            var selectFrom = property.GetCustomAttribute <SelectFromAttribute>();

            if (selectFrom == null)
            {
                return(null);
            }

            var type  = property.PropertyType;
            var field = new SelectionField(property.Name, property.PropertyType);

            if (selectFrom.DisplayPath != null)
            {
                field.DisplayPath = BoundExpression.ParseSimplified(selectFrom.DisplayPath);
            }

            if (selectFrom.ValuePath != null)
            {
                field.ValuePath = BoundExpression.ParseSimplified(selectFrom.ValuePath);
            }

            if (selectFrom.ItemStringFormat != null)
            {
                field.ItemStringFormat = BoundExpression.ParseSimplified(selectFrom.ItemStringFormat);
            }

            field.SelectionType = Utilities.GetResource <SelectionType>(selectFrom.SelectionType, SelectionType.ComboBox, Deserializers.Enum <SelectionType>());

            switch (selectFrom.ItemsSource)
            {
            case string expr:
                var value = BoundExpression.Parse(expr);
                if (!value.IsSingleResource)
                {
                    throw new InvalidOperationException("ItemsSource must be a single resource reference.");
                }

                field.ItemsSource = value.Resources[0];
                break;

            case IEnumerable <object> enumerable:
                field.ItemsSource = new LiteralValue(enumerable.ToList());
                break;

            case Type enumType:
                if (!enumType.IsEnum)
                {
                    throw new InvalidOperationException("A type argument for ItemsSource must be an enum.");
                }

                var values     = Enum.GetValues(enumType);
                var collection = new List <KeyValuePair <ValueType, IValueProvider> >();
                foreach (Enum enumValue in values)
                {
                    var            enumName   = enumValue.ToString();
                    var            memInfo    = enumType.GetMember(enumName);
                    var            attributes = memInfo[0].GetCustomAttributes(typeof(EnumDisplayAttribute), false);
                    IValueProvider name;
                    if (attributes.Length > 0)
                    {
                        var attr = (EnumDisplayAttribute)attributes[0];
                        name = BoundExpression.ParseSimplified(attr.Name);
                    }
                    else
                    {
                        name = new LiteralValue(enumName.Humanize());
                    }

                    collection.Add(new KeyValuePair <ValueType, IValueProvider>(enumValue, name));
                }

                field.ItemsSource = new EnumerableStringValueProvider(collection);
                field.DisplayPath = new LiteralValue(nameof(StringProxy.Value));
                field.ValuePath   = new LiteralValue(type == typeof(string)
                        ? nameof(StringProxy.Value)
                        : nameof(StringProxy.Key));
                break;
            }

            return(field);
        }
コード例 #19
0
 public ElementWrapper(FormElement element, IFormProperty property)
 {
     Element  = element;
     Property = property;
 }
コード例 #20
0
        public void Initialize(IShapeDefinition shape, string mode, string shapeCode, string shapeXml)
        {
            #region Validations

            if (shape == null)
            {
                throw new ArgumentNullException(nameof(shape));
            }

            if (mode == null)
            {
                throw new ArgumentNullException(nameof(mode));
            }

            #endregion


            /*
             *
             */
            if (string.IsNullOrEmpty(shapeCode) == true)
            {
                this.Text = shape.FriendlyName;
            }
            else
            {
                this.Text = string.Concat(shape.FriendlyName, ": ", shapeCode);
            }


            /*
             *
             */
            Dictionary <string, string> values = new Dictionary <string, string>();

            if (string.IsNullOrEmpty(shapeXml) == false)
            {
                XmlDocument docShapeXml = new XmlDocument();
                docShapeXml.LoadXml(shapeXml);

                foreach (XmlElement elem in docShapeXml.SelectNodes(" /r/* "))
                {
                    values.Add(elem.LocalName, elem.InnerText);
                }
            }


            /*
             *
             */
            var config = FormsConfiguration.Current;

            XmlDocument document = shape.FormDefinition;
            _properties     = new Dictionary <string, IFormProperty>();
            _propertiesList = new List <IFormProperty>();

            foreach (XmlElement section in document.SelectNodes(" /xf:shape/xf:section ", config.NsManager))
            {
                string sectionName = section.GetAttribute("name");


                TabPage tabPage = new TabPage(sectionName);
                tabPage.Name = sectionName;

                Panel tabPanel = new Panel();
                tabPanel.Dock    = DockStyle.Fill;
                tabPanel.Padding = new Padding(5);

                tabPage.Controls.Add(tabPanel);


                /*
                 *
                 */
                foreach (XmlElement property in section.SelectNodes(" *[ @id and @name ] ", config.NsManager))
                {
                    string propertyId = property.GetAttribute("id");


                    /*
                     *
                     */
                    var propertyConfig = config.Find(property);

                    if (propertyConfig == null)
                    {
                        continue;
                    }


                    /*
                     *
                     */
                    IFormProperty prop = Platinum.Activator.Create <IFormProperty>(propertyConfig.Moniker);
                    prop.Control.Dock = DockStyle.Top;
                    prop.Initialize(property, mode);

                    if (values.ContainsKey(propertyId) == true)
                    {
                        prop.Value = values[propertyId];
                    }
                    else
                    {
                        prop.Value = null;
                    }

                    prop.EvaluateConditional(values);
                    prop.RebuildConditionals += new EventHandler(RebuildConditionals);

                    tabPanel.Controls.Add(prop.Control);

                    _properties.Add(prop.Id, prop);
                    _propertiesList.Add(prop);
                }


                /*
                 * This effectively re-orders the children, so that the z-Index
                 * matches their position. This will allow the user to tab
                 * correctly from field to field.
                 */
                foreach (Control c in tabPanel.Controls)
                {
                    c.BringToFront();
                }

                tabs.TabPages.Add(tabPage);
            }


            /*
             *
             */
            _propertiesList.Reverse();


            /*
             * Ergonomy: keep a preference of the last used tab, and automatically
             * set the current selected tab. This will allow an end-user to keep
             * focussed on the most relevant tab.
             */
            if (string.IsNullOrEmpty(Properties.Settings.Default.SelectedTab) == false)
            {
                tabs.SelectTab(Properties.Settings.Default.SelectedTab);
            }
        }
コード例 #21
0
 protected abstract FormElement Build(IFormProperty property, Func <string, object> deserializer);
コード例 #22
0
 public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
 {
     return(new DateField(property.Name));
 }
コード例 #23
0
 public FormElement TryBuild(IFormProperty property, Func <string, object> deserializer)
 {
     return(new ConvertedField(property.Name, property.PropertyType, Deserializer));
 }
コード例 #24
0
 protected override FormElement Build(IFormProperty property, Func <string, object> deserializer)
 {
     return(new StringField(property.Name));
 }