SWT 如何让 table 通过单击突出显示整行,并通过双击编辑单元格?

SWT how to have table that highlights entire row with single click, and edits cell with double click?

这里是 SWT 新手。所以,我想要的是能够突出显示整行,以及能够 select 多行,然后双击编辑单元格。是否需要 focusCellManager?相关代码:

EditorActivationEvent

final ColumnViewerEditorActivationStrategy actSupport = 
   new ColumnViewerEditorActivationStrategy(this)
   {
     @Override
     protected boolean isEditorActivationEvent
     (ColumnViewerEditorActivationEvent event)
       {
         return event.type == 
             ColumnViewerEditorActivationEvent.TRAVERSAL
             || event.eventType == 
         ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
             || event.eventType == 
             ColumnViewerEditorActivationEvent.KEY_PRESSED
             || event.eventType ==
             ColumnViewerEditorActivationEvent.PROGRAMMATIC;
       }
  };

创建 TableViewerEditor

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

管理器代码(focusCellManager):

focusCellOwnerDrawHighlighter drawHighlighter = new FocusCellOwnerDrawHighlighter(this);

final TableViewerFocusCellManager mgr = new TableViewerFocusCellManager(this, null);

tableViewer(因为 tableViewer 是由另一个 class 扩展的,所以在之前的截图中没有出现,我们使用另一个 class,所以我不想混淆你):

TableViewer vwr = new TableViewer(tableComposite,SWT.BORDER|SWT.FULL_SELECTION|SWT.MULTI);

在 table 列上使用 EditingSupport 并结合以下 TableViewerEditor 似乎对我有用:

TableViewer viewer = new TableViewer(tableComp, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);

ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
  @Override
  protected boolean isEditorActivationEvent(final ColumnViewerEditorActivationEvent event) {
    return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL
        || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
        || event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED
        || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
  }
};

int feature = ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_HORIZONTAL
    | ColumnViewerEditor.KEYBOARD_ACTIVATION
    | ColumnViewerEditor.TABBING_CYCLE_IN_VIEWER;

TableViewerEditor.create(viewer, actSupport, feature);