PageRenderTime 2732ms CodeModel.GetById 60ms RepoModel.GetById 11ms app.codeStats 0ms

/Xpand/Xpand.ExpressApp/Xpand.ExpressApp.Win/ListEditors/GridListEditors/ColumnView/Model/Synchronizers.cs

https://github.com/akingunes/eXpand
C# | 223 lines | 63 code | 15 blank | 145 comment | 8 complexity | 5cce5f1605d0730dc6176d031c80958b MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using DevExpress.ExpressApp.Editors;
  8. using DevExpress.ExpressApp.Model;
  9. using DevExpress.ExpressApp.SystemModule;
  10. using DevExpress.ExpressApp.Win.Editors;
  11. using DevExpress.ExpressApp.Win.SystemModule;
  12. using DevExpress.Utils;
  13. using DevExpress.XtraEditors.Filtering;
  14. using DevExpress.XtraGrid.Columns;
  15. using DevExpress.XtraGrid.Views.Base;
  16. using Fasterflect;
  17. using Xpand.ExpressApp.Win.ListEditors.GridListEditors.ColumnView.Design;
  18. using Xpand.ExpressApp.Win.ListEditors.GridListEditors.GridView;
  19. using Xpand.Persistent.Base.General.Model.Options;
  20. using Xpand.Persistent.Base.ModelAdapter;
  21. namespace Xpand.ExpressApp.Win.ListEditors.GridListEditors.ColumnView.Model {
  22. // public abstract class ColumnViewEditorLayoutStoreSynchronizer : DevExpress.ExpressApp.Model.ModelSynchronizer<WinColumnsListEditor, IModelLayoutDesignStore> {
  23. // protected ColumnViewEditorLayoutStoreSynchronizer(WinColumnsListEditor control, IModelLayoutDesignStore modelNode)
  24. // : base(control, modelNode) {
  25. // }
  26. // protected override void ApplyModelCore() {
  27. // if (Model.NodeEnabled || (Control is IColumnViewEditor && ((IColumnViewEditor)Control).OverrideViewDesignMode)) {
  28. // ApplyModelFromLayoutStore(Control.Grid.MainView);
  29. // }
  30. // }
  31. //
  32. // public override void SynchronizeModel(){
  33. // var editor = Control as IColumnViewEditor;
  34. // if (editor != null && (editor.OverrideViewDesignMode||SynchronizeModelCore()))
  35. // SaveToLayoutStore(Control.Grid.MainView);
  36. // }
  37. //
  38. // protected virtual bool SynchronizeModelCore() {
  39. // return false;
  40. // }
  41. //
  42. // OptionsLayoutGrid GetOptionsLayoutGrid() {
  43. // var optionsLayoutGrid = new OptionsLayoutGrid();
  44. //
  45. // optionsLayoutGrid.Columns.StoreLayout = true;
  46. // optionsLayoutGrid.Columns.StoreAppearance = true;
  47. // optionsLayoutGrid.Columns.RemoveOldColumns = false;
  48. // optionsLayoutGrid.Columns.AddNewColumns = false;
  49. //
  50. // optionsLayoutGrid.StoreVisualOptions = true;
  51. // optionsLayoutGrid.StoreDataSettings = false;
  52. // optionsLayoutGrid.StoreAppearance = true;
  53. //
  54. // optionsLayoutGrid.StoreAllOptions = true;
  55. // return optionsLayoutGrid;
  56. // }
  57. // void SaveToLayoutStore(BaseView baseView) {
  58. // using (var saveStream = new MemoryStream()) {
  59. // baseView.SaveLayoutToStream(saveStream, GetOptionsLayoutGrid());
  60. // Model.LayoutStore = Encoding.UTF8.GetString(saveStream.ToArray());
  61. // }
  62. // }
  63. // void ApplyModelFromLayoutStore(BaseView gridView) {
  64. // var optionsLayoutGrid = GetOptionsLayoutGrid();
  65. // if (!string.IsNullOrEmpty(Model.LayoutStore)) {
  66. // using (var restoreStream = new MemoryStream(Encoding.UTF8.GetBytes(Model.LayoutStore))) {
  67. // gridView.RestoreLayoutFromStream(restoreStream, optionsLayoutGrid);
  68. // }
  69. // }
  70. // }
  71. //
  72. // }
  73. // public abstract class ColumnViewEditorColumnOptionsSynchronizer<TComponent, TModelListViewOptionsColumnView, TModelColumn> : Persistent.Base.ModelAdapter.ModelSynchronizer<TComponent, TModelListViewOptionsColumnView>
  74. // where TModelListViewOptionsColumnView : IModelListViewOptionsColumnView
  75. // where TModelColumn : IModelColumnOptionsColumnView {
  76. // protected ColumnViewEditorColumnOptionsSynchronizer(TComponent control, TModelListViewOptionsColumnView modelNode)
  77. // : base(control, modelNode) {
  78. // }
  79. // protected override void ApplyModelCore() {
  80. // var gridColumnCollection = GetColumnView().Columns;
  81. // foreach (var modelColumn in Model.Columns.OfType<TModelColumn>()) {
  82. // var layoutViewColumn = gridColumnCollection[GetPropertyName(modelColumn)];
  83. // var columnOptions = GetColumnOptions(modelColumn);
  84. // if (columnOptions.NodeEnabled)
  85. // ApplyModel(columnOptions, layoutViewColumn, ApplyValues);
  86. // }
  87. // }
  88. //
  89. // string GetPropertyName(TModelColumn modelColumn) {
  90. // var propertyName = modelColumn.PropertyName;
  91. // if (modelColumn.ModelMember != null && modelColumn.ModelMember.MemberInfo.MemberTypeInfo.IsDomainComponent) {
  92. // propertyName += "!";
  93. // }
  94. // return propertyName;
  95. // }
  96. //
  97. // protected abstract DevExpress.XtraGrid.Views.Base.ColumnView GetColumnView();
  98. //
  99. // protected abstract IModelColumnViewColumnOptions GetColumnOptions(TModelColumn modelColumnOptionsView);
  100. //
  101. // public override void SynchronizeModel() {
  102. // var gridColumnCollection = GetColumnView().Columns;
  103. // foreach (var column in gridColumnCollection.ToList()) {
  104. // var propertyName = column.PropertyName();
  105. // if (Model.Columns[propertyName] is TModelColumn) {
  106. // var modelColumn = (TModelColumn)Model.Columns[propertyName];
  107. // var columnOptions = GetColumnOptions(modelColumn);
  108. // if (columnOptions.NodeEnabled)
  109. // ApplyModel(columnOptions, column, SynchronizeValues);
  110. // }
  111. // }
  112. // }
  113. //
  114. //
  115. // }
  116. // public abstract class GridViewModelSynchronizer : DevExpress.ExpressApp.Model.ModelSynchronizer<DevExpress.XtraGrid.Views.Grid.GridView, IModelListView> {
  117. // private readonly ColumnsListEditor _columnsListEditor;
  118. //
  119. //
  120. // protected GridViewModelSynchronizer(GridListEditor columnViewEditor)
  121. // : base(columnViewEditor.GridView, columnViewEditor.Model) {
  122. // _columnsListEditor = columnViewEditor;
  123. // _columnsListEditor.ControlsCreated += ColumnsListEditorControlsCreated;
  124. // }
  125. // private void ColumnsListEditorControlsCreated(object sender, EventArgs e) {
  126. // Control.OptionsView.ShowFooter = Model.IsFooterVisible;
  127. // Control.OptionsView.ShowGroupPanel = Model.IsGroupPanelVisible;
  128. // Control.OptionsBehavior.AutoExpandAllGroups = Model.AutoExpandAllGroups;
  129. // }
  130. // protected override void ApplyModelCore() {
  131. // Control.OptionsBehavior.AutoExpandAllGroups = Model.AutoExpandAllGroups;
  132. // Control.OptionsView.ShowGroupPanel = Model.IsGroupPanelVisible;
  133. //
  134. // var modelListViewShowAutoFilterRow = Model as IModelListViewShowAutoFilterRow;
  135. // if (modelListViewShowAutoFilterRow != null) {
  136. // Control.OptionsView.ShowAutoFilterRow = (modelListViewShowAutoFilterRow).ShowAutoFilterRow;
  137. // }
  138. // var modelListViewShowFindPanel = Model as IModelListViewShowFindPanel;
  139. // if (modelListViewShowFindPanel != null) {
  140. // if ((modelListViewShowFindPanel).ShowFindPanel) {
  141. // Control.ShowFindPanel();
  142. // }
  143. // else {
  144. // Control.HideFindPanel();
  145. // }
  146. // }
  147. // }
  148. // public override void SynchronizeModel() {
  149. // Model.AutoExpandAllGroups = Control.OptionsBehavior.AutoExpandAllGroups;
  150. // Model.IsGroupPanelVisible = Control.OptionsView.ShowGroupPanel;
  151. // var modelListViewShowAutoFilterRow = Model as IModelListViewShowAutoFilterRow;
  152. // if (modelListViewShowAutoFilterRow != null) {
  153. // (modelListViewShowAutoFilterRow).ShowAutoFilterRow = Control.OptionsView.ShowAutoFilterRow;
  154. // }
  155. // var modelListViewShowFindPanel = Model as IModelListViewShowFindPanel;
  156. // if (modelListViewShowFindPanel != null) {
  157. // (modelListViewShowFindPanel).ShowFindPanel = Control.IsFindPanelVisible;
  158. // }
  159. // }
  160. // public override void Dispose() {
  161. // base.Dispose();
  162. // if (_columnsListEditor != null) {
  163. // _columnsListEditor.ControlsCreated -= ColumnsListEditorControlsCreated;
  164. // }
  165. // }
  166. // }
  167. public class ListEditorModelSynchronizer : ModelListSynchronizer {
  168. public ListEditorModelSynchronizer(WinColumnsListEditor columnViewEditor, IEnumerable<IModelSynchronizable> modelSynchronizers)
  169. : this(columnViewEditor) {
  170. ModelSynchronizerList.AddRange(modelSynchronizers);
  171. }
  172. public ListEditorModelSynchronizer(WinColumnsListEditor columnViewEditor)
  173. : base(columnViewEditor, columnViewEditor.Model) {
  174. ((WinColumnsListEditor)Control).ColumnView.ColumnPositionChanged += Control_Changed;
  175. }
  176. public override void Dispose() {
  177. base.Dispose();
  178. var gridListEditor = Control as WinColumnsListEditor;
  179. if (gridListEditor != null && gridListEditor.ColumnView != null) {
  180. gridListEditor.ColumnView.ColumnPositionChanged -= Control_Changed;
  181. }
  182. }
  183. }
  184. public static class ColumnViewExtennsions {
  185. public static GridColumn Column(this ColumnWrapper columnWrapper) {
  186. return columnWrapper.GetPropertyValue("Column") as GridColumn;
  187. }
  188. public static Form CreateFilterBuilderDialogEx(this DevExpress.XtraGrid.Views.Base.ColumnView columnView, FilterColumnCollection filterColumns, FilterColumn defaultFilterColumn, IEnumerable<IModelMember> modelMembers) {
  189. return new XpandFilterBuilder(filterColumns, columnView.GridControl.MenuManager, columnView.GridControl.LookAndFeel, columnView, defaultFilterColumn, modelMembers);
  190. }
  191. public static string PropertyName(this GridColumn column) {
  192. IGridColumnModelSynchronizer columnInfo = GetGridColumnInfo(column);
  193. return columnInfo != null ? columnInfo.PropertyName : column.FieldName;
  194. }
  195. private static IGridColumnModelSynchronizer GetGridColumnInfo(GridColumn column) {
  196. return column != null && column.View is IModelSynchronizersHolder
  197. ? ((IModelSynchronizersHolder)column.View).GetSynchronizer(column) as IGridColumnModelSynchronizer
  198. : null;
  199. }
  200. public static IModelColumn GetModel(this GridColumn gridColumn) {
  201. var columnInfo = GetGridColumnInfo(gridColumn);
  202. return columnInfo != null ? columnInfo.Model : null;
  203. }
  204. public static IModelColumn Model(this GridColumn gridColumn) {
  205. return gridColumn.GetModel();
  206. }
  207. }
  208. }