Chapter Contents

Previous

Next
SAS/AF Software: Class Dictionary

Using the GET_DATA Data Vector Class


Calling Methods of the GET_DATA Data Vector Class

CAUTION:
Follow these Instructions Carefully To use the GET_DATA Data Vector class correctly, you must follow the instructions in this section.  [cautionend]

The GET_DATA Data Vector class contains information about one or more columns. The GET_DATA Data Vector class contains such information because the viewer can request or set information about as many columns as it likes with one call to the model's _getData or _setData method. The GET_DATA Data Vector class, however, contains information about only one row because the model's _getData and _setData methods only operate with one row at a time.

The caller of the model's _getData or _setData method is responsible for creating the instance of the GET_DATA Data Vector class passed as an argument to these methods. Therefore, if you override the model's _getData or _setData method, you need not create your own instance of the GET_DATA Data Vector class; one will be passed to you. If, however, you call the _getData or _setData method of the model directly or if your own viewer class calls _getData or _setData on the model, you are responsible for creating your own instance of the GET_DATA Data Vector class.

If you make your own instance of a GET_DATA Data Vector class, you must set up the GET_DATA data vector with information about

After making an instance of the GET_DATA Data Vector class, you should first call the _setNumberOfColumns method to tell the GET_DATA data vector how many columns exist. Then call _setRow to tell the GET_DATA data vector which row the instance refers to.

Next, for each column in the instance, you should call the _setIndex method, followed by the _setColumn method, to tell the GET_DATA data vector the information about which column you are requesting information for in each of the columns declared with the _setNumberOfColumns method.

Then you should call the _setIndex method to declare which column further method calls will refer to. If at a later point you want to change which column method calls refer to, call the _setIndex method again with the new column number. All methods of the GET_DATA Data Vector class other than the _setNumberOfColumns and _setIndex method apply to the current column, that is, the column set by the last _setIndex method call.

Calling the _setColumn method on each column index is necessary because the columns in the GET_DATA data vector may be noncontiguous. For example, if you are using a table editor, it may call _getData on the model with an instance of the GET_DATA Data Vector class requesting information about two columns. But the first column the table editor wants information about may be column number 6, and the second column it wants information about may be column number 3. The current column set by the _setColumn method reflects the display order that the table editor is using, which is 6 followed by 3 in this case.

Example: Calling GET_DATA Data Vector Methods

The following example is a code fragment from a situation in which a developer has created a viewer. In this code fragment, a GET_DATA data vector is created and set up with initial values. After that, the GET_DATA data vector can be sent to a model on a _setData call.

If this code fragment were used as part of an application, any objects that were instantiated during execution would need to be terminated when those objects were no longer needed. Likewise, any lists that were created during execution would need to be deleted when those lists were no longer needed.
 Note about code
