Beispiel #1
0
 /// <summary>
 /// Create a column from the given PropertyInfo and OLVColumn attribute
 /// </summary>
 /// <param name="pinfo"></param>
 /// <param name="attr"></param>
 /// <returns></returns>
 protected virtual OLVColumn MakeColumnFromAttribute(PropertyInfo pinfo, OLVColumnAttribute attr)
 {
     return(MakeColumn(pinfo.Name, DisplayNameToColumnTitle(pinfo.Name), pinfo.CanWrite, pinfo.PropertyType, attr));
 }
Beispiel #2
0
        /// <summary>
        /// Create a column.
        /// </summary>
        /// <param name="aspectName"></param>
        /// <param name="title"></param>
        /// <param name="attr"></param>
        /// <returns></returns>
        protected virtual OLVColumn MakeColumn(string aspectName, string title, OLVColumnAttribute attr)
        {
            string columnTitle = (attr == null || String.IsNullOrEmpty(attr.Title)) ? title : attr.Title;

            return(new OLVColumn(columnTitle, aspectName));
        }
Beispiel #3
0
        /// <summary>
        /// Make a column from the given PropertyDescriptor
        /// </summary>
        /// <param name="pd"></param>
        /// <returns></returns>
        public virtual OLVColumn MakeColumnFromPropertyDescriptor(PropertyDescriptor pd)
        {
            OLVColumnAttribute attr = pd.Attributes[typeof(OLVColumnAttribute)] as OLVColumnAttribute;

            return(MakeColumn(pd.Name, DisplayNameToColumnTitle(pd.DisplayName), !pd.IsReadOnly, pd.PropertyType, attr));
        }
Beispiel #4
0
        /// <summary>
        /// Create a column with all the given information
        /// </summary>
        /// <param name="aspectName"></param>
        /// <param name="title"></param>
        /// <param name="editable"></param>
        /// <param name="propertyType"></param>
        /// <param name="attr"></param>
        /// <returns></returns>
        protected virtual OLVColumn MakeColumn(string aspectName, string title, bool editable, Type propertyType, OLVColumnAttribute attr)
        {
            OLVColumn column = this.MakeColumn(aspectName, title, attr);

            column.Name = (attr == null || String.IsNullOrEmpty(attr.Name)) ? aspectName : attr.Name;
            this.ConfigurePossibleBooleanColumn(column, propertyType);

            if (attr == null)
            {
                column.IsEditable = editable;
                return(column);
            }

            column.AspectToStringFormat = attr.AspectToStringFormat;
            if (attr.IsCheckBoxesSet)
            {
                column.CheckBoxes = attr.CheckBoxes;
            }
            column.DisplayIndex   = attr.DisplayIndex;
            column.FillsFreeSpace = attr.FillsFreeSpace;
            if (attr.IsFreeSpaceProportionSet)
            {
                column.FreeSpaceProportion = attr.FreeSpaceProportion;
            }
            column.GroupWithItemCountFormat         = attr.GroupWithItemCountFormat;
            column.GroupWithItemCountSingularFormat = attr.GroupWithItemCountSingularFormat;
            column.Hyperlink        = attr.Hyperlink;
            column.ImageAspectName  = attr.ImageAspectName;
            column.IsEditable       = attr.IsEditableSet ? attr.IsEditable : editable;
            column.IsTileViewColumn = attr.IsTileViewColumn;
            column.IsVisible        = attr.IsVisible;
            column.MaximumWidth     = attr.MaximumWidth;
            column.MinimumWidth     = attr.MinimumWidth;
            column.Tag = attr.Tag;
            if (attr.IsTextAlignSet)
            {
                column.TextAlign = attr.TextAlign;
            }
            column.ToolTipText = attr.ToolTipText;
            if (attr.IsTriStateCheckBoxesSet)
            {
                column.TriStateCheckBoxes = attr.TriStateCheckBoxes;
            }
            column.UseInitialLetterForGroup = attr.UseInitialLetterForGroup;
            column.Width = attr.Width;
            if (attr.GroupCutoffs != null && attr.GroupDescriptions != null)
            {
                column.MakeGroupies(attr.GroupCutoffs, attr.GroupDescriptions);
            }
            return(column);
        }
Beispiel #5
0
        /// <summary>
        /// Generate a list of OLVColumns based on the attributes of the given type
        /// If allProperties to true, all public properties will have a matching column generated.
        /// If allProperties is false, only properties that have a OLVColumn attribute will have a column generated.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="allProperties">Will columns be generated for properties that are not marked with [OLVColumn].</param>
        /// <returns>A collection of OLVColumns matching the attributes of Type that have OLVColumnAttributes.</returns>
        public virtual IList <OLVColumn> GenerateColumns(Type type, bool allProperties)
        {
            List <OLVColumn> columns = new List <OLVColumn>();

            // Sanity
            if (type == null)
            {
                return(columns);
            }

            // Iterate all public properties in the class and build columns from those that have
            // an OLVColumn attribute and that are not ignored.
            foreach (PropertyInfo pinfo in type.GetProperties())
            {
                if (Attribute.GetCustomAttribute(pinfo, typeof(OLVIgnoreAttribute)) != null)
                {
                    continue;
                }

                OLVColumnAttribute attr = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute;
                if (attr == null)
                {
                    if (allProperties)
                    {
                        columns.Add(this.MakeColumnFromPropertyInfo(pinfo));
                    }
                }
                else
                {
                    columns.Add(this.MakeColumnFromAttribute(pinfo, attr));
                }
            }

            // How many columns have DisplayIndex specifically set?
            int countPositiveDisplayIndex = 0;

            foreach (OLVColumn col in columns)
            {
                if (col.DisplayIndex >= 0)
                {
                    countPositiveDisplayIndex += 1;
                }
            }

            // Give columns that don't have a DisplayIndex an incremental index
            int columnIndex = countPositiveDisplayIndex;

            foreach (OLVColumn col in columns)
            {
                if (col.DisplayIndex < 0)
                {
                    col.DisplayIndex = (columnIndex++);
                }
            }

            columns.Sort(delegate(OLVColumn x, OLVColumn y)
            {
                return(x.DisplayIndex.CompareTo(y.DisplayIndex));
            });

            return(columns);
        }