我想在RCP-Plugin-Product中隐藏工具栏。 我将此代码添加到我的观点中:
IHandlerService service = (IHandlerService) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getService(IHandlerService.class);
if (service != null) {
try {
service.executeCommand("org.eclipse.ui.ToggleCoolbarAction", null);
} catch (ExecutionException | NotDefinedException | NotEnabledException
| NotHandledException e) {
// TODO Auto-generated catch block
StatusManager.getManager()
.handle(new Status(IStatus.ERROR, Perspective.PLUGIN_ID, "Error while hiding toolbar", e));
}
} else {
StatusManager.getManager()
.handle(new Status(IStatus.ERROR, Perspective.PLUGIN_ID, "IHandlerService is null"));
}
执行我的产品工具栏仍然可见,我收到了这个错误:
org.eclipse.core.commands.NotEnabledException: Trying to execute the disabled command org.eclipse.ui.ToggleCoolbarAction
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:485)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:488)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
at org.eclipse.ui.internal.handlers.LegacyHandlerService.executeCommand(LegacyHandlerService.java:353)
at org.eclipse.ui.internal.handlers.LegacyHandlerService.executeCommand(LegacyHandlerService.java:340)
at bdd.klighd.Perspective.createInitialLayout(Perspective.java:79)...
避免这个错误我将代码放到我的RCP-Plugin的另一个类中,之后在执行我的产品时隐藏了工具栏。
但是当我再次执行我的产品时,工具栏是可见的;我的工具栏的可见性是切换。
我想隐藏工具栏,而不是切换工具栏。 有没有人知道如何以编程方式隐藏工具栏?