Eclipse 4 RCP-应用程序没有活动窗口

螃蟹

我正在尝试使用设置我的视图EPartService,但在findPart调用该行时仍然出现异常我做对了吗?

例外:

Caused by: java.lang.IllegalStateException: Application does not have an active window
    at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.getActiveWindowService(ApplicationPartServiceImpl.java:36)
    at org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl.findPart(ApplicationPartServiceImpl.java:87)

代码:

package cz.vutbr.fit.xhriba01.bc.handler;

import javax.inject.Inject;
import javax.inject.Named;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;

import cz.vutbr.fit.xhriba01.bc.ui.ExplorerView;
import cz.vutbr.fit.xhriba01.bc.ui.dialogs.NewFromDirectoryDialog;

public class NewFromDirectoryHandler {

    @Inject 
    private EPartService fPartService;

    @Execute
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {

        NewFromDirectoryDialog dialog = new NewFromDirectoryDialog(shell);
        dialog.create();
        if (dialog.open() == Window.OK) {
            String sourceDir = dialog.getSourceDir();
            String classDir = dialog.getClassDir();
            TreeViewer tv = ((ExplorerView)fPartService.findPart("bc.part.explorer").getObject()).getTreeViewer();
        }
    }

}
greg-449

尝试将注入EPartService作为execute方法的参数

@Execute
public void execute(EPartService fPartService, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell)

最好避免在处理程序中注入字段,因为在创建处理程序时,它们只会被注入一次。EPartService随着活动部分的变化,诸如此类的事物也会发生变化。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

没有Eclipse GUI的Eclipse RCP应用程序

如何防止Eclipse 4 RCP应用程序中的浮动编辑器窗口出现?

eclipse rcp 4导出

将GEF4的Zest添加到Eclipse 4 RCP应用程序-依赖噩梦

如何将Perspective Bar Switcher添加到纯eclipse 4 rcp应用程序

Eclipse 4 RCP-如何从应用程序模型中删除部件?

在可见之前重新启动Eclipse 4 RCP应用程序

Eclipse 4 RCP应用程序中初始屏幕上的进度条

Eclipse RCP 4-处理程序方法参数

在Eclipse RCP应用程序中的NatTable单元格上没有出现边框

在整个应用程序启动且GUI完全呈现后,Eclipse Rcp运行基于E4的代码

带有JFreeChart的Eclipse RCP

Eclipse 4 RCP-如何创建项目?

Eclipse 4 RCP中的团队设计

如何有条件地防止用户导航到Eclipse E4 RCP应用程序中的其他视图/零件?

防止 Eclipse RCP 应用程序的多个实例

如何获得Eclipse RCP应用程序的OSGi BundleContext?

如何从Eclipse RCP应用程序中的代码更新视图

Eclipse RCP应用程序无头构建

在Eclipse RCP应用程序中禁用插件贡献

Eclipse RCP:特定于应用程序的文件夹

Eclipse 4 RCP是否可以将激活器添加到现有项目

有没有办法使用Javascript将html与RCP(E4)应用程序接口?

获取Eclipse RCP中的活动插件列表

通过部署带有Eclipse RCP的应用程序构建,无法使用JAXB

对 RCP e4 应用程序的 @CanExecute 评估

开发GEF4 rcp应用程序

激活零件后,立即在eclipse e4 RCP应用程序的屏幕上居中对话框

Eclipse e4 RCP SourceViewer语法着色