gpt4 book ai didi

java - 为什么我不能在 Java NatTable 中使用特定的 CellEditor 实现 CellEditorMouseEventMatcher?

转载 作者:行者123 更新时间:2023-12-01 08:51:34 26 4
gpt4 key购买 nike

我想在 NatTable 中为所有单元格实现 MouseEvent,这是通过 ComboBoxCellEditor 类实现的。如果单击组合框,将打开包含条目的下拉框。因此,我在 UiBindingRegistry 中注册了 FirstSingleClickBinding。

我使用了 BodyCellEditorMouseEventMatcher,它工作得很好。但由于这个匹配器已被弃用,我不想再使用它了。所以它说我应该使用我尝试过的 CellEditorMouseEventMatcher,但它没有按照我期望的方式工作。CellEditorMouseEventMatcher 的文档说明如下:

Implementation of {@link IMouseEventMatcher} that will check if editing
* should be activated. For this it is possible to specify the region label to
* react on, the mouse button that was used to click and if an editor is
* registered for the cell on which the mouse click was executed. If no region
* label is specified, only the mouse button and the presence of a cell editor
* is evaluated.

但是我不能使用单元格编辑器作为参数,那么最后一句是什么意思?我只能选择提供按钮和/或区域标签作为参数。如何使用此 EventMatcher 获得与 BodyCellEditorMouseEventMatcher 相同的结果?我使用不同类型的单元格,因此只有组合框单元格才能获得此行为,这一点很重要。

这是我的“已弃用”代码:

private void editCombosOnSingleClick(final UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstSingleClickBinding(new BodyCellEditorMouseEventMatcher(ComboBoxCellEditor.class),
new MouseEditAction());
}

如果您需要更多信息,请告诉我。谢谢:)

最佳答案

使用CellEditorMouseEventMatcher,您无需指定编辑器实现。您只需指定区域和按钮(均为可选)。是否应该打开编辑器只需检查是否存在编辑器即可。编辑器的类型并不重要。

uiBindingRegistry.registerSingleClickBinding(
new CellEditorMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON),
new MouseEditAction());

使用 BodyCellEditorMouseEventMatcher,您需要为添加的每个编辑器注册一个新的匹配器。这是一个设计缺陷,因为编辑器的类型并不重要。控制单元格是否可编辑是通过 IEditableRule 甚至通过注册单元格编辑器来完成的。

因此,最终您需要确保仅注册可编辑单元格的编辑器,这又意味着您需要调整配置以确保 TextCellEditor 未注册为默认编辑器(请参阅DefaultEditConfiguration)。或者,您指定一个 IEditableRule,仅当编辑器类型为 ComboBoxCellEditor 时,该值才计算为 true,或者更好的是仅针对同一标签注册 IEditableRule#ALWAYS_EDITABLE作为编辑器,默认为 IEditableRule#NEVER_EDITABLE

关于java - 为什么我不能在 Java NatTable 中使用特定的 CellEditor 实现 CellEditorMouseEventMatcher?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42367368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com