Release 10.1A: OpenEdge Development:
Progress Dynamics Advanced Development

> ## Accessing the manager from viewers

> In order for viewers to display a visual cue for required fields, you must override the standard viewer behavior with a`customviewer.p` procedure. As for the `data` class, edit `src/adm2/custom/customviewer.i` to start the super procedure`adm2/custom/viewercustom.p`. Then create a local version of `src/adm2/custom/viewercustom.p` and define an `enableFields` procedure in it. Invoke the standard behavior with a `RUN SUPER` statement, and then retrieve the Field Edit Manager handle, as shown:

>     Procedure enableFields:
>     /*-------------------------------------------------------------------------
>       Purpose:     Override of enableFields to apply affordance for field edits
>                    defined in the entity field edit table.
>       Parameters:  <none>
>       Notes:
>     -------------------------------------------------------------------------*/
>     DEFINE VARIABLE cEditValue        AS CHARACTER  NO-UNDO.
>     DEFINE VARIABLE cFieldHandles     AS CHARACTER  NO-UNDO.
>     DEFINE VARIABLE cTable            AS CHARACTER  NO-UNDO.
>     DEFINE VARIABLE hDataSource       AS HANDLE     NO-UNDO.
>     DEFINE VARIABLE hField            AS HANDLE     NO-UNDO.
>     DEFINE VARIABLE hFieldEditManager AS HANDLE     NO-UNDO.
>     DEFINE VARIABLE hSideLabel        AS HANDLE     NO-UNDO.
>     DEFINE VARIABLE iNumField         AS INTEGER    NO-UNDO.
>       RUN SUPER.
>       hFieldEditManager= DYNAMIC-FUNCTION('getManagerHandle':U IN
>     gshSessionManager,
>                                            INPUT 'FieldEditManager':U).

> Now you must get the `DataSource` handle (the viewer’s SDO), which you use to identify the `columnTable` property for each of the viewer’s fields. This is the database table the column is derived from, and becomes one of the arguments to `getFieldEditData`.

> You also must retrieve the `FieldHandles` property of the viewer. This is a list of the widget handles for the field representations in the viewer.

> For each of the fields, run `getFieldEditData` in the manager to see if there is a `Required` edit for the field, as shown:

>      hDataSource = DYNAMIC-FUNCTION('getDataSource':U IN TARGET-PROCEDURE).
>       cFieldHandles = DYNAMIC-FUNCTION('getFieldHandles':U IN TARGET-PROCEDURE).
>       DO iNumField = 1 TO NUM-ENTRIES(cFieldHandles):
>         hField = WIDGET-HANDLE(ENTRY(iNumField, cFieldHandles)).
>         cTable = DYNAMIC-FUNCTION('columnTable':U IN hDataSource,
>                                   INPUT hField:NAME).
>         IF VALID-HANDLE(hFieldEditManager) THEN
>         DO:
>           RUN getFieldEditData IN hFieldEditManager
>               (INPUT cTable,
>                INPUT hField:NAME,
>                INPUT 'Required':U,
>                OUTPUT cEditValue).

> If there is a `Required` edit, then you modify the side label for the field to begin with an asterisk, as shown:

>      IF cEditValue = 'yes':U THEN
>           DO:
>             ASSIGN
>               hSideLabel = hField:SIDE-LABEL-HANDLE
>               hSideLabel:SCREEN-VALUE = '* ':U + hSideLabel:SCREEN-VALUE NO-ERROR.
>           END.  /* if required is "yes" */
>         END.  /* if field edit manager valid */
>       END.  /* do to number of data fields in viewer */
>     END PROCEDURE.

> Save and compile the `viewercustom.p` procedure.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095