« Back to AAU Project

Defining enumeration domain values dynamically

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Is it possible to define enumeration domain values dynamically in AdoScript code
(e.g. by reading them from some external source)?

e.g. for the following ALL fragment:

ATTRIBUTE <Content Relation Type> TYPE ENUMERATION
        FACET <EnumerationDomain> VALUE "Is related to@Is a version of@Categorizes@Classifies based on attribute"

I would like to define the <EnumerationDomain> value outside of the ALL file (as currently changing these values requires
rebuilding and redeploying the library, which is not convenient in some cases).

Having this possible could also allow me to make this set user-expandable (through asking for additional domain values
via e.g. AttrRep controls, saving them into some external media, and make the enumeration reflect these changes from that
time on).

Generically, as these values are defined in the facet, I tried to find any references to changing facet values from AdoScript in
the documentation but was not able to find anything.

RE: Defining enumeration domain values dynamically
Answer
12/17/14 1:43 PM as a reply to Vladimir Shekhovtsov.
Dynamic enumeration values can be achieved by extending the base types of attribute domain with a script-based solution. Please find below an implementaiton example for such a solution where the possible values for an attribute are read from a file residing within the ADOxx database, but potentially also anywhere on the file system, written during initialisation, or on a file share.

Select from list and store in STRING attribute
 1# 1. Store information of current object
 2SET nCurrentObjID: (objid)
 3# 2. Read enumeration list from file
 4CC "AdoScript" FREAD file: ("db:\\carTypes.txt")
 5SET sEnumerationValues: (text)
 6# 3. Open List and pre-select
 7CC "Core" GET_ATTR_VAL objid: (nCurrentObjID) attrname:"Type"
 8SET sCurrentSelection: (val)
 9CC "AdoScript" LISTBOX entries: (sEnumerationValues) toksep:";" title:"Select car type" oktext:"Apply" boxtext:"Choose car type:" selection: (sCurrentSelection)
10IF (endbutton = "ok")
11{
12   CC "Core" SET_ATTR_VAL objid: (nCurrentObjID) attrname:"Type" val: (selection)
13}

It is also possible to have the update of the list included in the tool, see the following snipplet as a reference how to handle add and remove functions via the menu

Add enumeration value:

 1# 1. Read enumeration list from file
 2CC "AdoScript" FREAD file: ("db:\\carTypes.txt")
 3SET sEnumerationValues: (text)
 4# 2. Display editfield
 5CC "AdoScript" EDITFIELD title:"Enter new car type" caption:"Car type:"
 6IF (ecode = 0)
 7{
 8   # 3. store the result of tokunion -> dublicates are excluded and ignored
 9   CC "AdoScript" FWRITE file: ("db:\\carTypes.txt") text: (tokunion(sEnumerationValues, text, ";"))
10}

Remove values from enumeration list (does not check for used values in models, could be done using AQL)
 1# 1. Read enumeration list from file
 2CC "AdoScript" FREAD file: ("db:\\carTypes.txt")
 3SET sEnumerationValues: (text)
 4# 2. Display in multiselect box
 5CC "AdoScript" MLISTBOX entries: (sEnumerationValues) toksep:";" title:"Select car type" oktext:"Apply" boxtext:"Choose car type:" selection: (sCurrentSelection)
 6IF (endbutton = "ok")
 7{
 8   # 3. save the diff between the initial set and those selected for removal
 9   CC "AdoScript" FWRITE file: ("db:\\carTypes.txt") text: (tokdiff(sEnumerationValues, selection, ";"))
10}

The integration implementation is available in the attached ABL file.

WebService Solution
A more complex solution is available in the following thread: http://www.adoxx.org/live/faq/-/message_boards/message/87053. This implementation reads from a web-service to retrieve the enumeration values.
Attachment

Attachments: Dynamic Enumeration Domain Library.abl (11.7k), ScreenSolution.jpg (15.6k)