]> git.argeo.org Git - lgpl/argeo-commons.git/blob - UiContext.java
ec3b2e96a62eb18cd162a25b167625223e03e984
[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 /** Can be null, thus indicating that we are not in a web context. */
13 public static HttpServletRequest getHttpRequest() {
14 return RWT.getRequest();
15 }
16
17 public static Locale getLocale() {
18 if (Display.getCurrent() != null)
19 return RWT.getUISession().getLocale();
20 else
21 return Locale.getDefault();
22 }
23
24 public static void setLocale(Locale locale) {
25 if (Display.getCurrent() != null)
26 RWT.getUISession().setLocale(locale);
27 else
28 Locale.setDefault(locale);
29 }
30
31 /** Can always be null */
32 @SuppressWarnings("unchecked")
33 public static <T> T getData(String key) {
34 Display display = getDisplay();
35 if (display == null)
36 return null;
37 return (T) display.getData(key);
38 }
39
40 public static void setData(String key, Object value) {
41 Display display = getDisplay();
42 if (display == null)
43 throw new SingleSourcingException(
44 "Not display available in RAP context");
45 display.setData(key, value);
46 }
47
48 private static Display getDisplay() {
49 return Display.getCurrent();
50 }
51
52 private UiContext() {
53 }
54
55 }