上下文
我正在为 eclipse 3.4 及更多版本构建一个插件。
我有一个 ID 为 mrp.view
的 View ,其 menuContribution 设置为 toolbar:mrp.view
。
这个 menuContribution 有一些命令,我有这个:
<handler
class="mrp.handlers.export"
commandId="mrp.commands.export">
</handler>
<command
commandId="mrp.commands.export"
label="My command"
style="push">
</command>
我的处理程序 mrp.handlers.export
有一个动态 ìsEnabled()` 方法,如下所示:
@Override
public boolean isEnabled() {
return !getMySelection().isEmpty();
}
问题
数据更改时如何刷新工具栏上的按钮? (如果我单击工具栏的另一个按钮,刷新会自动完成,但如果我不单击...)
我试过了..
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
service.refreshElements("mrp.commands.export", null);
但它似乎没有做任何事情。
还有这个:
public class Export extends AbstractHandler implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
setBaseEnabled(!getSelection().isEmpty());
}
// ....
}
它被调用,但我的 View 菜单上的图标没有刷新(在 Eclipse 3.7 上)。 我做错了什么吗?
最佳答案
当启用发生变化时,您的处理程序必须触发一个事件。如果您使用 org.eclipse.core.commands.AbstractHandler.setBaseEnabled(boolean) 进行了更改更新处理程序,它将触发所需的事件。
关于java - 刷新 View 中的菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17087203/