Improve CMS web app lifecycle.
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 19 Jul 2021 11:15:33 +0000 (13:15 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 19 Jul 2021 11:15:33 +0000 (13:15 +0200)
org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebApp.java
org.argeo.cms.ui/src/org/argeo/cms/ui/AbstractCmsApp.java
org.argeo.cms.ui/src/org/argeo/cms/ui/CmsApp.java

index dda02646d973763af7619482a3a94266ea03b4f9..66333858dd933f1bb415167eba0d1eabe9f8005e 100644 (file)
@@ -19,6 +19,7 @@ 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;
 
@@ -28,6 +29,7 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
 
        private BundleContext bundleContext;
        private CmsApp cmsApp;
+       private String cmsAppId;
        private EventAdmin eventAdmin;
 
        private ServiceRegistration<ApplicationConfiguration> rwtAppReg;
@@ -38,13 +40,17 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
        public void init(BundleContext bundleContext, Map<String, String> properties) {
                this.bundleContext = bundleContext;
                contextName = properties.get(CONTEXT_NAME);
-               if (cmsApp != null)
-                       themingUpdated();
+               if (cmsApp != null) {
+                       if (cmsApp.allThemesAvailable())
+                               publishWebApp();
+               }
        }
 
        public void destroy(BundleContext bundleContext, Map<String, String> properties) {
-               if (cmsApp != null)
+               if (cmsApp != null) {
                        cmsApp.removeCmsAppListener(this);
+                       cmsApp = null;
+               }
        }
 
        @Override
@@ -110,10 +116,17 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
 
        public void setCmsApp(CmsApp cmsApp, Map<String, String> properties) {
                this.cmsApp = cmsApp;
+               this.cmsAppId = properties.get(Constants.SERVICE_PID);
                this.cmsApp.addCmsAppListener(this);
        }
 
        public void unsetCmsApp(CmsApp cmsApp, Map<String, String> 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;
@@ -121,6 +134,11 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
 
        @Override
        public void themingUpdated() {
+               if (cmsApp != null && cmsApp.allThemesAvailable())
+                       publishWebApp();
+       }
+
+       protected void publishWebApp() {
                Dictionary<String, Object> regProps = LangUtils.dict(CONTEXT_NAME, contextName);
                if (rwtAppReg != null)
                        rwtAppReg.unregister();
index e760a101820f16d87b61ccdf260045c050456a50..77cd9838305b1c14dfc2ace95a06b887a4e2b27b 100644 (file)
@@ -30,7 +30,8 @@ public abstract class AbstractCmsApp implements CmsApp {
                return themes.get(themeId);
        }
 
-       protected boolean allThemesAvailable() {
+       @Override
+       public boolean allThemesAvailable() {
                boolean themeMissing = false;
                uiNames: for (String uiName : getUiNames()) {
                        String themeId = getThemeId(uiName);
index 3e445ce7baae3d4cff00fb04b3519d92dcdb3a59..bd7b00334e223f0de673089598c1e98a63d3a737 100644 (file)
@@ -25,6 +25,8 @@ public interface CmsApp {
 
        CmsTheme getTheme(String uiName);
 
+       boolean allThemesAvailable();
+
        void addCmsAppListener(CmsAppListener listener);
 
        void removeCmsAppListener(CmsAppListener listener);