Chapter Contents

Previous

Next
SAS/AF Software: Class Dictionary

Using the SCL List Model Class


Assigning Names to the Columns

Each column has a set of attributes to control how the data are displayed. These attributes are titles, formats, background colors, and foreground colors. Before you can set these attributes using their corresponding methods, you must assign names to the columns using the _setColumnNames method.

You can assign names to columns in two ways.

  1. Programmatically Using the _setColumnNames Method

    For examples that use the _setColumnNames method, see Example 1: Setting SCL List Model Attributes.

  2. By Using the SCL List Model Attributes Window

    For an example that uses the attributes window and edits the contents of a list, see Example 2: Using the SCL List Model Attributes Window.


Example 1: Setting SCL List Model Attributes

The following example shows how to set column attributes using the SCL List Model class. This example uses a list generated from the CATALOG class. The list is composed of a sublist containing six named items: LIBNAME, CATNAME, OBJNAME, OBJTYPE, OBJDESC, and MODIFIED.

How to Reproduce this Example

Follow these steps to reproduce the example in this section:

  1. Create a frame entry with a viewer such as a table editor object or a form editor object.

  2. Use the SCL code that follows.


Example Code

In this example, the viewer is called VIEWER. The viewer that is created using this code will only have four columns with titles. The ENTRY column will be blue with white text. The list contains information about each catalog entry in SASHELP.FSP.
 Note about code
INIT:
   catclass = loadclass
              ( 'sashelp.fsp.catalog.class' );
   catalog = instance( catclass );

   call send( catalog, '_setup', 
              'SASHELP.FSP' );
 Note about code
   datalist = makelist();
   call send( catalog, '_getMembers',
              datalist );
 Note about code
   call notify( '.', '_getWidget', 'VIEWER',
                view_id );
   engclass = loadclass
              ( 'SASHELP.FSP.LIST_M.CLASS' );
   model = instance( engclass );
 Note about code
   names = makelist();
   rc = insertc( names, 'OBJNAME', -1 );
   rc = insertc( names, 'OBJTYPE', -1 );
   rc = insertc( names, 'OBJDESC', -1 );
   rc = insertc( names, 'MODIFIED', -1 );

   call send( model, '_setColumnNames',
              names );
 Note about code
   titles= makelist();
   rc = setnitemc
        ( titles, 'Entry', 'OBJNAME' );
   rc = setnitemc
        ( titles, 'Type', 'OBJTYPE' );
   rc = setnitemc( titles, 'Description',
                   'OBJDESC' );
   rc = setnitemc( titles, 'Date Modified',
                   'MODIFIED' );

   call send( model, '_setColumnTitles',
              titles );
 Note about code
   bgcolors = makelist();
   rc = setnitemc
        ( bgcolors, 'BLUE', 'OBJNAME' );

   call send( model, 
              '_setColumnBgColors', 
              bgcolors );

   fgcolors = makelist();
   rc = setnitemc
        ( fgcolors, 'WHITE', 'OBJNAME' );

   call send( model, 
              '_setColumnFgColors',
              fgcolors );
 Note about code
   call send( model, '_setDataList', 
              datalist );
   call send( view_id, '_attach', model );
 Note about code
rc = dellist ( names );
rc = dellist ( titles );
rc = dellist ( bgcolors );
rc = dellist ( fgcolors );
return;

TERM:
  call send (catalog, '_term');
  call send (view_id, '_detach');
  call send (model, '_term');
  rc = dellist ( datalist );
return;


Example 2: Using the SCL List Model Attributes Window

The example in this section shows how to use the SCL List Model Attributes window to define columns that can be used in a form editor or table editor object. When using the Form Editor class with the SCL List Model, you have to define the columns that will be present at runtime so that the user will be able to create a custom layout.

During the process of creating a custom layout, the user probably will need to create one or more new widgets on the screen. To enable a new widget to display values from the SCL List Model, you have to link a column to that widget. In other words, to enable a new widget to display values from the SCL List Model, you must identify to the SCL List Model those columns that will be present at runtime.

To identify the runtime columns, use the SCL List Model Attributes window.

