Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RCP to RAP : getDefault in no-UI thread
RCP to RAP : getDefault in no-UI thread [message #1298322] Wed, 16 April 2014 07:21 Go to next message
Clément Chausson is currently offline Clément Chausson
Messages: 16
Registered: November 2013
Junior Member
Hi,

I currently try to convert a big RCP application in RAP but i have some troubles :

When i tried to call Display.getDefault() in my function it returns null :

Quote:
!ENTRY org.eclipse.core.jobs 4 2 2014-04-16 09:13:05.265
!MESSAGE An internal error occurred during: "Create operation launched".
!STACK 0
java.lang.NullPointerException
at thales.themis.em.gene.gem.ui.api.MassObjectEditorManager.findMassObjectEditor(MassObjectEditorManager.java:97)
at thales.themis.em.gene.gem.ui.api.MassObjectEditorManager.<init>(MassObjectEditorManager.java:61)
at thales.themis.em.gene.gem.ui.api.MassObjectEditorManager.getInstance(MassObjectEditorManager.java:175)
at thales.themis.em.gene.gem.ui.operations.GemOperation.potentiallyAddMassEditorContext(GemOperation.java:130)
at thales.themis.em.gene.gem.ui.operations.CreateOperation.<init>(CreateOperation.java:109)
at thales.themis.em.gene.gem.ui.operations.CreateOperation.<init>(CreateOperation.java:147)
at thales.themis.em.gene.gem.ui.action.CreateObjectAction.run(CreateObjectAction.java:129)
at thales.themis.em.gene.gem.ui.wizards.AssociateObjectWizard$1.run(AssociateObjectWizard.java:197)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)


I know that is because i don't call it in the UI thread but i don't know how to solve it .

	private void findMassObjectEditor() {
		if (this.editor == null) {
			[color=red]Display.getDefault()[/color].syncExec(new Runnable() {

				@Override
				public void run() {

					final IWorkbenchWindow activeWorkbenchWindow =
							PlatformUI.getWorkbench().getActiveWorkbenchWindow();
					if (activeWorkbenchWindow != null) {...


I already read all about it in the RAP/FAQ, in particular section "How to update the UI from a background thread using Jobs?" and "Why does Display#getDefault() work different than in SWT" but i don't find any solution.

I would be very grateful for any help you could might be able to give me on my problem.

Thank you.

Clément

[Updated on: Wed, 16 April 2014 07:40]

Report message to a moderator

Re: RCP to RAP : getDefault in no-UI thread [message #1298613 is a reply to message #1298322] Wed, 16 April 2014 11:34 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1838
Registered: July 2009
Senior Member
Hi Clément,
you have to provide the Display instance outside background thread. Is
MassObjectEditorManager a session singleton? If this is a case, you
could get the display from the current session when
MassObjectEditorManageris created and keep it in a field.
Best,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: RCP to RAP : getDefault in no-UI thread [message #1298643 is a reply to message #1298613] Wed, 16 April 2014 11:58 Go to previous messageGo to next message
Clément Chausson is currently offline Clément Chausson
Messages: 16
Registered: November 2013
Junior Member
Hi Ivan,

Thank you for your answer.

I tried to provide display in AssociateObjectWizard class like this:

final Display display = Display.getCurrent();
				final Job createJob =
						new Job(GEMUIMessages.getString("AssociateObjectWizard.0")) { //$NON-NLS-1$

					@Override
					public IStatus run(final IProgressMonitor monitor) {
						
						monitor.beginTask(GEMUIMessages
								.getString("AssociateObjectWizard.1"), //$NON-NLS-1$
								IProgressMonitor.UNKNOWN);
						final IJobManager jobMan = Job.getJobManager();
						IStatus jobExecution = Status.CANCEL_STATUS;
						
						try {
							jobMan.beginRule(rule, monitor);
							display.asyncExec( new Runnable() {
								public void run() {
									createAction.run();
								}});
							jobExecution = createAction.getActionStatus();
						} finally {
							jobMan.endRule(rule);
							monitor.done();
						}
						return jobExecution;
					}
				};


Eclipse doesn't throw exception yet but only one part of my UI is refreshed (left column) but central part of my UI is still empty (it is refreshed in the RCP application).

I continue to investigate
Re: RCP to RAP : getDefault in no-UI thread [message #1298719 is a reply to message #1298643] Wed, 16 April 2014 12:58 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5400
Registered: July 2009
Senior Member
If you do async stuff you need to run extra code in RAP to get the
client in sync.

You need to start a server push with:

ServerPushSession session = new ServerPushSession();
session.start();

Tom

On 16.04.14 13:58, Clément Chausson wrote:
> Hi Ivan,
>
> Thank you for your answer.
>
> I tried to provide display in AssociateObjectWizard class like this:
>
> final Display display = Display.getCurrent();
> final Job createJob =
> new
> Job(GEMUIMessages.getString("AssociateObjectWizard.0")) { //$NON-NLS-1$
>
> @Override
> public IStatus run(final IProgressMonitor monitor) {
>
> monitor.beginTask(GEMUIMessages
> .getString("AssociateObjectWizard.1"),
> //$NON-NLS-1$
> IProgressMonitor.UNKNOWN);
> final IJobManager jobMan = Job.getJobManager();
> IStatus jobExecution = Status.CANCEL_STATUS;
>
> try {
> jobMan.beginRule(rule, monitor);
> display.asyncExec( new Runnable() {
> public void run() {
> createAction.run();
> }});
> jobExecution = createAction.getActionStatus();
> } finally {
> jobMan.endRule(rule);
> monitor.done();
> }
> return jobExecution;
> }
> };
>
> Eclipse doesn't throw exception yet but only one part of my UI is
> refreshed (left column) but central part of my UI is still empty (it is
> refreshed in the RCP application).
>
> I continue to investigate
Re: RCP to RAP : getDefault in no-UI thread [message #1298749 is a reply to message #1298719] Wed, 16 April 2014 13:21 Go to previous message
Clément Chausson is currently offline Clément Chausson
Messages: 16
Registered: November 2013
Junior Member
Hello Thomas,

I don't know if in my case async is better than sync, i just follow RAP/FAQ code.
I don't think that i need async stuff.

Could you tell me more about that ?

Thanks
Previous Topic:[Announcement] RAP CSS Tooling
Next Topic:RAP 1.5/2.2 - IE memory leaks
Goto Forum:
  


Current Time: Mon Oct 20 18:12:51 GMT 2014

Powered by FUDForum. Page generated in 0.07652 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software