SWT使用TAB移动TableViewer

GGr*_*rec 2 swt jface widget tableviewer

另一个类似的StackOverflow问题帮助我达到了一定程度.

我的TableViewer单元格包含布尔小部件editors(不是通常的检查按钮小部件,而是一个切换按钮,可以是"已选中"/"未选中").




该表必须:
- 在选择单元格时始终显示编辑器;
- 当细胞焦点丢失时禁用编辑器;
- 按下row时正确移动到下一个TAB;




显然很容易,在实践中很难.很多听众的冲突(TAB并没有真正起作用).

稍后编辑:

我已经设法解决了大多数错误,但是这一个错误仍然令我难以理解.如果我用鼠标更改小部件的值,然后按TAB以遍历,焦点将跳转到下一行,而不是下一行.但是,如果我使用空格键更改编辑器的值,那么遍历工作正常; 它应该跳到下一行.

我应该如何调试那些该死的听众?

Waq*_*yas 5

为了便于开发,您可以在JFace中使用一些帮助程序类,您不必处理Tab键或鼠标单击的事件处理.这是一个应该帮助您入门的片段:

TableViewer viewer = ...

TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer));

ColumnViewerEditorActivationStrategy activationSupport = new ColumnViewerEditorActivationStrategy(viewer) {
    protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
        if (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION) {
            EventObject source = event.sourceEvent;
            if (source instanceof MouseEvent && ((MouseEvent)source).button == 3)
                return false;
        }
        return super.isEditorActivationEvent(event) || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR);
    }
};

TableViewerEditor.create(viewer, focusCellManager, activationSupport, ColumnViewerEditor.TABBING_HORIZONTAL | 
    ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | 
    ColumnViewerEditor.TABBING_VERTICAL |
    ColumnViewerEditor.KEYBOARD_ACTIVATION);
Run Code Online (Sandbox Code Playgroud)