After you use the attributes window to identify the runtime columns, then the Form Editor automatically will know about the columns, and the user can use then to link to widgets. The alternative to defining the columns at buildtime and linking the widgets is to add SCL code to create the links at runtime before any of the widgets would display data from the model.

Relationship between the Viewer and the SCL List

The following example is an SCL program for a FRAME entry that contains a form editor or table editor object, named VIEWER, that will display the contents of an SCL list, DATALIST, containing 4 named sublists. When displayed in the viewer, each sublist represents a row, and the items in the sublists represent the columns.

Structure of the SCL List, DATALIST

Here is the structure of the list:

   datalist:  (  1 = ( ONE = 1
                       TWO = 2
                       THREE = 3
                       FOUR = 4
                       )[]
                 2 = ( ONE = 2
                       TWO = 4
                       THREE = 6
                       FOUR = 8
                       )[]
                 3 = ( ONE = 3
                       TWO = 6
                       THREE = 9
                       FOUR = 12
                       )[]
                 4 = ( ONE = 4
                       TWO = 8
                       THREE = 12
                       FOUR = 16
                       )[]
                 )[]

How to Reproduce this Example

Follow these steps to create the frame entry:

  1. Edit new.frame

  2. Create an empty region in the frame.

  3. Fill the region with either a form editor object or a table editor object.

  4. Change the NAME to 'VIEWER' and set the Data Class to be SASHELP.FSP.LIST_M.CLASS.

  5. Select the 'Data Class Attributes...'.

  6. In this example, there will be four columns named: 'ONE', 'TWO' 'THREE' and 'FOUR'. You will need to define these columns in this attribute window. Perform the following steps for each of the four column listed previously:
    1. Click the 'Add' button. A new column will be displayed in the 'Columns' list.

    2. Change the name to 'ONE' or the next column name.

    3. For the label, enter 'Column #', where # is the number of the column you are on. Then entering a label for a column, it will automatically be used for the column label text.

  7. OK out of the 'Data Class Attributes' window.

  8. OK out of the 'Form Editor Attributes' or 'Table Editor Attributes' window.

  9. In the Form Editor, a default layout that contains a widget for each of the four columns that were entered in the 'Data Class Attributes' window will be created. If you skipped step 6 and just OKed out of the Form Editor attributes window, then the Form Editor would have been empty. This is because there were no columns defined in the model.

  10. Use the code below for the frame's SCL.

  11. Compile the frame and execute it with TESTAF.

  12. The values for the items in each sublist will appear in the widgets in the Form Editor or in the cells of the Table Editor.

  13. You can edit the values of the column by clicking in one of the input widgets in the Form Editor or one of the cells in the Table Editor and typing in a new value.


How to Edit the SCL List

You can edit and update DATALIST by:


Example Code

 Note about code
length name $ 5 subname $ 8;
array sublist{4} 8 sub1-sub4;
 Note about code
