首次致电后,透视图为空

时间:2018-12-04 12:32:13

标签: java eclipse-rcp

最近,我一直在将所有观点和观点从RCP 3移植到RCP4。我现在想在我的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

可能是什么原因造成的?

1 个答案:

答案 0 :(得分:2)

“制成本地副本”消息来自3.x兼容模式代码的WorkbenchPage部分。它试图在3.x透视图列表中找到该透视图并失败(因为您是使用e4 API创建的)。

在您仍然拥有3.x兼容模式代码的情况下,您似乎真的无法轻松使用e4透视图API。