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