Eclipse4:如果使用EPartService检索PART,则无法访问PART的STW小部件 [英] Eclipse4: Unable to access STW widget of a PART if PART is retrieved with EPartService
本文介绍了Eclipse4:如果使用EPartService检索PART,则无法访问PART的STW小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我这样声明了自己的部分:
So I declared my own part like that:
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
public class MyPart {
private Browser browser;
@Inject
public MyPart() {
}
@PostConstruct
public void createComposite(Composite parent) {
parent.setLayout(new FillLayout());
Browser browser = new Browser(parent, SWT.NONE);
}
@Focus
public void onFocus() {
if (browser!= null){
browser.forceFocus();
}
}
public Browser getBrowser() {
return browser;
}
}
从我的应用程序的另一点来看通过
From another point in my application I get a reference to this PART
via
@Inject private EPartService partService;
MPart clientPart = partService.findPart("rcp.parts.clientpart");
MyPart view = (MyPart)clientPart.getObject();
我再次检查了检索到的引用和应用程序中显示的部分是否具有相同的对象ID,因此它们是相同的。但是,如果我调用getBrowser(),我总是会得到一个空对象。
我用String尝试了相同的方案,并且可行。
I double checked that the reference retrieved and the part shown in the application have the same object ID so they are the same. BUT if I call getBrowser() I always get a null object. I tried the same scenario with a String and this worked.
问题是它是SWT小部件吗?
Is the problem that it is a SWT widget?
推荐答案
您的 createComposite
分配给局部变量:
Browser browser = new Browser(parent, SWT.NONE);
不是班级成员-应该是
browser = new Browser(parent, SWT.NONE);
这篇关于Eclipse4:如果使用EPartService检索PART,则无法访问PART的STW小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文