]> git.argeo.org Git - lgpl/argeo-commons.git/blob - UiContext.java
82b60612404b565875b3faeb51e0dc77bf810b2b
[lgpl/argeo-commons.git] / UiContext.java
1 package org.argeo.eclipse.ui.specific;
2
3 import java.util.Locale;
4
5 import javax.servlet.http.HttpServletRequest;
6
7 import org.eclipse.rap.rwt.RWT;
8 import org.eclipse.swt.widgets.Display;
9
10 /** Singleton class providing single sources infos about the UI context. */
11 public class UiContext {
12
13 public static HttpServletRequest getHttpRequest() {
14 return RWT.getRequest();
15 }
16
17 public static Locale getLocale() {
18 return RWT.getUISession().getLocale();
19 }
20
21 public static void setLocale(Locale locale) {
22 RWT.getUISession().setLocale(locale);
23 }
24
25 /** Can always be null */
26 @SuppressWarnings("unchecked")
27 public static <T> T getData(String key) {
28 Display display = getDisplay();
29 if (display == null)
30 return null;
31 return (T) display.getData(key);
32 }
33
34 public static void setData(String key, Object value) {
35 Display display = getDisplay();
36 if (display == null)
37 throw new SingleSourcingException(
38 "Not display available in RAP context");
39 display.setData(key, value);
40 }
41
42 private static Display getDisplay() {
43 return Display.getCurrent();
44 }
45
46 private UiContext() {
47 }
48
49 }