Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Key navigation not "active" when programmatically focusing NatTable Control
Key navigation not "active" when programmatically focusing NatTable Control [message #1752042] Wed, 18 January 2017 09:07 Go to next message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 102
Registered: October 2011
Location: Berlin, Germany
Senior Member

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 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2614
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. Wink

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

Re: Key navigation not "active" when programmatically focusing NatTable Control [message #1752078 is a reply to message #1752061] Wed, 18 January 2017 16:17 Go to previous message
Stephan Druskat is currently offline Stephan DruskatFriend
Messages: 102
Registered: October 2011
Location: Berlin, Germany
Senior Member

Thanks Dirk,

Works like a spell. I don't actually need the edit command, I simply wanted the first cell to be selected so that the user can start navigation with arrow keys straightaway.

Marvellous!

Cheers
Stephan
Previous Topic:StyledText in TextPainter
Next Topic:Displaying different objects in Nat Table
Goto Forum:
  


Current Time: Sat Sep 22 16:54:24 GMT 2018

Powered by FUDForum. Page generated in 0.01589 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top