]> git.argeo.org Git - lgpl/argeo-commons.git/blob - UiContext.java
ebececf154cae3d0bed8b6f2d209761cf56c5ad7
[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 if (Display.getCurrent() != null)
23 RWT.getUISession().setLocale(locale);
24 }
25
26 /** Can always be null */
27 @SuppressWarnings("unchecked")
28 public static <T> T getData(String key) {
29 Display display = getDisplay();
30 if (display == null)
31 return null;
32 return (T) display.getData(key);
33 }
34
35 public static void setData(String key, Object value) {
36 Display display = getDisplay();
37 if (display == null)
38 throw new SingleSourcingException(
39 "Not display available in RAP context");
40 display.setData(key, value);
41 }
42
43 private static Display getDisplay() {
44 return Display.getCurrent();
45 }
46
47 private UiContext() {
48 }
49
50 }