简体   繁体   中英

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

SWT newbie here. 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. Is a focusCellManager necessary? 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.create(this,
    mgr,
    actSupport,
    ColumnViewerEditor.TABBING_HORIZONTAL|
    ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR|
    ColumnViewerEditor.TABBING_VERTICAL|
    ColumnViewerEditor.KEYBOARD_ACTIVATION);

code for mgr (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 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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