为了便于开发,您可以在 JFace 中使用一些帮助程序类,而不必处理选项卡或鼠标单击的事件处理。这是一个可以帮助您入门的片段:
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);