Objective Grid : PART II Programmer’s Guide : Chapter 21 Database Engine Architecture : Layout Manager
Layout Manager
The layout manager, CGXBrowserLayoutManager, is a utility class for the database engine grid. It encapsulates the logic for initializing the grid with a browser-like layout, so you can take advantage of browser-like editing behavior (Edit/Modify/Update). It also communicates with the DBEngine to fetch and store data. With this utility class, you can easily customize the browser-like layout and the browser-like editing behavior by subclassing and overriding the virtuals.
Browser-Like Layout
The grid styles and properties that the layout manager modifies fall into two categories: datasource-independent and datasource-dependent.
The datasource-independent properties include an arrow row header control that indicates the current row with the edit mode and the append row at the bottom that allows you to add new records.
There are other properties that are dependent on the datasource and the result set's schema, like the column name (based on the field name), column width (based on the field type), and the column base style (again based on the field type). The grid needs to determine certain styles for the column based on the corresponding field's data type.
Sometimes you may encounter proprietary, nonstandard data types with different data access APIs. Ideally, the DBEngine would convert the proprietary data types from different data access APIs to a predefined data type enumeration that the layout manager understands. However, our classes do not change proprietary data types to a predefined data type enumeration, because this conversion is inefficient, restrictive, and not easily scalable.
Instead, the layout manager delegates conversion to a function with a pre-defined signature through a member-function pointer that you can initialize during run-time. The signature for this function is defined as GXInitDBEGridFromEngine. Each implementation of CGXDBEngine needs to have an implementation of the GXInitDBEGridFromEngine function signature to avoid translating proprietary data-types inside the DBEngine and to keep the layout manager abstract so it can work with all data access APIs.
Browser-Like Editing
The layout manager supplies the data to be displayed in the grid cells on demand and stores any changes the user makes to the datasource via the DBEngine. It uses the DBEngine’s edit mode to cache the user’s changes in the current row. When the user moves to a new row, it asks the DBEngine to store the changes into the datasource by calling Update(). DBEngine handles adding recording in the same fashion.
Note that the grid has a reference to the DBEngine. It always uses the layout manager to fetch/store data from the engine so it can remain independent of the data access logic.
Hierarchical Browser Layout Manager
The CGXHierGridLayoutManager template derives from the CGXBrowserLayoutManager template and implements the logic involved in initializing a CGXRegularGrid-type hierarchical grid.
It handles binding the child grids to the appropriate child engine by querying for it from the parent’s engine.
Use this kind of layout manager in conjunction with a hierarchical DBEGrid.