Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RWT.getLocale() in Threads
RWT.getLocale() in Threads [message #642414] Wed, 01 December 2010 09:09 Go to next message
Michael Klein is currently offline Michael KleinFriend
Messages: 11
Registered: July 2009
Junior Member
Hi,

I'm a little bit confused about the best way getting the client locale.
In most cases RWT.getLocale() returns the correct value, but in threads this doesn't work.
I have to implement a Runnable but (in my case) I can't be sure if it is executed with fork=true or fork=false.
So sometimes the messages I set in the ProgressMonitor are based on the wrong locale.

Is there a better way to get the client locale?

On my system the following snippet generates this output:
de_DE
en_GB


public class MyEntryPoint implements IEntryPoint {

	public int createUI() {
		Display display = new Display();
		Shell shell = new Shell(display, SWT.TITLE);
		
		System.out.println(RWT.getLocale().toString());
		
		try {
			IRunnableWithProgress runnable = new IRunnableWithProgress() {
				public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
					System.out.println(RWT.getLocale().toString());
				}
			};
			ModalContext.run(runnable, true, new NullProgressMonitor(), shell.getDisplay());
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return 0;
	}

}
Re: RWT.getLocale() in Threads [message #642601 is a reply to message #642414] Wed, 01 December 2010 22:42 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

Hi,

the client locale is only available during the processing of a request.
The forked thread runs in context that does not have that information. In
this case, the system locale is used as a fallback.

If you need the client locale in background threads, set it as RWT locale
like this: RWT.setLocale( RWT.getLocale() );

Note that doing so prevents updates when the client changes it's locale
during the session - unlikely, but possible.

Hope this helps,

--
Ralf Sternberg

Twitter: http://twitter.com/ralfstx
Blog: http://www.eclipsesource.com/blogs/

Professional support for RAP and RCP?
http://www.eclipsesource.com/support/
Re: RWT.getLocale() in Threads [message #642742 is a reply to message #642601] Thu, 02 December 2010 15:18 Go to previous message
Michael Klein is currently offline Michael KleinFriend
Messages: 11
Registered: July 2009
Junior Member
I understand.
Thanks.
Previous Topic:Browser.setUrl(String url, String postData, String[] headers)
Next Topic:Websphere, RAP and Principal
Goto Forum:
  


Current Time: Thu Oct 21 07:40:36 GMT 2021

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

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

Back to the top