Key navigation not "active" when programmatically focusing NatTable Control [message #1752042] |
Wed, 18 January 2017 09:07 |
|
I have an Eclipse RCP editor with two widgets, one of them a NatTable.
When the editor is opened, I'd like the first cell (at 0,0; or column, both would work) to be selected in such a fashion that the user can start navigating the table with the arrow keys right away.
So at the end of createPartControl(), I call selectionLayer.selectCell() and then natTable.setFocus(). The cell does get selected alright, and the NatTable Control has focus (as returned by isFocusControl()), but the keys don't work. I need to click anywhere in the widget to make it work.
I've tried selecting a cell, setting focus and then calling natTable.doCommand(new EditCellCommand(natTable, natTable.getConfigRegistry(), natTable.getCellByPosition(0, 0))), but that doesn't work either, neither does SelectCellAction...
The GridLayer uses default configs, the selection layer uses custom configs.
Any ideas? Thanks!
|
|
|
Re: Key navigation not "active" when programmatically focusing NatTable Control [message #1752061 is a reply to message #1752042] |
Wed, 18 January 2017 12:28 |
Dirk Fauth Messages: 2903 Registered: July 2012 |
Senior Member |
|
|
I think you have a timing issue. NatTable is a Canvas and the internal initializations regarding sizing etc. is done after it is painted the first time. So at the time you are trying to call set focus etc. the internal states are not ready yet.
In the end you need to register a IPaintListener to perform such actions to ensure they are done after the initialization on painting is done:
natTable.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
natTable.setFocus();
natTable.doCommand(new SelectCellCommand(bodyLayerStack, 0, 0, false, false));
natTable.removePaintListener(this);
}
});
The same applies regarding the editing, where I would suggest to use the EditSelectionCommand instead of the EditCellCommand. Or if you want to use the EditCellCommand ensure to have the correct position values, as you are trying to edit the corner cell in a grid.
natTable.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
natTable.doCommand(new SelectCellCommand(bodyLayerStack, 0, 0, false, false));
natTable.doCommand(new EditSelectionCommand(natTable, natTable.getConfigRegistry()));
natTable.removePaintListener(this);
}
});
|
|
|
|
Powered by
FUDForum. Page generated in 0.03061 seconds