Chapter Contents |
Previous |
Next |
SAS/AF Software: Class Dictionary |
Use the Text Model Template class to create a custom model when you want to display text from a source that cannot use either an external file model or a catalog entry model. The external file model allows the text viewer to look at the contents of an external file and the catalog entry model allows the text viewer to look at the contents of a catalog entry. These models, which are subclasses of the Text Model Template class, are described in the Catalog Entry Model class and the External File Model class.
If you want to expand the functionality of either of these models, subclass that model directly and override only the methods you want to modify.
If you are making a model to view a different type of data, subclass the Text Model Template class. In this case, define all of the methods for the class to provide the functionality specific to your data.
Example: Creating a Custom Model by Subclassing the Text Model Template |
This example creates a model that, when connected with a text viewer, displays the contents of a LIST or SLIST catalog entry:
build sasuser.textview.list_m.class
LIST_M.CLASS is the name of the List Model subclass. Set the parent class to SASHELP.FSP.GCONTROL, the name of the Text Model class. LIST_M.CLASS will inherit methods from SASHELP.FSP.GCONTROL.CLASS.
Additional Attributes
, select
Methods
to bring up a list of all
of the methods defined for this class.
Source Entry
field, specify
SASUSER.TEXTVIEW.LIST_M.SCL as the location for the new SCL code for the method.
Specify ATTACH as the SCL entry label.
Instance Variables
to bring up a list of all of the instance variables
defined for this class.
Add mode on
. Type ATTR
in the
Name
field and set its value to SASUSER.TEXTVIEW.ATTRLIST.FRAME.
Name
field, set
Automatic
to
Yes
, and set
Type
to
List
.
Type
to
Numeric
.
build sasuser.textview.list_m.scl
length lname $ 35; GETDATA: method buffer attr $ 200 maxlen row col 8 cchar $ 1 rc textlist attrlist 8; if listlen(poplist) < row then do; buffer = _blank_; rc = -1; /* end of data */ end; else do; buffer = getitemc(poplist, row); rc = 0; /* not end of data */ end; attr = ""; /* attribute string is unused */ maxlen = length(buffer); cchar = _blank_; /* carriage control is unused */ textlist = 0; attrlist = 0; endmethod; INIT: method modellst 8; link setivs; call super(_self_, '_init_', modellst); endmethod; ATTACH: method modellst 8; link setivs; call super(_self_, '_attach_', modellst); endmethod; SETATTR: method modellst 8; link setivs; endmethod; SETIVS: viewer = modellst; /* list name is stored on input sublist */ englist = getniteml(modellst, '_engattr'); lname = getnitemc(englist, '_lname'); if poplist then rc = dellist(poplist, 'Y'); poplist = makelist(); rc = fillist('CATALOG', lname, poplist); if listlen(poplist) then call send(viewer, '_validFile', 1); else call send(viewer, '_validFile', 0); return; DETACH: method; viewer = 0; call super(_SELF_, '_detach'); endmethod;
The _init, _attach, and _setAttributes methods are all passed the object identifier of the text viewer. The text viewer saves the model information for the model it is using on a named sublist called _engattr. These items come from the attributes window that the list model defines (see step 5). The _lname item set in the attributes window will therefore be found on the _engattr list. These three methods are also responsible for calling the text viewer _validFile method upon completion and notifying it whether there is a valid data source.
The VIEWER instance variable is the object identifier of the text viewer. It is set on _init, _attach, and _setAttributes from the input list and is cleared on _detach to disconnect the viewer from the model.
The POPLIST instance variable contains the actual list of text to display in the text viewer. Therefore, the _getData method simply returns the text from this list. The POPLIST list is previously filled in by the _init, _attach, or _setAttributes method.
build sasuser.textview.attrlist.frame resource=syswndw
Specify the SYSWNDW resource so the Generic Combo Box object, which is not in the default RESOURCE entry, appears in the Selection List.
Combo type
select
Catalog
Entry Selector
.
Additional Attributes
, choose
Type Specific
and select LIST and
SLIST for entry types, since those are the only types you want to allow. (Use
the CNTRL key to make multiple selections.) Click OK
to exit the Catalog List Values window and again to exit the Base Combo Box
Attributes window.
entry optional = _widget_ 8 _uattr_ $ _class_ 8; INIT: lname = getnitemc(_widget_, '_lname_', 1, 1, " "); call notify('lname', '_set_text_', lname); return; TERM: if _status_ eq 'c' then return; call notify('lname', '_get_text_', lname); rc = setnitemc(_widget_, lname, '_lname_'); return;
The ENTRY statement is always specified as shown because these are the arguments that the Text Viewer Attributes window sends when it brings up the model window. Items from the Attributes window that need to be saved so that the model's _setAttributes, _init, and _attach methods can get to them should be placed on the _widget list as above. This _widget list will be saved as a named item list called _engattr on the object list of the text viewer.
rm make 'text viewer'
Data Source
, select
Other
and in the field to the right enter in the
name of the new class, SASUSER.TEXTVIEW.LIST_M.CLASS. Press RETURN.
Additional Attributes
, select
Data class attributes
to bring up
the List Model Attributes window. Enter or select a LIST or SLIST entry,
such as SASHELP.FSP.COLORNAM.SLIST. Click OK to
close the List Model Attributes window and again to close the Text Viewer
Attributes window.
Instance variables inherited from the object class are described in the Object class.
When you subclass the Text Model Template class, add an instance variable called ATTR if your subclass has an attributes window.
Data class
attributes
.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.