gddvecid = instance(loadclass('sashelp.fsp.
                               gddvec'));
 Note about code
call send(gddvecid, '_setNumberOfColumns',
          2);
 Note about code
rowlst = makelist();
rc = insertn(rowlst, 6, -1);
call send(gddvecid, '_setRow', rowlst);
 Note about code
call send(gddvecid, '_setIndex', 1);
collst1 = makelist();
rc = insertn(collst1, 4, -1);
call send(gddvecid, '_setColumn', collst1);
call send(gddvecid, '_setColor', 'green');
 Note about code
call send(gddvecid, '_setIndex', 2);
collst2 = makelist();
rc = insertn(collst2, 5, -1);
call send(gddvecid, '_setColumn', collst2);
call send(gddvecid, '_setHjust', 'center');

Some of the GET_DATA Data Vector methods set or return values that are only applicable for either the form editor or the table editor. By default, it is assumed that the instance of the GET_DATA Data Vector class you create can be used by either a form editor or a table editor, and you are free to call any methods of the GET_DATA Data Vector class.

However, if you know when you make a GET_DATA data vector that it will only be used for either a form editor or a table editor, then the GET_DATA Data Vector class can do error checking for you by program halting when you call a method that is not supported by the viewer you are using. For more information, see _init in this class.

Where Methods Can Be Used

The following table shows which methods of the GET_DATA Data Vector class can be used with the Form Editor class and which can be used with the Table Editor class.

Where Methods Can Be Used
Method Name Used in Form Editor? Used in Table Editor?
_getBackgroundColor Yes Yes
_getBackgroundPattern No Yes
_getBorderColor No Yes
_getBorderStyle No Yes
_getBorderWidth No Yes
_getClassName Yes No
_getClassProperties Yes No
_getColor Yes Yes
_getColumn Yes Yes
_getFont Yes Yes
_getFormatLength Yes Yes
_getHjust Yes Yes
_getInherit Yes No
_getInternalERROR Yes No
_getLightSource No Yes
_getMargin No Yes
_getMeasuring No Yes
_getNumberOfColumns Yes Yes
_getPrinting No Yes
_getProtect Yes Yes
_getReverse No Yes
_getRow Yes Yes
_getText No Yes
_getType Yes No
_getUnformattedText Yes No
_getUnformattedValue Yes No
_getUserERROR Yes No
_getVjust No Yes
_getWrapping No Yes
_setBackgroundColor Yes Yes
_setBackgroundPattern No Yes
_setBorderColor No Yes
_setBorderStyle No Yes
_setBorderWidth No Yes
_setClassName Yes No
_setClassProperties Yes No
_setColor Yes Yes
_setColumn Yes Yes
_setFont Yes Yes
_setFormatLength Yes Yes
_setHjust Yes Yes
_setIndex Yes Yes
_setInherit Yes No
_setInternalERROR Yes No
_setLightSource No Yes
_setMargin No Yes
_setMeasuring No Yes
_setNumberOfColumns Yes Yes
_setPrinting No Yes
_setProtect Yes Yes
_setReverse No Yes
_setRow Yes Yes
_setText No Yes
_setUnformattedText Yes No
_setUnformattedValue Yes No
_setUserERROR Yes No
_setVjust No Yes
_setWrapping No Yes


Using the GET_DATA Data Vector Class with a Form Editor

You need to make special considerations when using the GET_DATA Data Vector class with a form editor. When a form editor displays its data, it calls the _getData method on the first row of data to display, followed by calls to the model _getData method for subsequent rows. For performance reasons, most items in the GET_DATA Data Vector class are only checked for the first row that the viewer calls _getData on. Only the first row is checked because most models have the same settings for a particular column for each row that column is in. For example, in a particular model, the first column may always be red and the second column may always use a particular font. So, when the form editor calls the model with the _getData method for the first displayed row, it saves these color and font values and will not check them again for subsequent _getData calls for other rows. The form editor does check for a few items such as the data value and type, but most other items, such as font, color, and justification, are not checked.

If you are overriding the model's _getData method, consider the following about checking: If you know that your columns will always have the same characteristics regardless of the row, then you need not be concerned. If, however, you want some rows to have different characteristics for the same column, then you need to notify the viewer that this is the case so that it will know to check your settings.

To notify the viewer that it needs to check the settings for all rows, call the viewer's _updateColumn method from within the _getData method call. You should call the _updateColumn method at the end of the _getData model method. You can obtain the viewer's identifier from the model's VIEWERID instance variable.

See the Form Data Model class.


Steps for Overriding the _getData Method with a Form Editor

To subclass Data Set Data Model and display the new subclass in a FRAME entry that contains a form editor object, follow these steps:

  1. Subclass the Data Set Data Model class.
    1. Edit newdatam.class.

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

    3. Select methods and override _getData using a label of getdata.

    4. Edit the SCL source and copy the contents of MYDATAM.SCL.

    5. Compile the SCL source.

  2. Create a form editor object.
    1. Edit new.frame.

    2. Create an empty region in the FRAME entry.

    3. Use the command RM FILL 'FORM EDITOR'.

    4. Set the class to be newdatam.class.

    5. Select data attributes and define a data set to use. (The following example uses sasuser.class.)

    6. Save and testaf the FRAME entry.


Example of Overriding the _getData Method with a Form Editor

The following SCL code produces a form editor:

getdata:
method gddvecid numcols 8;
call super(_SELF_, '_getData', gddvecid,
            numcols);
call send(gddvecid, '_setIndex', 1);
rowlst = makelist();
call send(gddvecid, '_getRow', rowlst);
rownum = getitemn(rowlst, 1);

viewerid = getnitemn(_SELF_, 'VIEWERID');
collst = makelist();
 Note about code
if rownum eq 1 then do;
  call send(gddvecid, '_setIndex', 1);
  rc = insertn(collst, 1, -1);
  call send(gddvecid, '_setUnformattedText',
           'newtext');
end;
 Note about code
if rownum eq 1 then do;
  call send(gddvecid, '_setIndex', 1);
  rc = insertn(collst, 1, -1);
  flist = makelist();
  flist = setnitemn(flist, 0, 'OPTIONS');
  flist = setnitemn(flist, 2, 'FAMILY');
  flist = setnitemn(flist, -1, 'CHARSET');
  flist = setnitemn(flist, 60, 'POINTS');
  flist = setnitemn(flist, 1, 'STYLE');
  flist = setnitemn(flist, 9, 'WEIGHT');
  flist = setnitemn(flist, -1, 'WIDTH');
  flist = setnitemn(flist, 1, 'PORTABLE');
  flist = setnitemn(flist, 0.46875, 'RATIO');
  call send(gddvecid, '_setFont', flist);
end;
 Note about code
if rownum eq 0 then do;
  call send(gddvecid, '_setIndex', 2);
  rc = insertn(collst, 2, -1);
  call send(gddvecid, '_setClassName',
           'sashelp.fsp.radiobox.class');
  oid = loadclass('sashelp.fsp.radiobox');
  ivlist = getniteml(oid, '_iv');
  ivlist2 = copylist(ivlist, 'Y');
  rc = setlattr(ivlist2, 'UPDATE');
 Note about code
  rc = setnitemn(ivlist2, 6, 'LENGTH');
 Note about code
  rc = setnitemn(ivlist2, 2, 'NROWS');
 Note about code
  rlist = makelist();
  radio1 = makelist();
  radio2 = makelist();
  rc = setnitemc(radio1, 'Male', 'ROWTXT');
  rc = setnitemc(radio1, 'M', 'RETVAL');
  rc = setnitemc(radio2, 'Female', 'ROWTXT');
  rc = setnitemc(radio2, 'F', 'RETVAL');
  rc = setniteml(rlist, radio1, 'R1');
  rc = setniteml(rlist, radio2, 'R2');
  rc = setniteml(ivlist2, rlist, 'RADIOLST');
  rc = putlist(ivlist2);
  call send(gddvecid, '_setClassProperties',
            ivlist2);
end;
 Note about code
if rownum eq 1 then do;
  call send(gddvecid, '_setIndex', 3);
  rc = insertn(collst, 3, -1);
  call send(gddvecid, '_setColor', 'RED');
end;
 Note about code
if rownum eq 1 then do;
  call send(gddvecid, '_setIndex', 4);
  rc = insertn(collst, 4, -1);
  call send(gddvecid, '_setBackgroundColor',
           'GREEN');
end;
 Note about code
if rownum eq 1 then do;
  call send(gddvecid, '_setIndex', 5);
  rc = insertn(collst, 5, -1);
  call send(gddvecid, '_setHjust', 'CENTER');
end;

call send(viewerid, '_updateColumn', collst);
 Note about code
  rowlst = dellist (rowlst);
  collst = dellist (collst);
endmethod;


Steps for Overriding the _getData Method with a Table Editor

To subclass Data Set Data Model and display the new subclass in a FRAME entry that contains a table editor object, follow these steps:

  1. Subclass the Data Set Data Model class.
    1. Edit newdatam.class.

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

    3. Select methods and override _getData using a label of getdata.

    4. Edit SCL source and copy the contents of MYDATAM.SCL.

    5. Compile the SCL source.

  2. Create a table editor object.
    1. Edit new.frame.

    2. Create an empty region in the FRAME entry.

    3. Use the command RM FILL 'TABLE EDITOR'.

    4. Set the class to be newdatam.class.

    5. Select data attributes and define a data set to use. (The following example uses sasuser.houses.)

    6. Set the mode to EDIT and the level to MEMBER.

    7. Save and testaf the FRAME entry.


Example of Overriding the _getData Method with a Table Editor

The following SCL code produces a table editor:

getdata:
method gddvecid numcols 8;
call super(_SELF_, '_getData', gddvecid,
            numcols);
call send(gddvecid, '_setIndex', 1);
rowlst = makelist();
call send(gddvecid, '_getRow', rowlst);
rownum = getitemn(rowlst, 1);
 Note about code
if rownum eq 1 then do;
  call send(gddvecid, '_setIndex', 1);
  flist = makelist();
  flist = setnitemn(flist, 0, 'OPTIONS');
  flist = setnitemn(flist, 2, 'FAMILY');
  flist = setnitemn(flist, -1, 'CHARSET');
  flist = setnitemn(flist, 60, 'POINTS');
  flist = setnitemn(flist, 1, 'STYLE');
  flist = setnitemn(flist, 9, 'WEIGHT');
  flist = setnitemn(flist, -1, 'WIDTH');
  flist = setnitemn(flist, 1, 'PORTABLE');
  flist = setnitemn(flist, 0.46875, 'RATIO');
  call send(gddvecid, '_setFont', flist);
end;
 Note about code
if rownum eq 1 then do;
  call send(gddvecid, '_setIndex', 3);
  call send(gddvecid, '_setColor', 'RED');
end;
 Note about code
if rownum eq 2 then do;
  call send(gddvecid, '_setIndex', 2);
  call send(gddvecid, '_setBackgroundColor',
            'GREEN');
end;
 Note about code
if rownum eq 2 then do;
  call send(gddvecid, '_setIndex', 4);
  call send(gddvecid, '_setHjust', 'CENTER');
end;
 Note about code
if rownum eq 3 then do;
  call send(gddvecid, '_setIndex', 1);
  call send(gddvecid, '_setVjust', 'MIDDLE');
end;
 Note about code
if rownum eq 3 then do;
  call send(gddvecid, '_setIndex', 3);
  call send(gddvecid, '_setBorderColor',
            'ALL', 'YELLOW');
  call send(gddvecid, '_setBorderWidth',
           'ALL', 0.1, 'in');
end;
 Note about code
if rownum eq 4 then do;
  call send(gddvecid, '_setIndex', 2);
  call send(gddvecid, '_setBorderStyle', 
            'ALL', 'DASHED');
  call send(gddvecid, '_setBorderWidth',
            'ALL', 0.1, 'in');
end;
 Note about code
if rownum eq 4 then do;
  call send(gddvecid, '_setIndex', 4);
  call send(gddvecid, '_setBorderWidth', 'ALL',
            0.1, 'in');
end;
 Note about code
if rownum eq 5 then do;
  call send(gddvecid, '_setIndex', 1);
  call send(gddvecid, '_setMargin', 'LEFT',
            0.3, 'in');
end;
 Note about code
if rownum eq 5 then do;
  call send(gddvecid, '_setIndex', 3);
  call send(gddvecid, '_setReverse', 'Y');
end;
 Note about code
if rownum eq 6 then do;
  call send(gddvecid, '_setIndex', 1);
  call send(gddvecid, '_setText', 'newtext');
end;
 Note about code
  rowlst = dellist (rowlst);
endmethod;


Chapter Contents

Previous

Next

Top of Page

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