INIT:
   datalist=makelist();

   do i=1 to 4;
      sublist{i}=makelist();
      do j=1 to 4;
         amt=i*j;
         name=left(put(j,words10.));
         insertn(sublist{i},amt,-1,name);
      end;
      subname=put(i,8.);
      insertl(datalist,sublist{i},-1,
         subname);
   end;
   call putlist(datalist,'Contents of
                DATALIST before updates',0);
 Note about code
   call notify('viewer','_set_data_list_',
               datalist);
   attrs=makelist();
 Note about code
   insertc(attrs,'Y',-1,'EDIT');
   call notify('viewer','_set_attributes_',
               attrs);
return;
 Note about code
TERM:
   call putlist(datalist,'Contents of list 
                after updates',0);

   if datalist then datalist=dellist
               (datalist,'y');
   if attrs then attrs=dellist(attrs);
return;


Example 3: Subclassing the SCL List Model

You can subclass the SCL List Model class to set column attributes based on the data values. In the following example, the SCL List Model class is subclassed so that the rows in the display will have different background colors, based on the object type of each catalog entry. This example uses a list generated from the CATALOG class. The list is composed of a sublist containing six named items: LIBNAME, CATNAME, OBJNAME, OBJTYPE, OBJDESC, and MODIFIED.

How to Reproduce this Example

First, create a subclass of the SCL List Model class as follows:

  1. Edit work.example.mylistm.class.

  2. Set the parent to sashelp.fsp.data_m.class.

  3. Select methods and override _init using a label of init.

  4. While in methods, override _getRowValues using a label of get_row.

  5. While in methods, override _term using a label of term.

  6. Edit the SCL source and copy the contents of MYLISTM.SCL.

  7. Compile the SCL source.


Example Code

The following SCL code is the contents of MYLISTM.SCL.
 Note about code
INIT: method optional= attr 8;
   call super( _self_, '_init', VIEWER );

   colors = makelist();
   rc = setnitemc( colors,'BROWN','CBT' );
   rc = setnitemc( colors,'GREEN','FRAME' );
   rc = setnitemc( colors,'PURPLE','SCL' );
   rc = setnitemc( colors,'RED', 'SLIST' );
   rc = setnitemc( colors,'BLUE','CLASS' );
   rc = setnitemc( colors,'ORANGE','PMENU' );
   rc = setnitemc( colors,'GRAY','RESOURCE' );

   rc = setniteml( _self_,colors,'COLORS' );

   bg = makelist();
   rc = setniteml( _self_, bg,'BGCOLORS' );
endmethod;
 Note about code
GET_ROW: method rownum rowdata fg bg fmt 8;
    fg = 0;
    fmt = 0;

    call send( _self_, '_getDataList', 
               datalist );
    rowdata = getiteml( datalist, rownum );

    typename = getnitemc( rowdata,
                          'OBJTYPE' );

    colors = getniteml( _self_,'COLORS' );
    color = getnitemc( colors,typename, 1,
            1, '        ' );

    if ( substr( color, 1, 1 ) = ' ' )
         then bg = 0;
    else do;
       bg = getniteml( _self_,'BGCOLORS' );
       rc = setnitemc( bg, color,'_color' );
    end;
endmethod;
 Note about code
TERM: method;
   colors = getniteml( _self_, 'COLORS' );
   rc = dellist (colors);
   call super( _self_, '_term' );
endmethod;

Next, create a frame entry with a table editor object (in this example called TABLE), and then use the following SCL code. The table shown will have four columns, but the rows will be colored based on the entry type. The list contains information about each catalog entry in SASHELP.FSP.
 Note about code
INIT:
    catclass = loadclass
               ('sashelp.fsp.catalog.class');
    catalog = instance( catclass );
    call send( catalog, '_setup',
               'SASHELP.FSP' );
 Note about code
   datalist = makelist();
   call send( catalog, '_getMembers', 
              datalist );
 Note about code
   call notify( '.', '_getWidget', 'TABLE',
                tabid );
   engclass = loadclass
              ('WORK.EXAMPLE.MYLISTM.CLASS');
   model = instance( engclass );
 Note about code
   names = makelist();
   rc = insertc( names, 'OBJNAME', -1 );
   rc = insertc( names, 'OBJTYPE', -1 );
   rc = insertc( names, 'OBJDESC', -1 );
   rc = insertc( names, 'MODIFIED', -1 );

   call send( model, '_setColumnNames',
              names );
 Note about code
   titles= makelist();
   rc = setnitemc( titles,'Entry',
                   'OBJNAME' );
   rc = setnitemc( titles, 'Type',
                   'OBJTYPE' );
   rc = setnitemc( titles, 'Description', 
                   'OBJDESC' );
   rc = setnitemc( titles, 'Date Modified',
                   'MODIFIED' );

   call send( model, '_setColumnTitles', 
              titles );
 Note about code
   call send( model, '_setDataList', 
              datalist );
   call send( tabid, '_attach', model );
 Note about code
   attrs = makelist();
   rc = setnitemc( attrs, 'N',
                  'DISPLAY_rowNAMES' );
   rc = setnitemc( attrs, 'Y',
                   'RESIZE_COL' );
   call send( tabid, '_setAttributes',
              attrs );
 Note about code
   rc = dellist ( names );
   rc = dellist ( titles );
   rc = dellist ( attrs );
return;

TERM:
  call send (catalog, '_term');
  call send (tabid, '_detach');
  call send (model, '_term');
  rc = dellist ( datalist );
return;


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.