【问题标题】:Perspective is null after the first call第一次调用后透视为空
【发布时间】:2018-12-04 12:32:13
【问题描述】:

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

这可能是什么原因造成的?

【问题讨论】:

    标签: java eclipse-rcp


    【解决方案1】:

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

    看起来你真的不能轻松地使用 e4 透视 API,而你仍然有 3.x 兼容模式代码。

    【讨论】:

    • 我真的很想摆脱 cmpatability 模式。我们现在唯一坚持的是 3.x 服务,但其余的应该能够转移。我会试着找出这个 3.x 代码在哪里,因为它不应该再被调用了。
    • 你真的可以脱离兼容模式吗?这意味着删除所有org.eclipse.ui.xxxx 插件以及IFile 之类的东西。大多数现有的 3.x 代码很难迁移到纯 e4。
    • 我不是 100% 确定。我已经成功地改变了所有的观点和观点(除了一些小问题)。这是我仍然需要做的菜单贡献和服务。
    • 目前有什么办法可以解决这个问题吗?如果我能成功地改变观点,那么目前其他一切都会奏效。
    • 对不起,我不知道。我不使用透视图或混合 e4/3.x 代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2019-01-31
    • 2014-04-18
    相关资源
    最近更新 更多