最近,我一直在将所有视角和 View 从 RCP 3 移植到 RCP 4。我现在想在 RCP 4 应用程序中的视角之间切换。
第一次更改为视角后,这是输出。
!MESSAGE Perspective with name 'perspective_label' and id 'PerspectiveName' has been made into a local copy
要切换视角,我使用这个
@Inject
private static MApplication app;
@Inject
private static EPartService partService;
@Inject
private static EModelService modelService;
@Inject
private static MWindow window;
private static void switchPerspective(final String id)
{
final Optional<MPerspective> perspective = PerspectiveSwitcherToolbar.findPerspective(id);
if(perspective.isPresent())
{
partService.switchPerspective(perspective.get());
}
else
{
System.out.println("Perspective not found");
}
}
private static Optional<MPerspective> findPerspective(final String perspectiveId)
{
final MUIElement element = modelService.find(perspectiveId, app);
if(element instanceof MPerspective)
{
perspectiveIdsToElement.put(perspectiveId, (MPerspective) element);
return Optional.of((MPerspective)element);
}
System.out.println("Wrong type " + element);
return Optional.empty();
}
第一次调用切换视角时,它会正确更改。第二次调用时,findPerspective
返回empty()
。
我发现这个问题似乎与完全相同的问题有关,但没有解决问题。
Open Perspective programmatically
这可能是什么原因造成的?
最佳答案
“制作为本地副本”消息来自 3.x 兼容模式代码的 WorkbenchPage
部分。它试图在 3.x 透视图列表中查找透视图,但失败了(因为您使用 e4 API 创建了它)。
看起来,当您仍然拥有 3.x 兼容模式代码时,您确实无法轻松使用 e4 透视 API。
关于java - 第一次调用后视角为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53613104/