Improve CMS App.
[lgpl/argeo-commons.git] / org.argeo.cms.ui.rap / src / org / argeo / cms / web / CmsWebApp.java
index 03ac353df248ab5952daa0ad559747d477131532..ca26c5830c7a0ad4bbf4a08928aa45a06bc53848 100644 (file)
@@ -9,17 +9,20 @@ import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.ui.CmsApp;
 import org.argeo.cms.ui.CmsAppListener;
 import org.argeo.cms.ui.CmsTheme;
+import org.argeo.cms.ui.CmsView;
 import org.argeo.util.LangUtils;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.application.Application;
 import org.eclipse.rap.rwt.application.ApplicationConfiguration;
+import org.eclipse.rap.rwt.application.ExceptionHandler;
 import org.eclipse.rap.rwt.client.WebClient;
+import org.eclipse.swt.widgets.Display;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.event.EventAdmin;
 
 /** An RWT web app integrating with a {@link CmsApp}. */
-public class CmsWebApp implements ApplicationConfiguration, CmsAppListener {
+public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, CmsAppListener {
        private final static Log log = LogFactory.getLog(CmsWebApp.class);
 
        private BundleContext bundleContext;
@@ -59,6 +62,18 @@ public class CmsWebApp implements ApplicationConfiguration, CmsAppListener {
 
        }
 
+       @Override
+       public void handleException(Throwable throwable) {
+               Display display = Display.getCurrent();
+               if (display != null && !display.isDisposed()) {
+                       CmsView cmsView = CmsView.getCmsView(display.getActiveShell());
+                       cmsView.exception(throwable);
+               } else {
+                       log.error("Unexpected exception outside an UI thread", throwable);
+               }
+
+       }
+
        protected void addEntryPoints(Application application, Map<String, String> commonProperties) {
                for (String uiName : cmsApp.getUiNames()) {
                        Map<String, String> properties = new HashMap<>(commonProperties);
@@ -71,15 +86,17 @@ public class CmsWebApp implements ApplicationConfiguration, CmsAppListener {
 //                             if (themeId != null)
 //                                     log.warn("Theme id " + themeId + " was specified but it was not found, using default RWT theme.");
                        }
-                       application.addEntryPoint("/" + uiName, () -> {
+                       String entryPointName = !uiName.equals("") ? "/" + uiName : "/";
+                       application.addEntryPoint(entryPointName, () -> {
                                CmsWebEntryPoint entryPoint = new CmsWebEntryPoint(this, uiName);
                                entryPoint.setEventAdmin(eventAdmin);
                                return entryPoint;
                        }, properties);
                        if (log.isDebugEnabled())
-                               log.info("Added web entry point /" + (contextName != null ? contextName : "") + "/" + uiName);
+                               log.info("Added web entry point " + (contextName != null ? "/" + contextName : "") + entryPointName);
                }
-               log.debug("Published CMS web app /" + (contextName != null ? contextName : ""));
+               if (log.isDebugEnabled())
+                       log.debug("Published CMS web app /" + (contextName != null ? contextName : ""));
        }
 
 //     private void registerIfAllThemesAvailable() {