Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Select a cell programmatically
Select a cell programmatically [message #1185885] Thu, 14 November 2013 10:30 Go to next message
Gunnar Krüger is currently offline Gunnar KrügerFriend
Messages: 3
Registered: November 2013
Junior Member
Hi,

I am using the NatTable with GlazedList.
I want to select a cell programmatically.

The body layer stack:
SortedList<T> sortedList = new SortedList<T>(pEventList, null);
ListDataProvider<T> bodyDataProvider = new ListDataProvider<T>(sortedList, pColumnPropertyAccessor);
_bodyDataLayer = new DataLayer(bodyDataProvider, 200, 20);
GlazedListsEventLayer<T> glazedListsEventLayer = new GlazedListsEventLayer<T>(_bodyDataLayer, pEventList);
DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(glazedListsEventLayer);


The list contains about 100 entries. Now I want to select a cell.
cLOGGER.warn("select cell index column {0}  row {1}", columnIndex, rowIndex);
SelectionLayer selectionLayer = ((DefaultBodyLayerStack)_layer.getBodyLayer()).getSelectionLayer();
int columnPosition = selectionLayer.getColumnPositionByIndex(columnIndex);
int rowPosition = selectionLayer.getRowPositionByIndex(rowIndex);
cLOGGER.warn("select cell position column {0}  row {1}", columnPosition, rowPosition);
_natTable.doCommand(new SelectCellCommand(_layer.getBodyLayer(), columnPosition, rowPosition, false, false));

int testColumnPosition = ((DefaultBodyLayerStack)_layer.getBodyLayer()).getColumnPositionByIndex(columnIndex);
int testRowPosition = ((DefaultBodyLayerStack)_layer.getBodyLayer()).getRowPositionByIndex(rowIndex);
cLOGGER.warn("select cell test position column {0}  row {1}", testColumnPosition, testRowPosition);


The selection is correct if the nattable shows the first entries. But if I have scrolled the nattable before the selected cell isn't correct.

E.g. a log:
select cell index column 0  row 1
select cell position column 0  row 1
select cell test position column 0  row -18


After scrolling the nattable shows only a part of the list. Obviously it selects the row with index 1 of this part, but I want to select the entry with the index 1 of the whole list. Row -18 might be the correct position but doesn't select any cell.

Any advice how to get the right row position? Or is there another possibility to select a cell.
Re: Select a cell programmatically [message #1186084 is a reply to message #1185885] Thu, 14 November 2013 13:18 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Select the index, not the position. The position is the transformation of the index to the layer. That means, the row at index 1 is in your scrolled state at position -18. If you select the index 1 (rather than position -18) everything should work as expected. And as you told already, you want to select row at index 1 Wink

http://eclipse.org/nattable/documentation.php?page=layer
Re: Select a cell programmatically [message #1186103 is a reply to message #1186084] Thu, 14 November 2013 13:31 Go to previous messageGo to next message
Gunnar Krüger is currently offline Gunnar KrügerFriend
Messages: 3
Registered: November 2013
Junior Member
Hi Dirk,
but what Command should I use?
I used the SelectCellCommand that expects the positions not the index.
Re: Select a cell programmatically [message #1186129 is a reply to message #1186103] Thu, 14 November 2013 13:53 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Looking into the details it seems you are right ... in some way ... not sure about the details there and what the issues mentioned in the javadoc might be.

What if you try to call it like this
natTable.doCommand(new SelectCellCommand(bodyLayer.getSelectionLayer(), 0, 5, false, false));


This way you are relying on the positions in the SelectionLayer and skipping the ViewportLayer.
Re: Select a cell programmatically [message #1186200 is a reply to message #1186129] Thu, 14 November 2013 14:47 Go to previous messageGo to next message
Gunnar Krüger is currently offline Gunnar KrügerFriend
Messages: 3
Registered: November 2013
Junior Member
Yeah, that's it.
My mistake was to call the command with the body layer instead of the selection layer.

Thanks a lot.
Re: Select a cell programmatically [message #1186208 is a reply to message #1186200] Thu, 14 November 2013 14:51 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Not a mistake, but the ViewportLayer (which usually is the top most layer in the body layer stack) transforms the indexes/positions to add the virtual nature. Using the approach I suggested just skips that transformation.
Previous Topic:Drag'n'drop of rows
Next Topic:How to get row/column index based on position at CompositeLayer
Goto Forum:
  


Current Time: Thu Apr 25 09:34:51 GMT 2024

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

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

Back to the top