Moving Legacy Classes to the SAS Component Object Model |
With the SAS Component Object Model, SAS/AF components use a process of object passing and attribute linking (see Enabling Drag and Drop Functionality) to handle drag and drop operations. This process differs from the way drag and drop operations are handled in Version 6. SAS/AF software synchronizes the two approaches; if you use certain aspects of drag and drop operations that are found in Version 6, then you cannot use the SCOM approach. Specifically:
If you use the Version 6 _setDragOp method to set a drag operation, SAS/AF does not update the dragOperations attribute.
If you override a drag and drop method that has a Version 6 "signature" (that is, a method that does not have the drag and drop object as an argument) and you do not override any of the new SCOM-based methods, then SAS/AF uses Version 6 "signatures" for all other methods used in the drag and drop process.
If you override any drag and drop method that has a signature (that is, a method that does have the drag and drop object argument), then SAS/AF uses SCOM-based signatures for drag and drop methods even if a method with a Version 6 "signature" is overridden.
If you override both Version 6 methods and the new SCOM methods for any drag and drop method, then SAS/AF uses SCOM signatures for all drag and drop methods.
Comparing Legacy and New Drag and Drop Functionality |
In Version 6, in order for you to build any application that utilized drag and drop functionality, you had to override one or more of the drag and drop methods. A simple example would be a frame that has a list box that displays four-level GRSEG entry names. The frame also has a SAS/GRAPH Output object on it. You want the user to be able to drag an item from the list box and then to have the graph automatically be displayed in the graph output control. Version 6 required the following SCL code:
length lib cat entry type $ 8 fullname $43; INIT: /* assign the drag representation to the listbox object */ call notify('listbox', '_add_drag_rep_', '_DND_TEXT'); /* assign the drop representation to the graph output object */ call notify('graph', '_add_drop_rep_', '_DND_TEXT'); /* assign COPY as the drag and drop operation for both sites */ call notify('listbox', '_add_drag_op_', 'COPY'); call notify('graph', '_add_drop_op_', 'COPY'); /* override the _get_drag_data_ method on the drag site */ call notify('listbox', '_set_instance_method_', '_get_drag_data_', 'sasuser.methods.methods.scl', 'getdata'); /* override the _drop method on the drop site */ call notify('graph', '_set_instance_method_', '_drop_', 'sasuser.methods.methods.scl', 'drop'); /* create an instance of the SAS catalog class */ catclass= loadclass('sashelp.fsp.catalog.class'); catobj = instance(catclass); entryinfo = makelist(); /* tell it which catalog you want to retrieve entry names from */ call send(catobj, '_setup_', 'sashelp.eisgrph'); /* retrieves a list of sublists with catalog entry information */ /* for GRSEG entries only */ call send(catobj, '_get_members_', entryinfo, "objtype='grseg'", 'libname catname objname objtype'); /* entries is the name of the variable specified in the list */ /* box's object attribute window as the one that will contain */ /* the SCL list to fill the list box */ entries = makelist(); /* loop through the entryinfo list to build the fullname string */ /* to insert into the list that displays in the list box */ do j = 1 to listlen(entryinfo); sublist = getiteml(entryinfo, j); lib = getnitemc(sublist, 'LIBNAME',1,1,''); cat = getnitemc(sublist, 'CATNAME',1,1,''); entry = getnitemc(sublist, 'OBJNAME',1,1,''); type = getnitemc(sublist, 'OBJTYPE',1,1,''); fullname = trim(lib)||'.'||trim(cat)||'.'||trim(entry)|| '.'||trim(type); rc = insertc(entries, fullname, -1); end; /* clean-up */ rc = dellist(entryinfo, 'Y'); call send(catobj, '_term_'); return;
In addition, you had to override the _getDragData method on the list box drag site:
length text $40; getdata: method rep op $ 40 data x y 8; if rep = '_DND_TEXT' then do; call send(_self_, '_get_last_sel_', row, issel, text); rc=setitemc(data, text, 1, 'y'); end; else call super(_self_, '_get_drag_data_', rep, op, data, x, y); endmethod;
Then you had to override the _drop method on the graph drop site:
drop: method rep op $ 40 data 8 from $ 7 x y 8; if rep = '_DND_TEXT' then do; grafname=getitemc(data, 1); call send(_self_, '_set_graph_', grafname); end; else call super(_self_, '_drop_', rep, op, data, from, x, y); endmethod;
In new releases of SAS/AF, you can accomplish the same action with the following steps:
From the new Components window, select the List Box Control and then drop it on your frame.
From the Components window, select the Catalog Entry List Model and drop it on top of the List Box Control to establish a model/view relationship. (This step doesn't actually add drag and drop functionality, but it is used to illustrate the integration of SCOM features.)
From the Components window, select the Graph Output Control and then drop it onto your frame.
In the Properties window, set the following attributes for the Catalog Entry List Model component: catalog=sashelp.eisgrph, typeFilter=GRSEG. Because of the model/view communication that occurs, these attributes automatically display the list of GRSEG entries that are available from that catalog in the list box.
In the Properties window for the list box, set dragEnabled=Yes. For the graph, set dropEnabled=Yes.
In the example above, the list box control already has defaults set for its dragInfo attribute to send the current value of the selectedItem attribute when the selected item is dragged. The graph output control also has default dropInfo attribute settings to take the value passed to it and set it on its graph attribute. The value of the selectedItem is a four-level GRSEG name, so that is what the graph attribute expects. The graph output control then displays the graph.
When the drop occurs, an object that contains data which includes the name of the drag site attribute and its value is passed to the _drop method. The _drop method uses this information to invoke _setAttributeValue on itself. The attribute that is set on the drop site comes from the dropInfo attribute.
Because all components provided in AFComponents.resource include default drag and drop attribute settings, drag and drop operations are a simple process that does not require SCL code. If you want to change the defaults, simply use the Properties window to modify the attributes.
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.