【问题标题】:How to resolve Nattable conflicts between DefaultRowSelectionLayerConfiguration and ButtonCellPainter on left mouse keydown event?如何解决鼠标左键按下事件中 DefaultRowSelectionLayerConfiguration 和 ButtonCellPainter 之间的 Nattable 冲突?
【发布时间】:2016-05-05 13:57:54
【问题描述】:

我正在开发一个 RCP 应用程序,并为此使用 Nebula 的 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这个代码:

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

感谢任何帮助。

【问题讨论】:

    标签: nattable


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      相关资源
      最近更新 更多