Direct editing of cell values
The application programming interface (API) for user editing of cell values is similar to the interface provided by EwIconList. The main difference with a table list widget is that the beginEditCallback and endEditCallback resources are used to provide editing facilities for individual cell values rather than for items in the list. Cell editing can take place automatically as individual cells are selected, or it can occur under application control by using editing functions.
Cell editing can automatically begin when a user clicks on a cell. To enable automatic cell editing the following resources must be set:
• The editable resource of the table list widget must be set to true.
• The editable resource of each column in which cells are to be edited must be set to true.
• The selectionPolicy resource of the table list must be set to XmCELLSINGLESELECT or XmCELLBLOCKSELECT.
When cell editing is under application control, editing begins when the application sends editCellAt: or editSelectedCell to the table list widget. These functions can be used to trigger cell editing regardless of the value of the editable resource in the table or in its columns.
In both automatic editing and application-controlled editing, an application must specify a callback handler for the beginEditCallback and endEditCallback resources for each column that is to provide editing capability. When a cell is about to be edited, either because you clicked in it or because the application sent editCellAt: or editSelectedCell, the column activates its beginEditCallback. The application must hook this callback for editing to occur. At a minimum, the application must set the callData doit flag to true to allow editing to begin.
Editing ends when the widget loses focus or another item is selected. When this happens, or when the value in the edit widget has been changed (the exact details of when a change has occurred depend on the edit policy; see
"Edit policies"), the column activates its
endEditCallback. The callData includes the old value and the new value. Your application should hook this callback and save the new edited value in your application as appropriate. The cell is then automatically refreshed after the callback is sent, so that the new value is obtained and displayed.
The following code builds on the previous example and shows how cell editing can be provided. First, the table list must be created in a slightly different way:
...
tableList := shell
createScrolledTableList: 'scrolled list'
argBlock: [:w | w
columns: self columns;
items: Object subclasses;
"Automatic editing is provided by setting the table list to be
editable and setting the selection policy to XmCELLSINGLESELECT."
editable: true;
selectionPolicy: XmCELLSINGLESELECT].
tableList manageChild.
...
Next, the comment columns beginEditCallback and the endEditCallback must be hooked, and the editable resource must be set to true:
commentColumn
"Answer the column for the class' comment."
| col |
col := EwTableColumn new
editable: true;
heading: 'Comment';
resizable: true;
width: 512;
horizontalHeadingAlignment: XmALIGNMENTCENTER;
yourself.
col
addCallback: XmNcellValueCallback
receiver: self
selector: #textCellValue:clientData:callData:
clientData: #comment;
addCallback: XmNbeginEditCallback
receiver: self
selector: #beginEditText:clientData:callData:
clientData: nil;
addCallback: XmNendEditCallback
receiver: self
selector: #endEditText:clientData:callData:
clientData: nil.
^ col
Finally, the handlers must be written for the beginEditCallback and the endEditCallback.
beginEditText: widget clientData: clientData callData: callData
"About to start editing a text field. Ensure the doit field is true."
callData doit: true
endEditText: widget clientData: clientData callData: callData
"Editing of a cell has just completed. Accept the value
and place it into the appropriate place in the list item."
callData item comment: callData newValue
Last modified date: 01/29/2015