]> git.argeo.org Git - lgpl/argeo-commons.git/blob - UiContext.java
20163cffa927732b598df6af4a508a8d2411430c
[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 import javax.servlet.http.HttpServletResponse;
7
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 null;
15 }
16
17 public static HttpServletResponse getHttpResponse() {
18 return null;
19 }
20
21 public static Locale getLocale() {
22 return Locale.getDefault();
23 }
24
25 public static void setLocale(Locale locale) {
26 Locale.setDefault(locale);
27 }
28
29 /** Can always be null */
30 @SuppressWarnings("unchecked")
31 public static <T> T getData(String key) {
32 Display display = getDisplay();
33 if (display == null)
34 return null;
35 return (T) display.getData(key);
36 }
37
38 public static void setData(String key, Object value) {
39 Display display = getDisplay();
40 if (display == null)
41 throw new IllegalStateException("Not display available");
42 display.setData(key, value);
43 }
44
45 private static Display getDisplay() {
46 return Display.getCurrent();
47 }
48
49 private UiContext() {
50 }
51
52 }