Re-enable previous Error handling in RAP
[lgpl/argeo-commons.git] / swt / rap / org.argeo.cms.swt.rap / src / org / argeo / cms / web / CmsWebEntryPoint.java
index 3c894d158b84101a31e1d2a92aa805d251efd3e8..4d91cf8e20e8a163740f58e4deeecc39e50abfa1 100644 (file)
@@ -17,8 +17,8 @@ import org.argeo.api.cms.CmsLog;
 import org.argeo.api.cms.CmsSession;
 import org.argeo.api.cms.ux.CmsImageManager;
 import org.argeo.api.cms.ux.CmsView;
+import org.argeo.cms.CurrentUser;
 import org.argeo.cms.LocaleUtils;
-import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.auth.RemoteAuthCallbackHandler;
 import org.argeo.cms.servlet.ServletHttpRequest;
 import org.argeo.cms.servlet.ServletHttpResponse;
@@ -34,12 +34,12 @@ import org.eclipse.rap.rwt.client.service.BrowserNavigation;
 import org.eclipse.rap.rwt.client.service.BrowserNavigationEvent;
 import org.eclipse.rap.rwt.client.service.BrowserNavigationListener;
 import org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle;
+import org.eclipse.rap.rwt.service.ServerPushSession;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.SWTError;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Widget;
 
 /** The {@link CmsView} for a {@link CmsWebApp}. */
 @SuppressWarnings("restriction")
@@ -56,6 +56,8 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
        /** Experimental OS-like multi windows. */
        private boolean multipleShells = false;
 
+       private ServerPushSession serverPushSession;
+
        public CmsWebEntryPoint(CmsWebApp cmsWebApp, String uiName) {
                super(uiName);
                assert cmsWebApp != null;
@@ -86,6 +88,7 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                browserNavigation = RWT.getClient().getService(BrowserNavigation.class);
                if (browserNavigation != null)
                        browserNavigation.addBrowserNavigationListener(this);
+
        }
 
        protected void createContents(Composite parent) {
@@ -108,6 +111,11 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                                        ui = cmsWebApp.getCmsApp().initUi(parent);
                                        if (ui instanceof Composite)
                                                ((Composite) ui).setLayoutData(CmsSwtUtils.fillAll());
+                                       serverPushSession = new ServerPushSession();
+
+                                       // required in order to doAs to work
+                                       // TODO check whether it would be worth optimising
+                                       serverPushSession.start();
                                        // we need ui to be set before refresh so that CmsView can store UI context data
                                        // in it.
                                        cmsWebApp.getCmsApp().refreshUi(ui, null);
@@ -159,10 +167,10 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                                return;
                }
                display.syncExec(() -> {
-//                     CmsFeedback.show("Unexpected exception in CMS", e);
-                       exception = e;
-                       log.error("Unexpected exception in CMS", e);
-                       doRefresh();
+                       // TODO internationalise
+                       CmsFeedback.error("Unexpected exception", e);
+                       // TODO report
+//                     doRefresh();
                });
        }
 
@@ -171,19 +179,19 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                        Subject.doAs(getSubject(), new PrivilegedAction<Void>() {
                                @Override
                                public Void run() {
-                                       if (exception != null) {
-                                               // TODO internationalise
-                                               CmsFeedback.show("Unexpected exception", exception);
-                                               exception = null;
-                                               // TODO report
-                                       }
+//                                     if (exception != null) {
+//                                             // TODO internationalise
+//                                             CmsFeedback.error("Unexpected exception", exception);
+//                                             exception = null;
+//                                             // TODO report
+//                                     }
                                        cmsWebApp.getCmsApp().refreshUi(ui, state);
                                        return null;
                                }
                        });
        }
 
-       /** Sets the state of the entry point and retrieve the related JCR node. */
+       /** Sets the state of the entry point and retrieve the related content. */
        protected String setState(String newState) {
                cmsWebApp.getCmsApp().setState(ui, newState);
                state = newState;
@@ -192,7 +200,7 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
 
        @Override
        public void navigateTo(String state) {
-               exception = null;
+//             exception = null;
                String title = setState(state);
                if (title != null)
                        doRefresh();
@@ -215,6 +223,11 @@ public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint,
                return cmsWebApp.getCmsEventBus();
        }
 
+       @Override
+       public CmsApp getCmsApp() {
+               return cmsWebApp.getCmsApp();
+       }
+
        @Override
        public void stateChanged(String state, String title) {
                browserNavigation.pushState(state, title);