public static BaseEditController GetEditController(PropertyDescriptor propertyDescriptor) { BaseEditController editController = null; var editorType = EditorPublic.GetEditorTypeByReflection(propertyDescriptor); if (editorType == null) { editController = GetEditController(propertyDescriptor.PropertyType); } else { editController = editorType.CreateInstance() as BaseEditController; EditorPublic.SetEditControllerToStorage(propertyDescriptor.PropertyType, editController); } return(editController); }
/// 通用获取或创建编辑器步骤:(BaseObjectEditController中) /// 1. 从BaseObjectEditController中的PredefinedEditors属性中获取编辑控制器; /// 2. 通过类或属性的EditorTypeAttribute获取编辑控制器类型; /// 3. 根据类型获取默认的编辑控制器; /// 4. 从客户端存储中获取编辑控制器的配置; /// 5. 创建编辑器; /// /// 指定数据类型获取编辑器的步骤: /// 1. 通过类或属性的EditorTypeAttribute获取编辑控制器类型; /// 2. 根据类型获取默认的编辑控制器; /// 3. 从客户端存储中获取编辑控制器的配置; /// 4. 创建编辑器; /// /// 指定编辑器类型创建编辑器的步骤: /// 1. 从客户端存储中获取编辑控制器的配置; /// 3. 创建编辑器; public static BaseEditController GetEditController(Type objectType) { BaseEditController editController = null; var editorType = EditorPublic.GetEditorTypeByReflection(objectType); if (editorType == null) { editorType = GetDefaultEditorType(objectType); } if (editorType == null) { return(null); } editController = EditorPublic.GetEditControllerFromStorage(objectType, editorType); if (editController == null) { editController = editorType.CreateInstance() as BaseEditController; EditorPublic.SetEditControllerToStorage(objectType, editController); } return(editController); }
/// <summary> /// 根据对象填充属性字段 /// </summary> /// <param name="groupItem">组项目</param> /// <param name="objType">对象类型</param> private void RetrieveFields(LayoutControlGroup groupItem, Type objType) { UIPublic.ShowWaitingForm(); this.DataLayoutControl.CloseControl(); EditControls.Clear(); this.DataLayoutControl.Clear(true, true); var controller = Controller as ObjectLayoutEditController; if (objType == null) { return; } this.DataLayoutControl.SuspendLayout(); TabbedControlGroup tabbledGroup = null; foreach (PropertyDescriptor propDesc in TypeDescriptor.GetProperties(objType)) { if (!propDesc.IsBrowsable) { continue; } BaseEditController editController = null; Control editControl = null; if (controller != null) { editController = controller.GetPredefinedEditController(propDesc.PropertyType, propDesc.Name); } if (editController == null) { if (propDesc.PropertyType.IsAddon()) { var commonEditController = new CommonObjectEditController(); commonEditController.StartEditProperty(EditValue, propDesc.Name); editController = commonEditController; } else { editController = EditorPublic.GetEditController(propDesc); } } editControl = editController.CreateEditControl(propDesc.PropertyType); if (editControl.GetType().GetProperty("EditValue") == null) { throw new Exception("编辑控件必须实现EditValue属性"); } LayoutControlItem layoutControlItem = null; if (editControl is BaseObjectEditControl) { if (tabbledGroup == null) { tabbledGroup = groupItem.AddTabbedGroup(); } var layoutGroupItem = tabbledGroup.AddTabPage(); layoutGroupItem.Name = "Group_" + propDesc.Name; layoutGroupItem.Text = propDesc.DisplayName; layoutGroupItem.CustomizationFormText = "组_" + propDesc.DisplayName; layoutGroupItem.Padding = new DevExpress.XtraLayout.Utils.Padding(0); layoutControlItem = layoutGroupItem.AddItem(); layoutControlItem.TextLocation = DevExpress.Utils.Locations.Top; } else { layoutControlItem = groupItem.AddItem(); layoutControlItem.TextLocation = DevExpress.Utils.Locations.Left; } EditControls.Add(propDesc, editControl); editControl.Tag = propDesc; editControl.Name = propDesc.Name; layoutControlItem.Control = editControl; layoutControlItem.Name = propDesc.Name; layoutControlItem.Text = propDesc.DisplayName; layoutControlItem.CustomizationFormText = propDesc.DisplayName; if (editControl is BaseObjectEditControl) { layoutControlItem.TextVisible = false; } else { layoutControlItem.TextVisible = true; } } this.DataLayoutControl.ResumeLayout(); this.DataLayoutControl.SetDefaultLayout(); // 读取布局数据 if (controller != null && controller.LayoutData.IsNotNullOrEmpty()) { this.DataLayoutControl.SetLayoutData(controller.LayoutData); } UIPublic.CloseWaitingForm(); }
/// <summary> /// 设置默认编辑控制器到客户端存储 /// </summary> /// <param name="objectType">对象类型</param> /// <param name="editController">默认编辑控制器</param> public static void SetEditControllerToStorage(Type objectType, BaseEditController editController) { string editorID = GetEditorID(editController.GetType(), objectType); ConfigStoragePublic.SetConfig(EditorsStorageName, editorID, editController); }