Tab between fields in TableViewer

前端 未结 5 688
广开言路
广开言路 2020-12-19 10:20

What I\'d like to do is be able to tab between elements in table.

I currently am creating my table like this.

this.tableViewer = 
            new T         


        
5条回答
  •  感动是毒
    2020-12-19 10:49

    I couldn't get the desired behavior with a TraverseListener (it would not traverse within the table), and I had trouble getting it to work with a FocusCellManager and CellNavigationStrategy. I finally found this solution that enables me to tab from column to column within a row and automatically activate the editor.

    Viewer viewer =  ...
    
    TableViewerFocusCellManager focusCellManager =
        new TableViewerFocusCellManager(
            viewer,
            new FocusCellHighlighter(viewer) {});
    
    ColumnViewerEditorActivationStrategy editorActivationStrategy =
        new ColumnViewerEditorActivationStrategy(viewer) {
    
                @Override
                protected boolean isEditorActivationEvent(
                    ColumnViewerEditorActivationEvent event) {
                        ViewerCell cell = (ViewerCell) event.getSource();
                       return cell.getColumnIndex() == 1 || cell.getColumnIndex() == 2;
                }
    
    };
    
    TableViewerEditor.create(viewer, focusCellManager, editorActivationStrategy,
        TableViewerEditor.TABBING_HORIZONTAL);
    

提交回复
热议问题