如何解决鼠标左键按下事件时 DefaultRowSelectionLayerConfiguration 和 ButtonCellPainter 之间的 Nattable 冲突?

How to resolve Nattable conflicts between DefaultRowSelectionLayerConfiguration and ButtonCellPainter on left mouse keydown event?

我正在开发一个 RCP 应用程序,并为此使用 Nebula 的 NatTable。我配置行 selection(使用 DefaultRowSelectionLayerConfiguration)和配置单元格按钮(使用 ButtonCellPainter)。 ui bing 鼠标左键按下事件。

我想要的是:

当我点击鼠标左键时,按钮响应事件,同时整行按钮被select编辑。

以下部分代码:

selectionLayer = new SelectionLayer(columnHideShowLayer,false);
selectionLayer.setSelectionModel(new RowSelectionModel<Row>(selectionLayer, bodyDataProvider,
                new IRowIdAccessor<Row>() {
                    @Override
                    public Serializable getRowId(Row rowObject) {
                        return rowObject.getStatus();
                    }
                }));
selectionLayer.addConfiguration(new DefaultRowSelectionLayerConfiguration());


class ButtonClickConfiguration<T> extends AbstractUiBindingConfiguration {

    private final ButtonCellPainter buttonCellPainter;

    public ButtonClickConfiguration(ButtonCellPainter buttonCellPainter) {
        this.buttonCellPainter = buttonCellPainter;
    }

    @Override
    public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
        // Match a mouse event on the body, when the left button is clicked
        // and the custom cell label is present
        CellLabelMouseEventMatcher mouseEventMatcher = new CellLabelMouseEventMatcher(GridRegion.BODY,MouseEventMatcher.LEFT_BUTTON, CUSTOM_CELL_LABEL5);
        // Inform the button painter of the click.
        uiBindingRegistry.registerMouseDownBinding(mouseEventMatcher, this.buttonCellPainter);
    }
}

我研究了源代码,我找到了 UiBindingRegistry 这段代码:

private IMouseAction getMouseEventAction(MouseEventTypeEnum mouseEventType, MouseEvent 事件){

// TODO: This code can be made more performant by mapping mouse bindings
// not only to the mouseEventType but
// also to the region that they are interested in. That way, given an
// area and an event we can narrow down the
// list of mouse bindings that need to be searched. -- Azubuko.Obele

try {
    LinkedList<MouseBinding> mouseEventBindings = this.mouseBindingsMap
            .get(mouseEventType);
    if (mouseEventBindings != null) {
        LabelStack regionLabels = this.natTable.getRegionLabelsByXY(event.x,
                event.y);

        for (MouseBinding mouseBinding : mouseEventBindings) {

            if (mouseBinding.getMouseEventMatcher().matches(this.natTable,
                    event, regionLabels)) {
                return mouseBinding.getAction();
            }
        }
    }
} catch (Exception e) {
    e.printStackTrace();
}
return null;

}

如果MouseDown事件bing有两个事件,只有第一个能够perform.What怎么办?我能想到的办法是select一行数据同时模拟一个cell button的按下动作,但是我不知道怎么模拟cell button的动作。

感谢任何帮助。

如果您希望在一次交互中执行多个操作,则需要创建一个自定义操作来同时执行所需的两个操作。

我在这里展示这个是为了执行选择和打开菜单。