如何在 TableViewer 选择更改时触发 @CanExecute 方法
How to trigger @CanExecute method on TableViewer selection change
我有一个带工具栏的部件,还有一个 TableViewer。
Int 工具栏我有一个编辑按钮,只有在 table 查看器中选择了一行时才应该激活。
我在处理程序的 canExecute 方法中添加了一个条件。
我可以看到当我点击一些按钮时执行此方法,但当 TableViewer 中的选择更改时它不会执行,因此它无法识别工具栏中的编辑按钮应该激活。
也许我可以在 TableViewer 中的选择更改时触发 @CanExecute 的执行,或者也许还有其他方法?
您可以使用以下方式执行处理程序:
@Inject
ECommandService commandService;
@Inject
EHandlerService handlerService;
...
ParameterizedCommand command = commandService.createCommand("command id", Collections.emptyMap());
if (handlerService.canExecute(command)) {
handlerService.executeHandler(command);
}
"command id" 是您的处理程序正在处理的命令的 ID。
您可以使用以下方式请求更新工具栏:
@Inject
IEventBroker eventBroker;
...
eventBroker.send(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID);
我有一个带工具栏的部件,还有一个 TableViewer。 Int 工具栏我有一个编辑按钮,只有在 table 查看器中选择了一行时才应该激活。
我在处理程序的 canExecute 方法中添加了一个条件。 我可以看到当我点击一些按钮时执行此方法,但当 TableViewer 中的选择更改时它不会执行,因此它无法识别工具栏中的编辑按钮应该激活。
也许我可以在 TableViewer 中的选择更改时触发 @CanExecute 的执行,或者也许还有其他方法?
您可以使用以下方式执行处理程序:
@Inject
ECommandService commandService;
@Inject
EHandlerService handlerService;
...
ParameterizedCommand command = commandService.createCommand("command id", Collections.emptyMap());
if (handlerService.canExecute(command)) {
handlerService.executeHandler(command);
}
"command id" 是您的处理程序正在处理的命令的 ID。
您可以使用以下方式请求更新工具栏:
@Inject
IEventBroker eventBroker;
...
eventBroker.send(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID);