java - 第一次调用后视角为空

标签 java eclipse-rcp

最近,我一直在将所有视角和 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/

相关文章:

java - Eclipse 和 Team City 插件

java - 您可以从另一个类调用私有(private)构造函数吗?

java - 为什么 Eclipse RCP 显示包含某些源文件的警告消息?

java - 无法在 OwnerDrawLabelProvider 中绘制 Composite

java - 格式化 TreeItem 文本颜色?

java - Maven递归依赖排除

java - 如何在Realm中保存相关类?

Java:如果这是instanceof Something,则显示仅属于Something的变量?

eclipse - 如何在 eclipse rcp 的 View 工具栏中初始化切换按钮选定状态

java - Eclipse RCP - 相对视野透视扩展不起作用