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; } }
private void ListView_CellEditStarting(object sender, CellEditEventArgs e) { try { OLVColumn column = e.Column; object rowObject = e.RowObject; //object value = e.Value; JReadOnly readOnlyAttr = AttrHelper.GetAttribute <JReadOnly>(SourceObjectType, column.AspectName); if (readOnlyAttr != null) { DialogResult res = MessageBox.Show(null, FrwCRUDRes.This_field_is_readonly, FrwCRUDRes.WARNING, MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; return; } if (AppManager.Instance.IsCustomEditProperty(SourceObjectType, column.AspectName)) { /* This code was needed to provide a call for heavy dialogue (HTML editing) from a list cell. So far, we manage without him. * if (AttrHelper.GetAttribute<JText>(SourceObjectType, column.AspectName) != null) * { * // it is necessary to use a complex scheme, otherwise it cycles through the MouseUp event * Button b = new Button(); * b.Image = Properties.Resources.book_open; * b.Bounds = e.CellBounds; * b.Font = ((ObjectListView)sender).Font; * b.Click += (s1, e1) => * { * bool complated = false; * e.NewValue = AppManager.Instance.ProcessEditCustomPropertyValueAndSave(rowObject, column.AspectName, out complated, this); * if (complated) * { * RefreshObject(rowObject); * b.Text = e.NewValue as string; * } * else * { * RefreshObject(rowObject); * //it is necessary to use even if not complated * b.Text = e.NewValue as string; * } * b.Dispose(); * }; * e.Control = b; * e.Cancel = false; * } * else * {*/ bool complated = false; e.NewValue = AppManager.Instance.ProcessEditCustomPropertyValueAndSave(rowObject, column.AspectName, out complated, this); if (complated) { RefreshObject(rowObject); } e.Cancel = true; //} } else { e.Cancel = false; } } catch (Exception ex) { Log.ShowError(ex); e.Cancel = true; } }