Register a normal click in a table with CellEditors [message #1770747] |
Wed, 16 August 2017 13:13  |
Eclipse User |
|
|
|
Hi! I started a few days ago with NatTables. I am trying to select a CellEditor with a normal mouse click. By default the cellEditor is triggered on leftclick, but I want to trigger the acction with a second click, once the cell is selected.
-First left click: selects a cell
-Second left click on a selected cell: triggers the CellEditor
I tried this:
natTable.addConfiguration(new DefaultEditBindings() {
@Override
public void configureUiBindings(UiBindingRegistry pUiBindingRegistry) {
pUiBindingRegistry.unregisterSingleClickBinding(new CellEditorMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON));
CellEditorMouseEventMatcher mouseEventMatcher = new CellEditorMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON) {
@Override
public boolean matches(NatTable pNatTable, MouseEvent pEvent, LabelStack pRegionLabels)
{
return false;
};
pUiBindingRegistry.registerSingleClickBinding(mouseEventMatcher, new MySelectCellAction());
}
});
In MySelectCellAction I want to handle the cell selection or the CellEditor action.
When I click in the table the behavior does not change and I am not reach my own function (MySelectCellAction)
Could you please give me some help? Thanks a lot
|
|
|
Re: Register a normal click in a table with CellEditors [message #1770805 is a reply to message #1770747] |
Thu, 17 August 2017 05:10  |
Eclipse User |
|
|
|
Now it is works in this way;
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.unregisterMouseDownBinding(MouseEventMatcher.bodyLeftClick(SWT.NONE));
uiBindingRegistry.registerFirstSingleClickBinding(new CellEditorMouseEventMatcher(GridRegion.BODY), new MyAction());
}
});
private class MyAction implements IMouseAction {
@Override
public void run(NatTable natTable, MouseEvent event) {
int cursorCol = natTable.getColumnPositionByX(event.x);
int cursorRow = natTable.getRowPositionByY(event.y);
int indexCol = natTable.getColumnIndexByPosition(cursorCol);
int indexRow = natTable.getRowIndexByPosition(cursorRow);
boolean isCellSelected = selectionLayer.isCellPositionSelected(indexCol, indexRow);
if (selectedPreviously) {
natTable.doCommand(new EditCellCommand(natTable, natTable.getConfigRegistry(), natTable.getCellByPosition(cursorCol, cursorRow)));
} else {
natTable.doCommand(new SelectCellCommand(natTable, cursorCol, cursorRow, false, false));
}
natTable.redraw();
}
}
[Updated on: Fri, 18 August 2017 06:38] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03064 seconds