using context sensitive menus to enter values in a sas/af data table object richard a. devenezia

38
Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Upload: jaime-chadderton

Post on 30-Mar-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Using Context Sensitive Menus to Enter Values in a SAS/AF

Data Table Object

Richard A. DeVenezia

Page 2: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Context Menus

Widespread use Windows Office 97 SAS

Right mouse click Present menu of

choices applicable to task at hand

Page 3: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Sample Application

Enter data for a fitness study Add columns to SASUSER.FITNESS

– SMOKES

– DIET

– EXERCISE

Hands off data entry using context menus

Page 4: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

SASUSER.FITNESS

SMOKES Number of packs smoked a day

DIET Diet followed at time of fitness measures

EXERCISE Comma separated list of types of regular

exercises performed

Page 5: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

SAS/AF Front End

Page 6: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Default Context Menu

Page 7: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Desired Context Menus

SMOKES List of numbers

DIET List of diets

EXERCISE List of exercises

– Add or remove an exercise from subject’s list of exercises

Page 8: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Desired Context MenusDietSmokes Exercise

Page 9: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Control of Context Menu

Max Packs Restricts number of packs listed in menu

Exercises Restricts number of comma separated exercises

Life Style Choices Control data set

Page 10: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Life Style Choices

Data set of choices to be shown in context menus

Aspect value matches name of column in table being edited

Page 11: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

SAS/AF Makes It Happen

Frame class Data Table class Methods SCL Lists WPOPUP command

– Causes the pop up menus for a window to appear

– By default under Windows (and UNIX), this command is associated with the right mouse button

Page 12: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Making the FRAME entry

Issue commandBUILD SASUSER.NESUG99.MAIN.FRAME This creates an instance of a Frame class

Make a Data Table Right click in Frame and select Make

or Issue command RM MAKE Create an instance of a Data Table class named

FITNESS

Page 13: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Data Table: Command Processing

Right click on the Data Table Select Object Attributes

– Left click on Command Processing...

Note the Popmenu Processing setting Use _POPUP_ method

This is the ‘hook’ for installing the popmenu, I.e. the context menu

Page 14: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

FRAME: Core Concepts

Override Data Table _POPUP_ method This becomes the WPOPUP event handler

Attach column handler specifiers to the Data Table widget for the event handler to use

Page 15: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

FRAME: Sample

