Eclipse4: Unable to access STW widget of a PART if PART is retrieved with EPartService

不打扰是莪最后的温柔 提交于 2019-12-13 06:01:30

问题


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();

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.

Is the problem that it is a SWT widget?


回答1:


Your createComposite is assigning to a local variable:

Browser browser = new Browser(parent, SWT.NONE);

not the class member - should be

browser = new Browser(parent, SWT.NONE);


来源:https://stackoverflow.com/questions/20245358/eclipse4-unable-to-access-stw-widget-of-a-part-if-part-is-retrieved-with-eparts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!