第一次调用后透视为空
Perspective is null after the first call
最近我一直在将所有透视图和视图从 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
returns empty()
时。
我发现这个问题似乎与完全相同的问题有关,但没有解决问题。
Open Perspective programmatically
这可能是什么原因造成的?
'made in to a local copy' 消息来自 WorkbenchPage
兼容模式代码的 3.x 部分。它试图在 3.x 透视列表中找到透视,但失败了(因为您使用 e4 API 创建了它)。
当您仍然有 3.x 兼容模式代码时,您似乎真的无法轻松使用 e4 透视图 API。
最近我一直在将所有透视图和视图从 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
returns empty()
时。
我发现这个问题似乎与完全相同的问题有关,但没有解决问题。
Open Perspective programmatically
这可能是什么原因造成的?
'made in to a local copy' 消息来自 WorkbenchPage
兼容模式代码的 3.x 部分。它试图在 3.x 透视列表中找到透视,但失败了(因为您使用 e4 API 创建了它)。
当您仍然有 3.x 兼容模式代码时,您似乎真的无法轻松使用 e4 透视图 API。