Override _POPUP_ call send (_frame_, '_get_widget_',’FITNESS',tabid);call send (tabid, '_SET_INSTANCE_METHOD_','_POPUP_','SASUSER.NESUG99.CONTEXT.SCL', 'POPUPCEL');

Page 16: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

FRAME: Sample

Attach column handler specifiers rc = setnitemn (tabid, _smokes,

'RMB_LIST_FOR_SMOKES');

rc = setnitemn (tabid, _diet,'RMB_LIST_FOR_DIET');

rc = setnitemc (tabid,'CONTEXT:EXERCISE','RMB_LIST_FOR_EXERCISE');

Both _smokes and _diet are SCL lists made and populated in INIT, and repopulated by user front end actions

Page 17: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Column Handler: Core Concept

A column handler specifier is a named item attached to the Data Table widget

Item name is RMB_LIST_FOR_<column_name>

Item value is– numeric: event handler assumes it is an SCL list id– character: event handler assumes it is an SCL

method defined with statement:method _self_ 8 row 8 column_name $32 _pop 8;

Page 18: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

WPOPUP Event Handler

Method statement must conform to:method plist sel 8;

plist the SCL list that is about to be popmenu’ed

sel the number of the item selected

Neither argument is used in the sample application

Page 19: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Event Handler Sample

Catalog entry SASUSER.NESUG99.CONTEXT.SCL

Has this method statement in itPOPUPCEL: method plist sel 8;

Page 20: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Event Handler Concepts

Obtain cell coordinates where popup occurred Obtain column name cell is in Check for column handler specifier Set active cell to popup cell Get column type Dispatch column handler

Special case for row 0

Page 21: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Event Handler Details

Obtain cell coordinates _poprow = makelist();_popcol = makelist();call send (_self_,

‘_GET_POPUP_CELL_’, _poprow, _popcol);

Obtain column name col = getnitemn (_popcol,1);call send (_self_,

‘_GET_DISPLAYED_COLUMN_NAME_’, col, colname);

Page 22: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Event Handler Details

Check for column handler specifier handlerItem = namedItem (_self_,

‘RMB_LIST_FOR_’ || colname);

Set active cell call send (_self_,

‘_SET_ACTIVE_CELL_’, _poprow, _popcol);

Get column type call send (_self_,

‘_GET_COLUMN_ATTRIBUTE_’, colname, ‘TYPE’, coltype);

Page 23: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Event Handler Details

Dispatch column handler select itemType (_self_,handlerItem);

when (‘N’) link popItemN;when (‘C’) link popItemC;otherwise;

end;

Special case (not done in Sample) If row=0 call code specific to a column header Sorting, formatting, column order, etc...

Page 24: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Column Handler Dispatchers

popItemN: Column handler specifier is an SCL list

popItemC: Column handler specifier is a method name

– Term context method used in later slides

Both dispatchers link to setCell: Places value selected from context menu into

the popup cell or selected region

Page 25: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

popItemN: Details

Simplest case All work was done in the FRAME Just popmenu the SCL list

_pop = getItemN(_self_, handlerItem);if listlen (_pop) > 0 then do; choice = popmenu (_pop);

if choice > 0 then link setCell;end;

Page 26: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

popItemC: Concepts

Dispatching is easy Writing the method being dispatched is harder

Get the context method Call the context method

No error checking, bad method calls cause error messages in the Log

Must conform tomethod _self_ 8 row 8 column_name $32 _pop 8;

Page 27: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

popItemC: Concepts

_pop is an SCL list made by dispatcher and passed to context method Upon return

– If _pop is not empty dispatcher will present menu and insert values into table

– If _pop is empty or invalid (deleted) dispatcher will do nothing and exit normally

Context method can perform any actions Value insertion not required

Page 28: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

popItemC: Details

Get the context method and call it popcol_method = getitemc

(_self_, handlerItem);_pop = makelist (); pophold = _pop;call method (scan (popcol_method,1,':'),

scan (popcol_method,2,':'),_self_, row, colname, _pop);

if listlen (_pop) > 0 then do; choice = popmenu (_pop); if choice > 0 then link setCell;end;

Context method ignores _pop to prevent setCell

Page 29: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

popItemC: Concepts

Why let method prevent setCell ? Value inserted into table not applicable to

region select Additional flexibility

– requires more work

– method should use techniques similar to setCell: if it wants to insert a value into the table

– method is called with arguments sufficient enough to do setCell: like processing

Page 30: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

setCell:

Long winded grunt code due to filling selected region feature

Methods used: _GET_SELECTIONS_ _GET_DATASET_ATTRIBUTES_ _LOCK_ROW_ / _UNLOCK_ROW_ _CLEAR_SELECT_ _SET_ACTIVE_CELL_ _SET_COLUMN_TEXT_ / _VALUE_

Page 31: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Context Method Statement

Must conform to method _self_ 8 row 8 column_name $32 _pop 8;

_SELF_ Data Table widget id

ROW & COLUMN_NAME Data Table cell where popup event occurred

_POP SCL list to be populated

Page 32: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Exercise Context Method

Catalog entry SASUSER.NESUG99.CONTEXT.SCL

Has this method statement in itEXERCISE: method _self_ 8 row 8 column_name $32 _pop 8;

Term Exercise method used in later slides

Page 33: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Exercise Method Overview

End result Exercise value is a comma separated list of M

values taken from the N choice values in LIFESTYL data set where aspect=‘EXERCISE’

Coupled with a FRAME object Input field nExer in the FRAME controls M

Page 34: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Exercise Method Concepts

Get FRAME Data Table resides in Get nExer value from FRAME Get current value of Exercise Check if more exercises allowed Make a context menu that shows remove before

any exercise already present, and add before any exercise not present

Update value in table accordingly

Page 35: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Exercise Method Details

Get nExer value from FRAME Data Table is in call send (getnitemn (_self_, '_FRAME_'),

'_GET_NUM_VAR_', 'NEXER', nExer);

Get current value of Exercise call send (_self_, '_GET_COLUMN_TEXT_',

column_name, exercise);

Check if more exercises allowed allow_more=(scan(exercise,nExer, ',') = '');

Page 36: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Exercise Method Details

Make a context menu to show values with remove and add prefaces Involved bit of code using two SCL lists List1 are exercises currently in value List2 are exercises obtained from lookup

– open LIFESTYL(WHERE=(ASPECT="EXERCISE"))

– populate using LVARLEVEL function

Page 37: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Exercise Method Details

Update value in table call send (_self_, '_LOCK_ROW_', row);

call send (_self_, '_SET_COLUMN_TEXT_',column_name, exercise);

call send (_self_, '_UNLOCK_ROW_');

Page 38: Using Context Sensitive Menus to Enter Values in a SAS/AF Data Table Object Richard A. DeVenezia

Conclusion

Dare to dream up intuitive interfaces SAS/AF is superbly capable You can only maximize your AF investment

with deep understanding

Richard A. DeVeneziaSample application available upon request

[email protected] and SAS/AF are registered trademarks or trademarks of SAS Institute Inc, in the USA and other countries. indicates USA registration.