我正在处理工具栏项的启用/禁用状态。
我需要禁用第二个菜单,直到第一个菜单处于打开状态。为此,我尝试获取第一个菜单项的切换状态。但状态始终为 NULL。
ICommandService service = (ICommandService) PlatformUI.getWorkbench().
getService(ICommandService.class);
Command command = service.getCommand("com.commandID");
State state = command.getState("org.eclipse.ui.commands.toggleState");
有人知道是什么问题吗?也许有更好的方法来解决它?
最佳答案
您是否为您的命令注册了 ToggleState?
Since it is possible to have multiple menu contributions for the same command, we have to keep track of the state in a central place. Imagine a toggle button triggerable from the main menu and a views toolbar. The state of these buttons are keept in sync by storing the state directly in the command. The key to this is the org.eclipse.jface.commands.ToggleState.
<command id="org.eclipse.example.command.toggle"
name="Toggle Me">
<state class="org.eclipse.jface.commands.ToggleState"
id="org.eclipse.example.command.toggleState" />
</command>
请阅读this blog post了解更多详情。
关于java - 根据切换状态禁用/启用工具栏菜单项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20546360/