How to: How to Extend the Application Model: Extensible Application Model

To demonstrate how to extend the Application Model, this topic details how to display a Group Footer for List Views. An IsGroupFooterVisible property will be added to the to the Views | <ListView> node. When set to true for a ListView, a special Controller will enable the group footer. To specify a summary type for different columns, a GroupFooterSummaryType property will be added to the ListView | Columns | Column node. For general information on extending the Application Model, refer to the Extend and Customize the Application Model in Code help topic.

To demonstrate how to extend the application model, this topic provides details about how to display the group footer list view. IsGroupFooter visible property is added to the view | <ListView> node. When listView set to true, the special controller will enable the group footer. To specify a different column summary type, is added to the ListView | row | column node. For general information about the extended application model, see the Help extension code and custom application model theme.

Note Note
Mobile applications do not support the Group Footer. However, you can implement the approach described in this topic to extend your Application Model for other purposes.
Mobile applications do not support the group footer. However, you can method described in this topic implementation, in order to extend the application model to be used for other purposes.

HowToExdendApplicationModel

Tip Tip
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E213
Complete sample project can be found in the code sample database DevExpress, http://www.devexpress.com/example=E213

.

  • Implement the interfaces exposing the IsGroupFooterVisible and GroupFooterSummaryType properties.

  • And implementing the disclosed interfaces group FooterSummaryType IsGroupFooter visible attributes.

    using DevExpress.Data;
    //...
    public interface IModelListViewExtender {
        bool IsGroupFooterVisible { get; set; }
    }
    public  interface IModelColumnExtender {
        [DefaultValue(SummaryItemType.None)]
        SummaryItemType GroupFooterSummaryType { get; set; }
    }

     

  • Override the ModuleBase.ExtendModelInterfaces method of your base Module to extend the Application Model with declared interfaces.

  • The method of covering the basic module Base.ExtendModelInterface module to extend the application model interface declaration.

    using DevExpress.ExpressApp.Model;
    // ...
    public sealed partial class ExtendModelModule : ModuleBase {
        // ...
        public override void ExtendModelInterfaces(ModelInterfaceExtenders extenders) {
            base.ExtendModelInterfaces(extenders);
            extenders.Add <IModelListView, IModelListViewExtender> ();
            extenders.Add <IModelColumn, IModelColumnExtender> ();
        }
    }

     

  • Create a WinGroupFooterViewControllerViewController in the Windows Forms Module. Inherit it from the ViewController<ListView> type, since this Controller must be activated in List Views only.
  • Override the protected OnViewControlsCreated method to display the group footer, if the IsGroupFooterVisible property is set to true for the current List View. Additionally, when the Controller is activated, handle the View.ModelSaved event to save the group footer summary type for different columns into Application Model, when the current List View is closing.

  • Creating WinGroupFooterView Controller View Controller in a Windows Forms module. From the "View Controller <ListView> type inheritance it, because the controller must be activated only in the list view.
  • If you view the current list of IsGroupFooterVisible property is set to true, then cover protected OnViewControls creation method to display the group footer. Further, when the controller is activated, the current list view when off, the process View.ModelSave event, to save the group footer Abstract Type different columns to the application model.

    using System;
    using System.ComponentModel;
    using DevExpress.Data;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Model;
    using DevExpress.ExpressApp.Win.Editors;
    using DevExpress.XtraGrid.Views.Grid;
    using DevExpress.XtraGrid.Columns;
    //...
    public class WinGroupFooterViewController : ViewController<ListView> {
        private void View_ModelSaved(object sender, EventArgs e) {
            IModelListViewExtender modelListView = View.Model as IModelListViewExtender;
            if (modelListView! = null && modelListView.IsGroupFooterVisible) {
                GridListEditor gridListEditor = View.Editor as GridListEditor;
                if(gridListEditor != null) {
                    GridView gridView = gridListEditor.GridView;
                    for(int i = 0; i < gridView.GroupSummary.Count; i++) {
                        IModelColumnExtender modelColumn = View.Model.Columns[
                            gridView.GroupSummary[i].FieldName] as IModelColumnExtender;
                        if(modelColumn != null) {
                            modelColumn.GroupFooterSummaryType = gridView.GroupSummary[i].SummaryType;
                        }
                    }
                }
            }
        }
        protected override void OnViewControlsCreated() {
            base.OnViewControlsCreated();
            IModelListViewExtender modelListView = View.Model as IModelListViewExtender;
            if (modelListView! = null && modelListView.IsGroupFooterVisible) {
                GridListEditor gridListEditor = View.Editor as GridListEditor;
                if(gridListEditor != null) {
                    GridView gridView = gridListEditor.GridView;
                    gridView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
                    foreach(IModelColumn modelColumn in View.Model.Columns) {
                        IModelColumnExtender modelColumnExtender = modelColumn as IModelColumnExtender;
                        if(modelColumnExtender != null && 
                            modelColumnExtender.GroupFooterSummaryType != SummaryItemType.None) {
                            GridColumn gridColumn = gridView.Columns[
                                modelColumn.ModelMember.MemberInfo.BindingName];
                            gridView.GroupSummary.Add(modelColumnExtender.GroupFooterSummaryType, 
                                modelColumn.Id, gridColumn);
                        }
                    }
                }
            }
        }
        protected override void OnActivated() {
            base.OnActivated();
            View.ModelSaved += View_ModelSaved;
        }
        protected override void OnDeactivated() {
            View.ModelSaved -= View_ModelSaved;
            base.OnDeactivated();
        }
    }

     

  • Create a WebGroupFooterViewController ViewController in the ASP.NET Web Module. Inherit it from the ViewController<ListView> type, since this Controller must be activated in List Views only.
  • Override the protected OnViewControlsCreated method to display the group footer, if the IsGroupFooterVisible property is set to true for the current List View. There is no need to handle the ModelSaved event since end-users cannot customize summary types for different columns in the ASP.NET UI.

  • Creating a Web group FooterView controller view controller in ASP.NET Web module. From the "View Controller <ListView> type inheritance it, because the controller must be activated only in the list view.
  • If you view the current list of IsGroupFooterVisible property is set to true, then cover protected OnViewControls creation method to display the group footer. Without treatment ModelSaved event, because the end user can not customize the summary type ASP.NET UI in different columns.

    using System;
    using DevExpress.Data;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Model;
    using DevExpress.ExpressApp.Web.Editors.ASPx;
    using DevExpress.Web.ASPxGridView;
    //...
    public class WebGroupFooterViewController : ViewController<ListView> {
        protected override void OnViewControlsCreated() {
            base.OnViewControlsCreated();
            IModelListViewExtender modelListView = View.Model as IModelListViewExtender;
            if (modelListView! = null && modelListView.IsGroupFooterVisible) {
                ASPxGridListEditor gridListEditor = View.Editor as ASPxGridListEditor;
                if(gridListEditor != null) {
                    ASPxGridView gridView = gridListEditor.Grid;
                    gridView.Settings.ShowGroupFooter = GridViewGroupFooterMode.VisibleAlways;
                    foreach(IModelColumn modelColumn in View.Model.Columns) {
                        IModelColumnExtender modelColumnExtender = modelColumn as IModelColumnExtender;
                        if(modelColumnExtender != null && 
                            modelColumnExtender.GroupFooterSummaryType != SummaryItemType.None) {
                            string fieldName = modelColumn.ModelMember.MemberInfo.BindingName;
                            ASPxSummaryItem summaryItem = null;
                            foreach(ASPxSummaryItem currentItem in gridView.GroupSummary) {
                                if(currentItem.FieldName == fieldName) {
                                    currentItem.ShowInGroupFooterColumn = modelColumn.Caption;
                                    summaryItem = currentItem;
                                    break;
                                }
                            }
                            if(summaryItem == null) {
                                summaryItem = new ASPxSummaryItem(
                                    fieldName, modelColumnExtender.GroupFooterSummaryType);
                                summaryItem.ShowInGroupFooterColumn = modelColumn.Caption;
                                gridView.GroupSummary.Add(summaryItem);
                            }
                        }
                    }
                }
            }
        }
    }

     

  • Rebuild you solution and invoke the Model Editor for the base Module. Set a ListView node's IsGroupPanelVisible property to true to be able to group the List View's columns. Set the newly added IsGroupFooterVisible property to true. Specify summary types for the ListView node's Column nodes.
  • Run the application. Display the List View with a group panel and group the List View by a column. The footer with the specified summary types will be displayed.
  • Rebuild Solution model editor and call the base module. The node IsGroupPanel ListView visible property set to true, to be able to be grouped columns list view. The newly added IsGroupFooter visible property is set to true. Abstract specify columns of type ListView node node.
  • Run the application. Using Group panel displays a list view, and then grouped by columns list view. It will be displayed with the specified type of summary footer.

Guess you like

Origin www.cnblogs.com/foreachlife/p/How-to-Extend-the-Application-Model.html