import static org.eclipse.rap.rwt.internal.service.ContextProvider.getApplicationContext;
import java.security.PrivilegedAction;
-import java.util.HashMap;
import java.util.Locale;
-import java.util.Map;
import java.util.UUID;
import javax.security.auth.Subject;
import org.argeo.api.cms.CmsApp;
import org.argeo.api.cms.CmsAuth;
+import org.argeo.api.cms.CmsEventBus;
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.CmsUi;
import org.argeo.api.cms.ux.CmsView;
-import org.argeo.api.cms.ux.UxContext;
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;
+import org.argeo.cms.swt.AbstractSwtCmsView;
import org.argeo.cms.swt.CmsSwtUtils;
import org.argeo.cms.swt.SimpleSwtUxContext;
import org.argeo.cms.swt.acr.AcrSwtImageManager;
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.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 {
+public class CmsWebEntryPoint extends AbstractSwtCmsView implements EntryPoint, CmsView, BrowserNavigationListener {
private static final long serialVersionUID = 7733510691684570402L;
private final static CmsLog log = CmsLog.getLog(CmsWebEntryPoint.class);
- private EventAdmin eventAdmin;
-
private final CmsWebApp cmsWebApp;
- private final String uiName;
-
- private LoginContext loginContext;
- private String state;
- private Throwable exception;
- private UxContext uxContext;
- private CmsImageManager imageManager;
-
- private Display display;
- private CmsUi ui;
-
- private String uid;
// Client services
// private final JavaScriptExecutor jsExecutor;
/** Experimental OS-like multi windows. */
private boolean multipleShells = false;
+ private ServerPushSession serverPushSession;
+
public CmsWebEntryPoint(CmsWebApp cmsWebApp, String uiName) {
+ super(uiName);
assert cmsWebApp != null;
assert uiName != null;
this.cmsWebApp = cmsWebApp;
- this.uiName = uiName;
uid = UUID.randomUUID().toString();
// Initial login
browserNavigation = RWT.getClient().getService(BrowserNavigation.class);
if (browserNavigation != null)
browserNavigation.addBrowserNavigationListener(this);
+
}
protected void createContents(Composite parent) {
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);
});
}
- protected Subject getSubject() {
- return loginContext.getSubject();
- }
-
- public <T> T doAs(PrivilegedAction<T> action) {
- return Subject.doAs(getSubject(), action);
- }
-
- @Override
- public boolean isAnonymous() {
- return CurrentUser.isAnonymous(getSubject());
- }
-
@Override
public synchronized void logout() {
if (loginContext == null)
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();
});
}
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;
return null;
}
- @Override
- public UxContext getUxContext() {
- return uxContext;
- }
-
- @Override
- public String getUid() {
- return uid;
- }
-
@Override
public void navigateTo(String state) {
- exception = null;
+// exception = null;
String title = setState(state);
if (title != null)
doRefresh();
}
@Override
- public void sendEvent(String topic, Map<String, Object> properties) {
- if (properties == null)
- properties = new HashMap<>();
- if (properties.containsKey(CMS_VIEW_UID_PROPERTY) && !properties.get(CMS_VIEW_UID_PROPERTY).equals(uid))
- throw new IllegalArgumentException("Property " + CMS_VIEW_UID_PROPERTY + " is set to another CMS view uid ("
- + properties.get(CMS_VIEW_UID_PROPERTY) + ") then " + uid);
- properties.put(CMS_VIEW_UID_PROPERTY, uid);
- eventAdmin.sendEvent(new Event(topic, properties));
+ public CmsEventBus getCmsEventBus() {
+ return cmsWebApp.getCmsEventBus();
+ }
+
+ @Override
+ public CmsApp getCmsApp() {
+ return cmsWebApp.getCmsApp();
}
@Override
return cmsSession;
}
- @Override
- public Object getData(String key) {
- if (ui != null) {
- return ui.getData(key);
- } else {
- throw new IllegalStateException("UI is not initialized");
- }
- }
-
- @Override
- public void setData(String key, Object value) {
- if (ui != null) {
- ui.setData(key, value);
- } else {
- throw new IllegalStateException("UI is not initialized");
- }
- }
-
/*
* EntryPoint IMPLEMENTATION
*/
}
return shell;
}
-
- public void setEventAdmin(EventAdmin eventAdmin) {
- this.eventAdmin = eventAdmin;
- }
-
}