Exemplo n.º 1
0
        public virtual bool IsHidden(ColumnDescriptor columnDescriptor)
        {
            if (IsObsolete(columnDescriptor))
            {
                return(true);
            }
            var hiddenAttribute = FilterAttributes(columnDescriptor.UiMode, columnDescriptor.GetAttributes()).OfType <HiddenAttribute>().FirstOrDefault();

            if (hiddenAttribute != null)
            {
                return(true);
            }

            var hideWhens      = columnDescriptor.GetAttributes().OfType <HideWhenAttribute>().ToArray();
            var hideIfAncestor =
                new HashSet <Type>(hideWhens.SelectMany(attr => attr.AncestorsOfAnyOfTheseTypes).Where(type => null != type));

            if (hideIfAncestor.Count > 0)
            {
                for (ColumnDescriptor ancestor = columnDescriptor.Parent; ancestor != null; ancestor = ancestor.Parent)
                {
                    if (hideIfAncestor.Any(type => type.IsAssignableFrom(ancestor.PropertyType)))
                    {
                        return(true);
                    }
                }
            }

            ColumnDescriptor oneToManyColumn = columnDescriptor.GetOneToManyColumn();

            if (oneToManyColumn != null)
            {
                var oneToManyAttribute = oneToManyColumn.GetAttributes().OfType <OneToManyAttribute>().FirstOrDefault();
                if (oneToManyAttribute != null && oneToManyAttribute.ForeignKey == columnDescriptor.Name)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private IColumnCaption GetBaseDisplayName(ColumnDescriptor columnDescriptor)
        {
            var oneToManyColumn = columnDescriptor.GetOneToManyColumn();

            if (oneToManyColumn != null)
            {
                var oneToManyAttribute = oneToManyColumn.GetAttributes().OfType <OneToManyAttribute>().FirstOrDefault();
                if (oneToManyAttribute != null)
                {
                    if (@"Key" == columnDescriptor.Name && oneToManyAttribute.IndexDisplayName != null)
                    {
                        return(new ColumnCaption(oneToManyAttribute.IndexDisplayName));
                    }
                    if (@"Value" == columnDescriptor.Name && oneToManyAttribute.ItemDisplayName != null)
                    {
                        return(new ColumnCaption(oneToManyAttribute.ItemDisplayName));
                    }
                }
            }
            var invariantDisplayNameAttribute = columnDescriptor.GetAttributes().OfType <InvariantDisplayNameAttribute>().FirstOrDefault();

            if (null != invariantDisplayNameAttribute)
            {
                return(new ColumnCaption(invariantDisplayNameAttribute.InvariantDisplayName));
            }
            if (columnDescriptor.Name == null)
            {
                if (columnDescriptor.Parent != null)
                {
                    return(GetBaseDisplayName(columnDescriptor.Parent));
                }
                if (columnDescriptor.PropertyType != null)
                {
                    return(GetInvariantDisplayName(columnDescriptor.UiMode, columnDescriptor.PropertyType));
                }
            }
            return(new ColumnCaption(columnDescriptor.Name));
        }
Exemplo n.º 3
0
        public virtual bool IsAdvanced(ColumnDescriptor columnDescriptor)
        {
            if (IsObsolete(columnDescriptor))
            {
                return true;
            }
            var advancedAttribute = columnDescriptor.GetAttributes().OfType<AdvancedAttribute>().FirstOrDefault();
            if (advancedAttribute != null)
            {
                return advancedAttribute.Advanced;
            }

            var hideWhens = columnDescriptor.GetAttributes().OfType<HideWhenAttribute>().ToArray();
            var advancedIfAncestor =
                new HashSet<Type>(hideWhens.SelectMany(attr => attr.AncestorsOfAnyOfTheseTypes).Where(type => null != type));
            if (advancedIfAncestor.Count > 0)
            {
                for (ColumnDescriptor ancestor = columnDescriptor.Parent; ancestor != null; ancestor = ancestor.Parent)
                {
                    if (advancedIfAncestor.Any(type => type.IsAssignableFrom(ancestor.PropertyType)))
                    {
                        return true;
                    }
                }
            }

            ColumnDescriptor oneToManyColumn = columnDescriptor.GetOneToManyColumn();
            if (oneToManyColumn != null)
            {
                var oneToManyAttribute = oneToManyColumn.GetAttributes().OfType<OneToManyAttribute>().FirstOrDefault();
                if (oneToManyAttribute != null && oneToManyAttribute.ForeignKey == columnDescriptor.Name)
                {
                    return true;
                }
            }
            return false;
        }
Exemplo n.º 4
0
 private string GetBaseDisplayName(ColumnDescriptor columnDescriptor)
 {
     var oneToManyColumn = columnDescriptor.GetOneToManyColumn();
     if (oneToManyColumn != null)
     {
         var oneToManyAttribute = oneToManyColumn.GetAttributes().OfType<OneToManyAttribute>().FirstOrDefault();
         if (oneToManyAttribute != null)
         {
             if ("Key" == columnDescriptor.Name && oneToManyAttribute.IndexDisplayName != null) // Not L10N
             {
                 return oneToManyAttribute.IndexDisplayName;
             }
             if ("Value" == columnDescriptor.Name && oneToManyAttribute.ItemDisplayName != null) // Not L10N
             {
                 return oneToManyAttribute.ItemDisplayName;
             }
         }
     }
     var invariantDisplayNameAttribute = columnDescriptor.GetAttributes().OfType<InvariantDisplayNameAttribute>().FirstOrDefault();
     if (null != invariantDisplayNameAttribute)
     {
         return invariantDisplayNameAttribute.InvariantDisplayName;
     }
     if (columnDescriptor.Name == null)
     {
         if (columnDescriptor.Parent != null)
         {
             return GetBaseDisplayName(columnDescriptor.Parent);
         }
         if (columnDescriptor.PropertyType != null)
         {
             return columnDescriptor.PropertyType.Name;
         }
     } 
     return columnDescriptor.Name;
 }