X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui.rap%2Fsrc%2Forg%2Fargeo%2Fcms%2Fweb%2FCmsWebApp.java;h=66333858dd933f1bb415167eba0d1eabe9f8005e;hb=c5d120d226b31b3d930fc3006c56ac9e4d29ed2a;hp=ca26c5830c7a0ad4bbf4a08928aa45a06bc53848;hpb=fea7cd546f9c04c00f961918919dd6307c32cc8e;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebApp.java b/org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebApp.java index ca26c5830..66333858d 100644 --- a/org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebApp.java +++ b/org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebApp.java @@ -15,9 +15,11 @@ 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.application.Application.OperationMode; import org.eclipse.rap.rwt.client.WebClient; import org.eclipse.swt.widgets.Display; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; import org.osgi.framework.ServiceRegistration; import org.osgi.service.event.EventAdmin; @@ -27,6 +29,7 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm private BundleContext bundleContext; private CmsApp cmsApp; + private String cmsAppId; private EventAdmin eventAdmin; private ServiceRegistration rwtAppReg; @@ -37,29 +40,35 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm public void init(BundleContext bundleContext, Map properties) { this.bundleContext = bundleContext; contextName = properties.get(CONTEXT_NAME); - if (cmsApp != null) - themingUpdated(); -// registerIfAllThemesAvailable(); + if (cmsApp != null) { + if (cmsApp.allThemesAvailable()) + publishWebApp(); + } } public void destroy(BundleContext bundleContext, Map properties) { - if (cmsApp != null) + if (cmsApp != null) { cmsApp.removeCmsAppListener(this); + cmsApp = null; + } } @Override public void configure(Application application) { + // TODO make it configurable? + // SWT compatibility is required for: + // - Browser.execute() + // - blocking dialogs + application.setOperationMode(OperationMode.SWT_COMPATIBILITY); for (String uiName : cmsApp.getUiNames()) { CmsTheme theme = cmsApp.getTheme(uiName); if (theme != null) WebThemeUtils.apply(application, theme); } -// for (CmsTheme theme : themes.values()) -// WebThemeUtils.apply(application, theme); Map properties = new HashMap<>(); addEntryPoints(application, properties); - + application.setExceptionHandler(this); } @Override @@ -83,8 +92,6 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm properties.put(WebClient.HEAD_HTML, theme.getHtmlHeaders()); } else { properties.put(WebClient.THEME_ID, RWT.DEFAULT_THEME_ID); -// if (themeId != null) -// log.warn("Theme id " + themeId + " was specified but it was not found, using default RWT theme."); } String entryPointName = !uiName.equals("") ? "/" + uiName : "/"; application.addEntryPoint(entryPointName, () -> { @@ -95,41 +102,31 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm if (log.isDebugEnabled()) log.info("Added web entry point " + (contextName != null ? "/" + contextName : "") + entryPointName); } - if (log.isDebugEnabled()) - log.debug("Published CMS web app /" + (contextName != null ? contextName : "")); +// if (log.isDebugEnabled()) +// log.debug("Published CMS web app /" + (contextName != null ? contextName : "")); } -// private void registerIfAllThemesAvailable() { -// boolean themeMissing = false; -// uiNames: for (String uiName : cmsApp.getUiNames()) { -// String themeId = cmsApp.getThemeId(uiName); -// if (RWT.DEFAULT_THEME_ID.equals(themeId)) -// continue uiNames; -// if (!themes.containsKey(themeId)) { -// themeMissing = true; -// break uiNames; -// } -// } -// if (!themeMissing) { -// Dictionary regProps = LangUtils.dict(CONTEXT_NAME, contextName); -// if (bundleContext != null) { -// rwtAppReg = bundleContext.registerService(ApplicationConfiguration.class, this, regProps); -// log.info("Published CMS web app /" + (contextName != null ? contextName : "")); -// } -// } -// } - CmsApp getCmsApp() { return cmsApp; } + BundleContext getBundleContext() { + return bundleContext; + } + public void setCmsApp(CmsApp cmsApp, Map properties) { this.cmsApp = cmsApp; + this.cmsAppId = properties.get(Constants.SERVICE_PID); this.cmsApp.addCmsAppListener(this); -// registerIfAllThemesAvailable(); } public void unsetCmsApp(CmsApp cmsApp, Map properties) { + String cmsAppId = properties.get(Constants.SERVICE_PID); + if (!cmsAppId.equals(this.cmsAppId)) + return; + if (this.cmsApp != null) { + this.cmsApp.removeCmsAppListener(this); + } if (rwtAppReg != null) rwtAppReg.unregister(); this.cmsApp = null; @@ -137,6 +134,11 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm @Override public void themingUpdated() { + if (cmsApp != null && cmsApp.allThemesAvailable()) + publishWebApp(); + } + + protected void publishWebApp() { Dictionary regProps = LangUtils.dict(CONTEXT_NAME, contextName); if (rwtAppReg != null) rwtAppReg.unregister();