Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » get IHandlerService from background thread(How to get IHandlerService from background thread in RAP)
get IHandlerService from background thread [message #878481] Tue, 29 May 2012 12:04 Go to next message
Andreas Hollmann is currently offline Andreas Hollmann
Messages: 20
Registered: June 2011
Location: Dresden
Junior Member
How can I access Services from background jobs in RAP?

Usually you get IHandlerService throgh workbench instance like this:
public static IHandlerService getHandlerService(){
	IWorkbench workbench = PlatformUI.getWorkbench();
	if(workbench==null)
		return null;
	IHandlerService handlerService = (IHandlerService) workbench.getService(IHandlerService.class);
	return handlerService;
}


But if you want to get IHandlerService from a background job to fire some events you can't do it because you can't access Display object.
Display.getDefault();

doesn't work in RAP!

Best Regards
Andreas Hollmann


[Updated on: Tue, 29 May 2012 12:05]

Report message to a moderator

Re: get IHandlerService from background thread [message #878541 is a reply to message #878481] Tue, 29 May 2012 13:48 Go to previous messageGo to next message
Rüdiger Herrmann is currently offline Rüdiger Herrmann
Messages: 335
Registered: July 2009
Senior Member
Andreas,

unlike in RCP, in RAP there is more than one display. Each session has
its own display (and Workbench).
The UI thread (the one that services the requests) has a context
assigned that associates it with the session/display it belongs to.
Hence, calling Display#getDefault() from this thread will return the
associated display.
Any other thread you'll have to associate to a session yourself. Usually
the display or workbench is passed as a parameter to the thread.
Given hat you have a reference to the display within your background
thread, you can use the method described here [1] to access any other
per-session singleton (i.e. the Workbench).

HTH
Rüdiger

[1]
http://wiki.eclipse.org/RAP/FAQ#How_to_access_the_HTTP_session_.2F_session_store.3F

On 29.05.2012 14:05, Andrej Mising name wrote:
> How can I access Services from background jobs in RAP?
>
> Usually you get IHandlerService throgh workbench instance like this:
>
> public static IHandlerService getHandlerService(){
> IWorkbench workbench = PlatformUI.getWorkbench();
> if(workbench==null)
> return null;
> IHandlerService handlerService = (IHandlerService)
> workbench.getService(IHandlerService.class);
> return handlerService;
> }
>
>
> But if you want to get IHandlerService from a background job to fire
> some events you can't do it because you can't access Display object.
>
> Display.getDefault();
>
> doesn't work in RAP!
>
> Best Regards
> Andreas Hollmann
>
>
>
--
Rüdiger Herrmann
http://codeaffine.com
Re: get IHandlerService from background thread [message #878560 is a reply to message #878541] Tue, 29 May 2012 14:24 Go to previous message
Andreas Hollmann is currently offline Andreas Hollmann
Messages: 20
Registered: June 2011
Location: Dresden
Junior Member
Thank you for your reply!

I'll do like your advice.

I think in the future the IWorkbench.getService() method should be moved to Platform-API, thus it becomes independend of Display class. For example some background work started from NON-UI threads can fire events and UI-components can react on fired events and update its content.

Best Regards
Andreas Hollmann
Previous Topic:RAP 1.5m7 + FORMS
Next Topic:GEF in RAP repaints the whole SWT canvas on any update
Goto Forum:
  


Current Time: Sat Oct 25 20:54:59 GMT 2014

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

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