我正在尝试使用以下代码获取 commandService 对象。
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
return (ICommandService) window.getService(ICommandService.class);
但在其中一种情况下,我们将没有工作台。
当工作台不可用时如何获取CommandService对象。
有什么想法吗?
最佳答案
您确定工作台不可用吗?或者只是 getActiveWorkbenchWindow() 返回 null(例如,当从非 UI 线程调用时,它会返回 null)。如果是这种情况,您可以在没有 Activity 窗口的情况下获取命令服务,如下所示:
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
关于java - 当工作台不可用时如何获取 ICommandService 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17061426/