Multiple Row Selection - Cursor Moves to the Next Column/Row Selected [message #1708241] |
Mon, 14 September 2015 17:32  |
Eclipse User |
|
|
|
Hi,
In our application we have a need to select (highlight) another row present in the table with the same value in one of the column from the selected row.
We were able to achieve this by using the selectRow method of SelectionLayer class.
The issue is when it selects(highlights) the another row, the cursor moves to another row that got selected(highlighted) and also it shifts one column to the right.
Is there a way to Not move the cursor down to the another selected row?
Any help would be appreciated.
Thank you
Tarun.
This is the code we are using:
private Point lastClickPoint;
try {
List<AbstractFormBean> list = bodyLayerStack.getSortedList();
Collection coll = getSelectedRows();
for (int i = 0; i < list.size(); i++) {
AbstractFormBean bean = list.get(i);
if (coll.contains(bean)) {
continue;
}
Field field = bean.getClass().getDeclaredField(columnName);
field.setAccessible(true);
// TODO need for different data types
Object value = field.get(bean);
if (value != null) {
if (value.equals(cellValue)) {
int x = lastClickPoint == null ? 0 : lastClickPoint.x;
bodyLayerStack.selectionLayer.selectRow(x, i, false, true);
}
}
}
} catch (Exception e) {
// do nothing
}
We are getting the lastClickPoint based on the MousedownEvent:
natTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent arg0) {
lastClickPoint = new Point(natTable.getColumnPositionByX(arg0.x), natTable
.getRowPositionByY(arg0.y));
}
});
|
|
|
Re: Multiple Row Selection - Cursor Moves to the Next Column/Row Selected [message #1708267 is a reply to message #1708241] |
Tue, 15 September 2015 02:28  |
Eclipse User |
|
|
|
Well, there are many things that doesn't match the NatTable concepts. But let's start with the obvious.
It seems you are not aware of the index-position transformations and you are using a GridLayer. Your are using the column position of the NatTable (top-most layer) and use the same for actions on the SelectionLayer. But as you are having a GridLayer (my assumption) there is a shift of 1 column to the right, because the NatTable adds a column position to the left (the row header column). So if you want to stick with your "workaround-code" you need to use the LayerUtil for transformations by hand.
http://www.vogella.com/tutorials/NatTable/article.html#architecture_layers
The next thing is that you are adding a MouseListener on the NatTable instance. Sure this is a way to go with SWT by default, but in NatTable there are more elegant solutions. For example, NatTable has its own action binding mechanisms as you can see in the DefaultSelectionBindings. So a NatTable solution for the requirement could be to implement and register a custom IMouseAction that performs your multi-selection instead of the default SelectCellAction. At least I would implement it that way.
|
|
|
Powered by
FUDForum. Page generated in 0.04269 seconds