Sw4   >   Windows   >   Field Handling
The StudioWorks field handling classes provides you with the following benefits:
A new field handler structure and classes was introduced in the 2008-03 release of StudioWorks. The new field handling structure and classes make it easier for StudioWorks developers to override and customize field handling. The field handler classes are located in the Field Handling folder of swGui4.
has a module with simple windows that demonstrate various aspects of the field handler. You can shift+click on buttons in the demo windows to look at the code behind the window and step through the field handler code.
The easiest way to control field handling is by setting the
under the section of the .The decorator types supported in StudioWorks are:
The decorator type values can each field are listed in the decoratortype column of the SQL lists columns list. You can get the columns list from a StudioWorks SQL defined list from the $:ColsList property method.
The FieldHandlersFactory_Task provides oFieldHandlerController with a $:TypesList. The list has 4 columns:
For example a clickedit decorator type would have the following values:
The field properties list is a list of all the fields in a window instance which the field handler could be involved with.
The field properties list is defined from sFieldHandlerProperties_listdef. It has the following columns:
A window class can include a field properties list with the $initialize message it sends to oFieldHandlerController. To improve performance oConcretizer builds and stores a field properties list in the $userinfo property of a runtimized window class when it creates it.
If the field properties list is not supplied, oFieldHandlerController builds a list on-the-fly by sending a $retFieldPropertiesList message to the oFieldHandlerPropertiesList object.
If the data list of a window is based on a query class that joins multiple tables any field which is not part of the base schema of the query class is automatically assigned a decoratortype as follows:
When oFieldHandlerController receives an $event message, is searches the field properties list for a matching objident, then based on the current mode, it sends a message to the appropriate field handler object.
You can change the decoratortype for any field, add new fields, or add complex grid exceptions to the field properties list, using the $addsetFieldDecoratorType method of oFieldHandlerController.
You can modify the field properties list by getting it from the field handler controller, modifying the list, and then setting it back to the controller.
See the section on for more details.The current mode affects which field handler object is called to handle a field's events. The handler_new, handler_edit, handler_view columns in the properties list specify which field handler object to use for the appropriate mode.
For a clickedit decorator type the handler_[mode] column values would be as follows:
Each time the mode is set in the window class, the window must send a $setMode(pMode) message to the oFieldHandlerController.
If the value of pMode is different than the controller's current mode, the controller sets its internal iMode state to the specified mode, and then loops through the field properties list sending a $setField message to the appropriate field handler specified in the handler_[iMode] column.
When an $event message is passed to oFieldHandlerController it searches for the current field in the field properties list, and then forwards the message to the field handler type specified in the appropriate handler_[iMode] column.
With the clickedit decorator type example above the oFieldHandlerController will send messages to the following field handlers for the specified modes:
The oFieldHandlerController delegates most of the field handling to field handler objects.
The field handler object naming syntax is: oFieldHandler_type
The following field handler objects can be found in swGui4.
The field handler objects delegate field decoration to field decorator objects.
The field decorator object naming syntax is: oFieldDecorator_type
The following field decorator objects can be found in swGui4.
Normally a field is decorated by setting its $fieldstyle property. There are a series of StudioWorks field styles which you must have in the #STYLES class of your library in order for field decoration to work. The StudioWorks field styles are:
You can use the StudioTips swGui4 to your library's #STYLES class.
utilities to copy the StudioWorks field styles fromComplex grids add a wrinkle to field decoration because you can not set the $fieldstyle for an individual cell. For complex grids we have to set each property separately to change the field decoration of each field. The StudioWorks field styles for complex grids are:
The FieldHandlersFactory_Task is a task class which is used to reduce memory use and improve performance. The StudioWorks field handling structure is based on the flyweight design pattern.
When oFieldHandlerController is initialized it checks for a task instance of the FieldHandlersFactory_Task. If found it uses the existing instance. If not found, it opens an instance.
The FieldHandlersFactory_Task finds and creates a single instance of each oFieldHandler_type object class and a single instance of each oFieldDecorator_type object class. Object reference datatypes are used to ensure that just one instance of each of these object classes is created. The object reference to each of these instances are stored in an iHandlersRow and an iDecoratorsRow in the FieldHandlersFactory_Task.
The handler and decorator type suffix is used for the row column name.
iHandlersRow would have columns named: click, displayonly, lookup, notes, notesdisplay
iDecoratorsRow would have columns named: click, displayonly, hasfocus, normal, notes
When oFieldHandlerController is initialized it gets these rows from the FieldHandlersFactory_Task by sending it a $:HandlersRow message and a $:DecoratorsRow message. Each column in the row has a pointer to the single instance of the respective handler or decorator. All instances of oFieldHandlerController point to the exact same instance of each handler and decorator.
Developers can create their own oFieldHandler_type and oFieldDecorator_type classes in their main library. Handlers and decorators found in the main library take priority over ones by the same name in swGui4. As long as your handler has the same methods and parameters at those found in swGui4 you are free to tweak your handler or decorator code to suit your application's needs.
One potential design flaw in the FieldHandlersFactory_Task is that a single task instance of the factory is used for all StudioWorks applications open under the same instance of Omnis Studio. When a second StudioWorks app is opened it finds and uses the existing task instance of the factory. If the second StudioWorks app has custom field handlers or decorators they will be ignored. The solution is to have each StudioWorks app open its own task instance of the factory. This is relatively easy to implement, but it uses more memory, and will likely never be an issue for 99% of StudioWorks developers.
If you add custom handlers or decorators you need to quit Omnis Studio and reopen it in order to destroy the factory task instance. Just closing and reopening the StudioWorks app won't destroy the factory task instance.
StudioWorks normally decorates fields by changing the $fieldstyle of the field to the appropriate type.
For a click field, the $fieldstyle is set to swFieldNoFocus_click, until the user clicks on the field as which time the $fieldstyle is set to swFieldFocus
Complex grids increase the complexity of field handling because you can not set the $fieldstyle for individual cells of a complex grid. To decorate a field in a cell of complex grid we must set each field property individually, and we must specify the row number in the complex grid for each property we set.
The oFieldHandler_type and oFieldDecorator_type series objects check if the specified field is inside a complex grid and if so, executes complex grid friendly handler and decorator code.
One advantage of the StudioWorks field handling structure is that lookups and notes decorator type fields automatically work in complex grids. This is a big benefit!
The field handler classes are located in the Field Handling folder of swGui4.
The oFieldHandlerController object is instantiated by the ivar ifld in the window instance. There will be one instance of oFieldHandlerController for each window (subwindow) instance.
When the window is instantiated the following sequence of events relating to field handling normally takes place:
Runtimized window have the field properties list stored in the $userinfo property of the runtimized window class.
Note: If you have an On evBefore in the field $event method, the event will not pass to the window's $control method. If you want StudioWorks field handling for the field you must either remove the On evBefore or end it with Quit event handler (Pass to next handler). The same goes for evAfter, evClick, and evKey. For evKey the field or library's $keyevents property must be set to kTrue.
Overriding field handling and decorating is relatively easy. Knowing the sequence of events, you can decide where to best intercept and modify the field handling.
; Set the OrderID field in row 2 of the complex grid to 'displayonly'
; (prField,pDecoratorType,pRowNum_opt)
Do ioFieldHandlerController.$addsetFieldDecoratorType($cinst.$objs.OrderID,'displayonly',2)
; Add a displayonly Status field.
; (prField,pDecoratorType,pRowNum_opt)
Do ioFieldHandlerController.$addsetFieldDecoratorType($cinst.$objs.Status,'displayonly')
; Get the field properties list and add a special 'approved' mode.
Do ioFieldHandlerController.$:FieldPropertiesList() Returns List
Do List.$cols.$add('handler_approved',kCharacter,kSimplechar,50)
; Set the handler to click for any displayonly fields.
Do List.$sendall($ref.handler_approved.$assign('click'),List.handler_edit='displayonly')
; Assign the modified field properties list back to the field handler controller.
Do ioFieldHandlerController.$:FieldPropertiesList.$assign(List)
You can also create additional field handlers and decorators. As long as you following the naming convention syntax for field handlers and decorators, the FieldHandlersFactory_Task will find and add them to the handlers row and the decorators row. If you get to this level of overriding StudioWorks field handling you will likely need to also take over the FieldHandlersFactory_Task. Ask questions via the StudioWorks members list if you get to this stage.
has a module with simple windows that demonstrate various aspects of the field handler. You can shift+click on windows in the demo to look at the code behind the window and step through the field handler code