]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/UiContext.java
1 package org
.argeo
.eclipse
.ui
.specific
;
3 import java
.util
.Locale
;
5 import javax
.servlet
.http
.HttpServletRequest
;
6 import javax
.servlet
.http
.HttpServletResponse
;
8 import org
.eclipse
.rap
.rwt
.RWT
;
9 import org
.eclipse
.swt
.widgets
.Display
;
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();
18 public static HttpServletResponse
getHttpResponse() {
19 return RWT
.getResponse();
22 public static Locale
getLocale() {
23 if (Display
.getCurrent() != null)
24 return RWT
.getUISession().getLocale();
26 return Locale
.getDefault();
29 public static void setLocale(Locale locale
) {
30 if (Display
.getCurrent() != null)
31 RWT
.getUISession().setLocale(locale
);
33 Locale
.setDefault(locale
);
36 /** Can always be null */
37 @SuppressWarnings("unchecked")
38 public static <T
> T
getData(String key
) {
39 Display display
= getDisplay();
42 return (T
) display
.getData(key
);
45 public static void setData(String key
, Object value
) {
46 Display display
= getDisplay();
48 throw new SingleSourcingException("Not display available in RAP context");
49 display
.setData(key
, value
);
52 private static Display
getDisplay() {
53 return Display
.getCurrent();