Exemplo n.º 1
0
        private static ITableColumnSettings SettingsMerger(string name, Type type, Func <string, ITableColumnSettings> onGetSettings)
        {
            ITableColumnSettings target    = TableColumnSettingMapping.GetSettings(type);
            ITableColumnSettings overrides = onGetSettings?.Invoke(name);

            TableColumnSettings.Apply(ref target, overrides);
            if (target.TextCasing.HasValue)
            {
                return(target);
            }
            type = type.ResolveType();
            if (type == null)
            {
                return(target);
            }

            if (type.IsArray)
            {
                type = type.GetElementType();
                if (type == null || !type.IsAssignableFrom(typeof(byte)) && !type.IsAssignableFrom(typeof(sbyte)))
                {
                    return(target);
                }
                target.Formatting = TableColumnFormatting.Raw;
                target.TextCasing = TextCasing.Upper;
            }
            else if (type == typeof(Guid))
            {
                target.Formatting = TableColumnFormatting.Raw;
                target.TextCasing = TextCasing.Upper;
            }

            return(target);
        }
Exemplo n.º 2
0
 static void ApplyHeaderProps(ref ITableColumnSettings target, ITableColumnSettings overrides)
 {
     if (overrides.Text != null)
     {
         target.Text = overrides.Text;
     }
     if (overrides.HeaderAbbr != null)
     {
         target.HeaderAbbr = overrides.HeaderAbbr;
     }
     if (overrides.Sortable.HasValue)
     {
         target.Sortable = overrides.Sortable == true;
     }
     if (overrides.Searchable.HasValue)
     {
         target.Searchable = overrides.Searchable == true;
     }
     if (overrides.Hidden.HasValue)
     {
         target.Hidden = overrides.Hidden == true;
     }
     if (overrides.Order.HasValue)
     {
         target.Order = overrides.Order.Value;
     }
     if (overrides.IsRowHeader.HasValue)
     {
         target.IsRowHeader = overrides.IsRowHeader == true;
     }
 }
