swt表按Enter键可将焦点移至下一行列

时间:2019-09-23 05:59:52

标签: swt

如果更改当前表的列值并按Enter,它将移至下一行列。我想在这里输入值。当前只有单元格选择被移动,您需要直接用鼠标单击该单元格以输入一个值。

CellNavigationStrategy naviStrat = new CellNavigationStrategy() 
        {

            @Override
            public boolean isNavigationEvent(ColumnViewer viewer, Event event) {
                return event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR;
            }

            public ViewerCell findSelectedCell(ColumnViewer viewer, ViewerCell currentSelectedCell, Event event) {            
                if (event.type == ColumnViewerEditorActivationEvent.KEY_PRESSED) {                  
                    if (event.keyCode == SWT.CR  || event.keyCode == SWT.KEYPAD_CR) {                    
                        ViewerCell nextCell = currentSelectedCell.getNeighbor(ViewerCell.BELOW, false);
                        if(nextCell != null) { //다음 라인이 있을경우                        
                            if(nextCell.getItem() instanceof TableItem) {
                                tableViewer.getTable().setSelection(((TableItem)nextCell.getItem()));                                   
                            }
                        }                

                        return nextCell;

                    }

                }
                return null;
            }

        };

        new TableViewerFocusCellManager(tableViewer, new FocusCellOwnerDrawHighlighter(tableViewer), naviStrat);       

    }

0 个答案:

没有答案