Pergunta

I have several UI-Components which have listeners. All these listeners invoke method dialogChanged(). My goal is to make some long processing in this method and don't let the UI freeze. According to Lars Vogel it is possible to do this with help of UISynchronize being injected during runtime. But it fails for me, field of this type is not being injected and i get a NullPointerException. Here's relevant part of my code:

@Inject UISynchronize sync;
Job job = new Job("My Job") {

    @Override
    protected IStatus run(IProgressMonitor arg0)
    {
        sync.asyncExec(new Runnable()
        {
            @Override
            public void run()
            {
                updateStatus("Checking connection...");
                if (bisInstallDirSelected)
                    bisSettingsChanged();
                else
                    jarSettingsChanged();
            }
        });
        return Status.OK_STATUS;
    }

};
protected void dialogChanged()
{
    job.schedule();
}

The methods updateStatus(String s), bisSettingsChanged() and jarSettingsChanged() interact with UI, to be presice, they use method setErrorMessage(String newMessage) of superclass org.eclipse.jface.wizard.WizardPage I'd appreciate if somebody could tell me what I am doing wrong or suggest a better way to handle this problem.

Foi útil?

Solução

You can only use @Inject in classes that the e4 application model creates (such as the class for a Part or a Command Handler).

You can also use ContextInjectionFactory to do injection on your own classes.

For classes where injection has not been done you can use the 'traditional' way of running code in the UI thread:

Display.getDefault().asyncExec(runnable);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top