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