Uniface 9: Search profile tool for forms
In Uniface, the default method to enter search profile and then get the resulting list is to first create an occurrence, enter search criteria, and then retrieve from the (current) working occurrence.
While this's an handy method, it could be improved to automagically manage the three situations (modes) :
* Default: empty entity, we want to enter search profile criteria
* List: we retrieved occurrences, no profile occurrence shown
* Retrieve: we have retrieved occurrences, we want to make another search, we have an additional profile occurrence

Default profile mode
Then you enter your criteria (or let the profile blank), and retrieve :

List mode
Note that the profile occurrence (the yellow one) disappeared, and the dropdownlist widget for the component type gone to a simple editbox. The occurrences are marked not editable too.
Now, if you want to make another search, just insert a new occurrence :

Retrieve profile mode
As the goal is to have a read-only list, a new occurrence makes a profile occurrence (trying to make another one will bring a message saying to use the existing profile row). Of course, fields are editables. When retrieving, we go back in the list mode (the second one).
Then, in the Defines trigger, declare constants needed by the tool. Two of them are mandatory :
* PROFILE_ENTITY : the entity to work on
* PROFILE_VARIABLE : either a field or a component variable which will hold the current profile state
* PROFILE_COLOR (optionnal) : an indexed color used for the profile row color (default is 6)
In the Execute trigger, initialize it (this simply set the profile color) :
In the Retrieve trigger, call the function which will retrieve data and update the profile :
The same for the Clear trigger :
Install a hook in the Quit trigger to be able to remove the profile row from the Escape key :
Now in the working entity (here, UFORM. We don't want to add occurrence, but if we want to enable the profile row from it, we must code it. A return value different than zero from profileAddInsOcc() indicates that the Add/Insert Occurrence wasn't needed :
The Read is a little bit special, because we want to :
* change the dropdownlist to a simple editbox
* update the picture associated with the component type
* disable occurrence editing
Finally, in the Occurrence Gets Focus, we call another entry to update the profile row if needed, but we do it only if we changed the current row :
The whole example is provided in the following export, from Uniface 9.4.0.1 (sorry I don't have a 8.4 installation anymore). It contains the include proc TOOLS:PROFILE and the form FTESTPROFILE. Note that you must have the DICT model available in your repository.
Download: http://www.udev.info/stuff/search_profile_tool/search_profile_tool.xml
While this's an handy method, it could be improved to automagically manage the three situations (modes) :
* Default: empty entity, we want to enter search profile criteria
* List: we retrieved occurrences, no profile occurrence shown
* Retrieve: we have retrieved occurrences, we want to make another search, we have an additional profile occurrence
Presentation
The following screen-shots show a simple use case with the UFORM entity shown as a grid. We start in default profile mode (empty entity, profile occurrence available) :
Default profile mode
Then you enter your criteria (or let the profile blank), and retrieve :

List mode
Note that the profile occurrence (the yellow one) disappeared, and the dropdownlist widget for the component type gone to a simple editbox. The occurrences are marked not editable too.
Now, if you want to make another search, just insert a new occurrence :

Retrieve profile mode
As the goal is to have a read-only list, a new occurrence makes a profile occurrence (trying to make another one will bring a message saying to use the existing profile row). Of course, fields are editables. When retrieving, we go back in the list mode (the second one).
So what?
All seasoned Uniface developer can to such a design pattern. The whole point is that it's painful, so a bit of genericity would be welcome. This is where included proc can give a great help. By defining well designed entries to be included in your Local Proc Modules, you can transform a form into a profile enabled one.How to use it?
Load the tool from the include proc in the Local Proc Modules :Local Proc Modules SOURCE CODE
Sorry- ... please log-in or register to get this!
Then, in the Defines trigger, declare constants needed by the tool. Two of them are mandatory :
* PROFILE_ENTITY : the entity to work on
* PROFILE_VARIABLE : either a field or a component variable which will hold the current profile state
* PROFILE_COLOR (optionnal) : an indexed color used for the profile row color (default is 6)
Defines SOURCE CODE
Sorry- ... please log-in or register to get this!
In the Execute trigger, initialize it (this simply set the profile color) :
Execute SOURCE CODE
Sorry- ... please log-in or register to get this!
In the Retrieve trigger, call the function which will retrieve data and update the profile :
Retrieve SOURCE CODE
Sorry- ... please log-in or register to get this!
The same for the Clear trigger :
Clear SOURCE CODE
Sorry- ... please log-in or register to get this!
Install a hook in the Quit trigger to be able to remove the profile row from the Escape key :
Quit SOURCE CODE
Sorry- ... please log-in or register to get this!
Now in the working entity (here, UFORM. We don't want to add occurrence, but if we want to enable the profile row from it, we must code it. A return value different than zero from profileAddInsOcc() indicates that the Add/Insert Occurrence wasn't needed :
Add/Insert Occurrence SOURCE CODE
Sorry- ... please log-in or register to get this!
The Read is a little bit special, because we want to :
* change the dropdownlist to a simple editbox
* update the picture associated with the component type
* disable occurrence editing
UFORM Read SOURCE CODE
Sorry- ... please log-in or register to get this!
Finally, in the Occurrence Gets Focus, we call another entry to update the profile row if needed, but we do it only if we changed the current row :
UFORM Occurrence Gets Focus SOURCE CODE
Sorry- ... please log-in or register to get this!
The whole example is provided in the following export, from Uniface 9.4.0.1 (sorry I don't have a 8.4 installation anymore). It contains the include proc TOOLS:PROFILE and the form FTESTPROFILE. Note that you must have the DICT model available in your repository.
Download: http://www.udev.info/stuff/search_profile_tool/search_profile_tool.xml
Comments