Exemplo n.º 3
0
 public static void Apply(ref ITableColumnSettings target, ITableColumnSettings overrides)
 {
     if (overrides == null)
     {
         return;
     }
     ApplyHeaderProps(ref target, overrides);
     ApplyStyle(ref target, overrides);
Exemplo n.º 4
0
        public bool MapSchemaTable([NotNull] DataTable schema, Func <string, bool> filter = null, Func <string, ITableColumnSettings> onGetSettings = null)
        {
            ClearItems();
            if (schema.Columns.Count == 0 ||
                schema.Rows.Count == 0 ||
                __columnNames.Any(e => !schema.Columns.Contains(e)))
            {
                return(false);
            }

            IDictionary <string, ITableColumnSettings> allSettings = new Dictionary <string, ITableColumnSettings>(StringComparer.OrdinalIgnoreCase);

            foreach (DataRow columnInfo in schema.Rows)
            {
                string name = columnInfo.Get <string>(__columnNames[0])?.ToLowerInvariant() ?? throw new InvalidOperationException("Column name is missing.");

                // filter the columns
                if (filter?.Invoke(name) == false)
                {
                    continue;
                }

                Type type = columnInfo.Get <Type>(__columnNames[1]) ?? throw new InvalidOperationException("Column data type is missing.");
                // get the default settings for the type and specific column settings overrides then merge them
                ITableColumnSettings settings = SettingsMerger(name, type, onGetSettings);

                ITableColumn column = new TableColumn(name, type)
                {
                    Size        = columnInfo.Get <int>(__columnNames[2]),
                    PrimaryKey  = columnInfo.Get <bool>(__columnNames[3]),
                    Unique      = columnInfo.Get <bool>(__columnNames[4]),
                    RowId       = columnInfo.Get <bool>(__columnNames[5]),
                    AllowDbNull = columnInfo.Get <bool>(__columnNames[6]),
                    Sortable    = type.IsPrimitive(),
                    ReadOnly    = columnInfo.Get <bool>(__columnNames[7]),
                    Expression  = columnInfo.Get <bool>(__columnNames[8]),
                    Hidden      = columnInfo.Get <bool>(__columnNames[9]),
                    Align       = type.IsNumeric() ? HorizontalAlignment.Right : HorizontalAlignment.Left,
                    Order       = Items.Count
                };

                allSettings[column.Name] = settings;
                settings.Apply(column);
                Items.Add(column);
            }

            AdjustWidths(allSettings);
            return(true);
        }
Exemplo n.º 5
0
 static void ApplyStyle(ref ITableColumnSettings target, ITableColumnSettings overrides)
 {
     if (overrides.Formattable.HasValue)
     {
         target.Formattable = overrides.Formattable == true;
     }
     if (overrides.Align.HasValue)
     {
         target.Align = overrides.Align.Value;
     }
     if (overrides.Weight.HasValue)
     {
         target.Weight = overrides.Weight.Value;
     }
     if (overrides.Formatting.HasValue)
     {
         target.Formatting = overrides.Formatting;
     }
     if (!string.IsNullOrEmpty(overrides.CustomFormat))
     {
         target.CustomFormat = overrides.CustomFormat;
     }
     if (overrides.TextCasing.HasValue)
     {
         target.TextCasing = overrides.TextCasing.Value;
     }
     if (overrides.Class != null)
     {
         target.Class = overrides.Class;
     }
     if (overrides.ThClass != null)
     {
         target.ThClass = overrides.ThClass;
     }
     if (overrides.ThStyle != null)
     {
         target.ThStyle = overrides.ThStyle;
     }
     if (overrides.TdClass != null)
     {
         target.TdClass = overrides.TdClass;
     }
     if (overrides.Variant != null)
     {
         target.Variant = overrides.Variant;
     }
 }
Exemplo n.º 6
0
        public bool MapSchemaTable <TInstance>([NotNull] TInstance instance, Func <string, bool> filter = null, Func <string, ITableColumnSettings> onGetSettings = null)
        {
            ClearItems();
            IReadOnlyDictionary <string, Type> schema = instance.ToSchema();

            if (schema.Count == 0)
            {
                return(false);
            }

            IDictionary <string, ITableColumnSettings> allSettings = new Dictionary <string, ITableColumnSettings>(StringComparer.OrdinalIgnoreCase);

            foreach (KeyValuePair <string, Type> pair in schema)
            {
                // filter the columns
                if (filter?.Invoke(pair.Key) == false)
                {
                    continue;
                }
                // get the default settings for the type and specific column settings overrides then merge them
                ITableColumnSettings settings = SettingsMerger(pair.Key, pair.Value, onGetSettings);

                ITableColumn column = new TableColumn(pair.Key, pair.Value)
                {
                    //Size = pair.Get<int>(COLUMN_NAMES[2]),
                    //PrimaryKey = pair.Get<bool>(COLUMN_NAMES[3]),
                    //Unique = pair.Get<bool>(COLUMN_NAMES[4]),
                    //RowId = pair.Get<bool>(COLUMN_NAMES[5]),
                    AllowDbNull = pair.Value.IsClass,
                    Sortable    = pair.Value.IsPrimitive(),
                    //ReadOnly = pair.Get<bool>(COLUMN_NAMES[7]),
                    //Expression = pair.Get<bool>(COLUMN_NAMES[8]),
                    //Hidden = pair.Get<bool>(COLUMN_NAMES[9]),
                    Align = pair.Value.IsNumeric() ? HorizontalAlignment.Right : HorizontalAlignment.Left,
                    Order = Items.Count
                };

                allSettings[column.Name] = settings;
                settings.Apply(column);
                Items.Add(column);
            }

            AdjustWidths(allSettings);
            return(true);
        }
Exemplo n.º 7
0
        public void Apply(ITableColumnSettings column)
        {
            ITableColumnSettings target = this;

            Apply(ref target, column);
        }