gpt4 book ai didi

Eclipse 4 RCP - 应用程序没有事件窗口

转载 作者:行者123 更新时间:2023-12-02 01:02:45 25 4
gpt4 key购买 nike

我正在尝试使用 EPartService 设置我的 View ,但在 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();
}
}

}

最佳答案

尝试将 EPartService 作为参数注入(inject) execute 方法:

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

最好避免在处理程序中注入(inject)字段,因为它们只会在创建处理程序时注入(inject)一次。 EPartService 之类的东西会随着事件部件的变化而变化。

关于Eclipse 4 RCP - 应用程序没有事件窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26560627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com