getViewer()。setSelection()不使用FocusCellOwnerDrawHighlighter

时间:2013-02-11 12:05:18

标签: java swt eclipse-rcp jface tableviewer

我想将焦点设置为TableViewer中的特定行。

焦点和输入处理的定义如下:

ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.NO_RECREATE);

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

ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
            protected boolean isEditorActivationEvent(final 
                   ColumnViewerEditorActivationEvent event) {
                return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
                        || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION
                        || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.F2)
                        || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
            }
};

TableViewerEditor.create(viewer, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL
                | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR |
                 ColumnViewerEditor.TABBING_VERTICAL
                | ColumnViewerEditor.KEYBOARD_ACTIVATION);

选择行的代码是:

getViewer().setSelection(new StructuredSelection(parameterTable.getViewer().getElementAt(selection)), false);

问题是,只要我使用FocusCellOwnerDrawHighlightersetSelection就不再有效,这意味着没有选择任何行。

任何想法我做错了什么?

此致   罗杰

1 个答案:

答案 0 :(得分:0)

这不是解决方案。只是详细说明可能存在的问题。

我看到了一个问题
FocusCellOwnerDrawHighlighter:110 line


                    ViewerCell cell = row.getCell(event.index);

                    if (focusCell == null || !cell.equals(focusCell)) {
                        removeSelectionInformation(event, cell);
                    } else {
                        markFocusedCell(event, cell);
                    }

初始焦点单元格将是Table的默认顶部索引。焦点单元格和选择单元格将不相等,因此它将删除所选单元格上的选择背景。