SAS/AF Filtered SCL List
This class was developed to allow sophisticated filtering of listing models such as the Data Set List Model. As such, it can provide filtering on any model that supports the StaticStringList Interface (see sashelp.classes.staticstringlist.intrface)
The class functions as an intermediary between a model and a view, and thus, is a model to a viewer and a (non-visual) viewer of a model. The StaticStringList interface is both supported and required.
This class can be used in a SAS/AF frame by compiling the class definition and implementation and adding the class to the Components tab. To instantiate the class during build, drag the class from the components tab and drop it into a frame. Set a viewer's model attribute to the filteredlist and the filteredlist's model to the model that is being filtered for the viewer.
The class contains these attributes:
Data: itemsMatch - a SAS regular expression pattern. Only the source list items matching this pattern will be forwarded.
The itemsMatch attribute would typically be linked to a TextEntry.text attribute where the user can type in a pattern.
Installation
This class is designed to be installed as common.utility.filteredlist_c.class
Class definition
This scl code defines the class. Be sure to SAVECLASS it (don't need to compile it since there are no method implementations in the class
definition.)
Note that the class both supports and requires the StaticStringList Interface. In order to support StaticStringList a
class must implement four methods: _getItem(), getIndex(), _getItems(), _count()
common.utility.filteredlist_cclass.scl
Class COMMON.UTILITY.FILTEREDLIST_C.CLASS Extends SASHELP.FSP.OBJECT Supports SASHELP.CLASSES.STATICSTRINGLIST.INTRFACE Requires SASHELP.CLASSES.STATICSTRINGLIST.INTRFACE / ( Description="Filtered List") ; /*--------------------------*/ /* Attributes: */ /*--------------------------*/ Public Char description / (State="O", InitialValue="Filtered List") ; Public Char itemsMatch / (SetCAM="setcamItemsMatch", Category="Data", Description="Regular expression items must match to pass through") ; Public List items / (Editor="sashelp.classes.SimpleListEditor.frame", Category="Data") ; Public Char contentsUpdatedAttributes / (State="O", InitialValue="triggerViewerUpdate") ; Public Num triggerViewerUpdate / (InitialValue=0, Category="Model/View") ; /*--------------------------*/ /* Methods: */ /*--------------------------*/ _getItem: Public Method index:Input:Num Return=Char / (SCL="common.utility.filteredlist_c.scl", Label="getItem", ArgDesc1="specifies the index number of the item to retrieve on the items list", ReturnDesc="returns the text of the specified list item index") ; _getIndex: Public Method text:Input:Char Return=Num / (SCL="common.utility.filteredlist_c.scl", Label="getIndex", ArgDesc1="specifies the text to search for on the items list", ReturnDesc="returns the index number of the specified text if found") ; _getItems: Public Method Return=List / (SCL="common.utility.filteredlist_c.scl", Label="getItems") ; _count: Public Method Return=Num / (SCL="common.utility.filteredlist_c.scl", Label="count") ; _onContentsUpdated: Public Method attributeName:Input:Char / (SCL="common.utility.filteredlist_c.scl", Label="onContentsUpdated", State="O", ArgDesc1="Name of attribute whose value changed to cause the event") ; _setcamModel: Public Method attributeValue:Update:Char RETURN=Num / (SCL="common.utility.filteredlist_c.scl", Label="setcamModel", State="O", ArgDesc1="contains the attribute value", ReturnDesc="returns 0 if successful, >0 if error, <0 if warning") ; filterModelData: Public Method regexp:Input:Char / (SCL="common.utility.filteredlist_c.scl") ; setcamItemsMatch: Protected Method attributeValue:Update:Char RETURN=Num / (SCL="common.utility.filteredlist_c.scl", Description="Invoked when the itemsMatch attribute is changed", ArgDesc1="contains the attribute value", ReturnDesc="returns 0 if successful, >0 if error, <0 if warning") ; EndClass ;
Class implementation
Place this code in common.utility.filteredlist_c.scl, issue commands COMPILE, and END.
useclass common.utility.FilteredList_c.class; count: public method return=num; return listlen (items); endmethod; getIndex: public method item:input:char return=num; return searchc (items, item); endmethod; getItem: public method index:input:num return=char; return getitemC (items, index); endmethod; * this method is invoked by viewer using this class as a model; getItems: public method return=list; return(items); endmethod; onContentsUpdated: public method content:input:char; filterModelData(itemsMatch); triggerViewerUpdate = datetime(); endmethod; setcamModel: protected method av:update:char return=num; _super(av); if av = ' ' then return 0; filterModelData(itemsMatch); triggerViewerUpdate = datetime(); endmethod; filterModelData: public method regexp:input:char; declare num rc rx i ; if modelid < 1 then return; rc = clearlist (items); * use method defined for StaticStringList interface to get the models list of items; * do not presume the model class has list of items in an attribute named .items; declare list modelItems = modelid._getItems(); if regexp ne ' ' then do; rx = rxparse(regexp); if rx > 0 then do; do i = 1 to listlen (modelItems) ; declare char item = getitemC (modelItems, i); if rxmatch (rx, item) then rc = insertC (items, item, -1); end; call rxfree (rx); end; end; else rc = copylist (modelItems, 'N', items); endmethod; setcamItemsMatch: protected method av:update:char return=num; filterModelData(av); triggerViewerUpdate = datetime(); endmethod; enduseclass;Copyright 2003 Richard A. DeVenezia This page was last updated 9 May 2003.