override public void ProcessView() { if (SourceObjectType != null) { string descr = ModelHelper.GetEntityJDescriptionOrName(SourceObjectType); SetNewCaption(descr + " " + FrwCRUDRes.SimplePropertyWindow_Props); } if (tempSourceObject != null) { if (tempSourceObject.GetType().Equals(SourceObjectType) == false) { throw new ArgumentException("SourceObject not of SourceObjectType"); } bag1 = new PropertyBag(); bag1.GetValue += new PropertySpecEventHandler(this.bag1_GetValue); bag1.SetValue += new PropertySpecEventHandler(this.bag1_SetValue); bag1.ValueModified += Bag1_ValueModified; bag1.SourceObject = tempSourceObject; bag1.SourceObjectType = SourceObjectType; PropertyInfo[] propsList = AttrHelper.GetBasePropertiesFirst(tempSourceObject.GetType()); PropertyInfo pName = AttrHelper.GetProperty <JNameProperty>(tempSourceObject.GetType()); if (pName != null) { propsList = propsList.OrderBy(x => x != pName).ToArray(); } PropertySpec props = null; foreach (PropertyInfo p in propsList) { if (AttrHelper.IsGenericListTypeOf(p.PropertyType, typeof(IField))) { IList itemDatas = (IList)p.GetValue(tempSourceObject); if (itemDatas != null) { foreach (var it in itemDatas) { IField itemdata = (IField)it; string group = null; props = new PropertySpec(ITEM_ATTRIBUTE_PREFIX + itemdata.FieldSysname, typeof(string), group, itemdata.Name); props.PropTag = itemdata; if (viewMode == ViewMode.View || viewMode == ViewMode.ViewContent) { props.Attributes = new Attribute[] { new ReadOnlyAttribute(true) }; } bag1.Properties.Add(props); } } } else { JReadOnly readOnlyAttr = AttrHelper.GetAttribute <JReadOnly>(SourceObjectType, p.Name); JIgnore ignoreAttr = AttrHelper.GetAttribute <JIgnore>(SourceObjectType, p.Name); if (ignoreAttr != null) { continue; } string desc = ModelHelper.GetPropertyJDescriptionOrName(p); bool isCustomEdit = false; if (AppManager.Instance.IsCustomEditProperty(SourceObjectType, p.Name)) { isCustomEdit = true; } Type pType = null; if (isCustomEdit) { pType = typeof(string); //disabled comboboxes for list type fields } else { pType = p.PropertyType; } props = new PropertySpec(desc, pType, null, desc); props.PropTag = p.Name; if (readOnlyAttr != null || viewMode == ViewMode.View || viewMode == ViewMode.ViewContent) { props.Attributes = new Attribute[] { new ReadOnlyAttribute(true) }; } if (isCustomEdit) { //not only for edit props.EditorTypeName = typeof(CustomPropertyEditor).ToString(); } bag1.Properties.Add(props); } this.propertyGrid1.SelectedObjects = new object[] { bag1 }; } } else { this.propertyGrid1.SelectedObjects = null; } }
/// <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 override IList <OLVColumn> GenerateColumns(Type type, bool allProperties) { List <OLVColumn> columns = new List <OLVColumn>(); // Sanity if (type == null) { return(columns); } PropertyInfo[] pList = AttrHelper.GetBasePropertiesFirst(type); PropertyInfo pName = AttrHelper.GetProperty <JNameProperty>(type); if (pName != null) { pList = pList.OrderBy(x => x != pName).ToArray(); } // 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()) foreach (PropertyInfo pinfo in pList) { if (Attribute.GetCustomAttribute(pinfo, typeof(OLVIgnoreAttribute)) != null) { continue; } //added j if (Attribute.GetCustomAttribute(pinfo, typeof(JIgnore)) != null) { continue; } //if (Attribute.GetCustomAttribute(pinfo, typeof(JManyToOne)) != null) // continue; //обычно дублирована с JForeinKey поэтому оставляем одну OLVColumnAttribute attr = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute; OLVColumn column = null; if (attr == null) { if (allProperties) { column = this.MakeColumnFromPropertyInfo(pinfo); } } else { column = this.MakeColumnFromAttribute(pinfo, attr); } if (column != null) { columns.Add(column); } } // 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); }
/// <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 override IList <OLVColumn> GenerateColumns(Type type, bool allProperties) { List <OLVColumn> columns = new List <OLVColumn>(); // Sanity if (type == null) { return(columns); } PropertyInfo[] pList = AttrHelper.GetBasePropertiesFirst(type); PropertyInfo pName = AttrHelper.GetProperty <JNameProperty>(type); if (pName != null) { pList = pList.OrderBy(x => x != pName).ToArray(); } // 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()) foreach (PropertyInfo pinfo in pList) { if (Attribute.GetCustomAttribute(pinfo, typeof(OLVIgnoreAttribute)) != null) { continue; } //added j if (Attribute.GetCustomAttribute(pinfo, typeof(JIgnore)) != null) { continue; } OLVColumnAttribute attr = Attribute.GetCustomAttribute(pinfo, typeof(OLVColumnAttribute)) as OLVColumnAttribute; OLVColumn column = null; if (attr == null) { if (allProperties) { column = this.MakeColumnFromPropertyInfo(pinfo); } } else { column = this.MakeColumnFromAttribute(pinfo, attr); } if (column != null) { //reset checkboxes (setted by ConfigurePossibleBooleanColumn()) for correct working of virtual lists column.CheckBoxes = false; columns.Add(column); } } // 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); }