カスタムセルのTab遷移

【ご質問】
RecordGridにTextFieldを含むカスタムセルを設定したところ、
このセルにTab移動でフォーカスを当てることができません。
RecordGridに設定したカスタムセル間をTab移動するには、どうすれば良いでしょうか。

【回答】
本来RecordGridを含むコンテナでのTabキーでの移動はセル自身にフォーカスが移動します。
TextFieldを含むカスタムセルを設定すると、セル自身にフォーカスが移動した際
TextFieldが埋め込まれているため本来の動きができません。

回避策としては、セル自身にフォーカスが当たったときに
TextFieldでTabキーが押されたときの処理を追加することなどが考えられます。

詳細は以下のサンプルをご参照ください。

{curl 6.0,7.0,8.0 applet}
{curl-file-attributes character-encoding = “shift-jis”}

{def grid =
    {RecordGrid
        record-source = {RecordSet
                            {RecordFields
                                {RecordField “First”, domain = String},
                                {RecordField “Last”, domain = String},
                                {RecordField “Age”, domain = int}
                            },
                            {RecordData First = “John”, Last = “Smith”, Age = 25},
                            {RecordData First = “Jane”, Last = “Smith”, Age = 29},
                            {RecordData First = “Jane”, Last = “Jones”, Age = 28}
                        },
        automatic-columns? = false,
        select-current-record? = true,
        editable? = true,
        display-record-selectors? = false,
        display-navigation-panel? = false,
        select-current-record? = true,
        display-filler-column? = true,
        column-resizable? = false,
        column-movable? = false,
        multiple-selection-enabled? = false,
        {on e:FocusIn at gird:RecordGrid do
            {InputCell.cell.become-active}
        },
       
        {RecordGridColumn “First”, cells-take-focus? = false,editable? = false},
        {RecordGridColumn “Last”, cells-take-focus? = false,editable? = false},
        {RecordGridColumn “Age”, halign = “right”, cell-spec = InputCell}

    }
}

{define-class public InputCell {inherits StandardRecordGridCell}

  field private _input:TextField =
      {TextField
        color = “black”,
        halign = “right”,
        max-chars = 10,
        takes-focus? = true,
        active-traversal-container = null,
        {validate-with {NumericValidator}}
      }

  let public cell:#InputCell

  {constructor public {default …}
    {self.add-internal self._input}

    {if InputCell.cell == null then
        set InputCell.cell = self
    }
   
    {self.add-event-handler
        {on e:FocusIn at cell:InputCell do
            {self._input.become-active}
        }
    }
    {self._input.add-event-handler
        {on e:KeyPress at tf:TextField do
            {if e.value == KeyPressValue.tab then
                {if (self.grid.current-index == 0  and e.shift?) or
                    (self.grid.current-index == self.grid.record-source.size – 1 and not e.shift? )
                 then
                    {self.grid.active-traversal-container.traverse forward? = (not e.shift?)}
                    {e.consume}
                    {return}
                }
                {self.active-traversal-container.traverse forward? = (not e.shift?)}
             else
                {super.on-key-press e}
            }
        }
    }
  }

  {method public {note-grid-focus-out}:void
    {self.attempt-update self._input.value}
    {super.note-grid-focus-out}
  }
 
  {method public {refresh-data}:void
    {super.refresh-data}
    let (val:any, valid?:bool) = {self.get-data}
    set self._input.value = {if val == null then “” else val & “”}
   
  }    
}

{View
    {StandardActiveTraversalContainer
        {VBox
            {TextField width = 100pt},
            grid,
            {CommandButton}
        }
    },
    visibility = “normal”,
    {on WindowClose do
        {exit}
    }
}