如何在左鼠标keydown事件中解决DefaultRowSelectionLayerConfiguration和ButtonCellPainter之间的Nattable冲突?

时间:2016-01-28 09:17:05

标签: nattable

我正在开发一个RCP应用程序,并且正在使用星云的NatTable。我配置行选择(使用DefaultRowSelectionLayerConfiguration),并配置单元格按钮(使用ButtonCellPainter)。 ui bing左键击落事件。

我想要的是:

当我点击鼠标左键时,按钮会在选择整行按钮时响应事件。

部分代码:

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两个事件,只有第一个能够执行。我该怎么办?我可以想到的方法是选择一行数据同时模拟单元格按钮按下动作,但我不知道如何模拟单元格按钮的动作。

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

如果您希望在一次互动中执行多项操作,则需要创建一起执行所需操作的自定义操作。

我在这里展示了进行选择和菜单打开。 Showing NatTable context menu