Set CmsSession locale as RWT locale.
[lgpl/argeo-commons.git] / org.argeo.cms.ui.rap / src / org / argeo / cms / web / CmsWebEntryPoint.java
index 2961eead9c386951f21b2156d62f909a77f6b90b..9a023d6bc780f999ee3afa281f46209be413ae7c 100644 (file)
@@ -14,6 +14,7 @@ import javax.security.auth.login.LoginException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.api.NodeConstants;
+import org.argeo.cms.auth.CmsSession;
 import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.auth.HttpRequestCallbackHandler;
 import org.argeo.cms.ui.CmsApp;
@@ -39,6 +40,7 @@ import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 
 /** The {@link CmsView} for a {@link CmsWebApp}. */
+@SuppressWarnings("restriction")
 public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationListener {
        private static final long serialVersionUID = 7733510691684570402L;
        private final static Log log = LogFactory.getLog(CmsWebEntryPoint.class);
@@ -101,6 +103,9 @@ public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationL
                                try {
                                        uxContext = new SimpleUxContext();
                                        imageManager = new DefaultImageManager();
+                                       CmsSession cmsSession = getCmsSession();
+                                       if (cmsSession != null)
+                                               RWT.setLocale(cmsSession.getLocale());
                                        ui = cmsWebApp.getCmsApp().initUi(parent);
                                        ui.setData(CmsApp.UI_NAME_PROPERTY, uiName);
                                        ui.setLayoutData(CmsUiUtils.fillAll());
@@ -116,6 +121,10 @@ public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationL
                return loginContext.getSubject();
        }
 
+       public <T> T doAs(PrivilegedAction<T> action) {
+               return Subject.doAs(getSubject(), action);
+       }
+
        @Override
        public boolean isAnonymous() {
                return CurrentUser.isAnonymous(getSubject());
@@ -153,9 +162,12 @@ public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationL
 
        @Override
        public void exception(final Throwable e) {
-               exception = e;
-               log.error("Unexpected exception in CMS", e);
-               doRefresh();
+               ui.getDisplay().syncExec(() -> {
+                       CmsFeedback.show("Unexpected exception in CMS", e);
+                       exception = e;
+//             log.error("Unexpected exception in CMS", e);
+                       doRefresh();
+               });
        }
 
        protected synchronized void doRefresh() {
@@ -196,7 +208,8 @@ public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationL
        public void navigateTo(String state) {
                exception = null;
                String title = setState(state);
-               doRefresh();
+               if (title != null)
+                       doRefresh();
                if (browserNavigation != null)
                        browserNavigation.pushState(state, title);
        }
@@ -209,7 +222,7 @@ public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationL
        @Override
        public void navigated(BrowserNavigationEvent event) {
                setState(event.getState());
-               doRefresh();
+               // doRefresh();
        }
 
        @Override
@@ -223,6 +236,17 @@ public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationL
                eventAdmin.sendEvent(new Event(topic, properties));
        }
 
+       @Override
+       public void stateChanged(String state, String title) {
+               browserNavigation.pushState(state, title);
+       }
+
+       @Override
+       public CmsSession getCmsSession() {
+               CmsSession cmsSession = CmsSession.getCmsSession(cmsWebApp.getBundleContext(), getSubject());
+               return cmsSession;
+       }
+
        /*
         * EntryPoint IMPLEMENTATION
         */