简体   繁体   English

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

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

SWT newbie here. SWT 新手在这里。 So, what I want is to be able to highlight a whole row, along with being able to select multiple rows, and make it so that double click edits the cells.所以,我想要的是能够突出显示整行,以及能够 select 多行,并使其双击编辑单元格。 Is a focusCellManager necessary?是否需要focusCellManager? Relevant pieces of code:相关代码:

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;
       }
  };

creation of TableViewerEditor创建 TableViewerEditor

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

code for mgr (focusCellManager):经理(focusCellManager)的代码:

focusCellOwnerDrawHighlighter drawHighlighter = new FocusCellOwnerDrawHighlighter(this);

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

The tableViewer (doesn't appear in the previous snippers as tableViewer is extended by another class and we use the other class, so I don't want to confuse you): tableViewer(没有出现在之前的截图中,因为 tableViewer 是由另一个 class 扩展的,我们使用另一个 class,所以我不想混淆你):

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

Using EditingSupport on the table columns combined with the following TableViewerEditor seems to work for me:在表格列上使用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM