Can deploy and Argeo RAP app independently.
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 22 Sep 2020 07:57:37 +0000 (09:57 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 22 Sep 2020 07:57:37 +0000 (09:57 +0200)
org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoOfficeRapE4App.java
org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/settings/AppDeployer.java
org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/settings/ArgeoRapApp.java

index ab43845a97a85d0f3c3ef2c5b06afb4309f0ec32..6bc92fd922e5e514971bfd4556b2260f7846a4b7 100644 (file)
@@ -1,3 +1,4 @@
+
 package org.argeo.suite.e4.rap;
 
 import org.argeo.cms.e4.rap.AbstractRapE4App;
index f19220b8e600d7a2606f93327ee1dc6951b51d26..c1588119efd1a8a8ef178c8c94f5e55eec59ac1c 100644 (file)
@@ -8,21 +8,28 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.e4.rap.AbstractRapE4App;
 import org.argeo.cms.ui.util.CmsTheme;
+import org.argeo.util.LangUtils;
 import org.eclipse.rap.rwt.application.ApplicationConfiguration;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedServiceFactory;
 
+/**
+ * Managed service factory deploying Argeo RAP app based on OSGi configurations.
+ */
 public class AppDeployer implements ManagedServiceFactory {
+       public final static String CMS_THEME_BUNDLE_PROPERTY = "argeo.cms.theme.bundle";
+       public final static String DEFAULT_CMS_THEME_BUNDLE = "org.argeo.theme.argeo2";
+
        private final static Log log = LogFactory.getLog(AppDeployer.class);
        private BundleContext bundleContext;
 
        public void init(BundleContext bundleContext, Map<String, String> properties) {
                this.bundleContext = bundleContext;
 
-               deploy(findBundle("org.argeo.suite.studio", null));
-               deploy(findBundle("org.argeo.suite.docs", null));
+               deploy(findBundle("org.argeo.suite.studio", null), properties);
+               deploy(findBundle("org.argeo.suite.docs", null), properties);
        }
 
        public void destroy() {
@@ -37,13 +44,19 @@ public class AppDeployer implements ManagedServiceFactory {
        @Override
        public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
                Bundle bundle = findBundle(pid, properties);
-               deploy(bundle);
+               deploy(bundle, LangUtils.dictToStringMap(properties));
        }
 
-       protected void deploy(Bundle bundle) {
-               CmsTheme cmsTheme = new CmsTheme(bundleContext, "org.argeo.theme.argeo2");
+       protected void deploy(Bundle bundle, Map<String, String> properties) {
+               CmsTheme cmsTheme;
+               if (properties.containsKey(CMS_THEME_BUNDLE_PROPERTY)) {
+                       String cmsThemeBundle = properties.get(CMS_THEME_BUNDLE_PROPERTY);
+                       cmsTheme = new CmsTheme(bundleContext, cmsThemeBundle);
+               } else {
+                       cmsTheme = new CmsTheme(bundleContext, DEFAULT_CMS_THEME_BUNDLE);
+               }
 
-               ArgeoRapApp app = new ArgeoRapApp(bundle, cmsTheme);
+               ArgeoRapApp app = new ArgeoRapApp(bundleContext, bundle, cmsTheme);
 
                Hashtable<String, String> props = new Hashtable<String, String>();
                props.put(AbstractRapE4App.CONTEXT_NAME_PROPERTY, app.getContextName());
index 169ea6232837ae6ff79c1ab00fbd41c6741e614b..322a1bff7d773cab3038598f7631a382d073d1ca 100644 (file)
@@ -1,6 +1,10 @@
 package org.argeo.suite.e4.rap.settings;
 
+import static org.argeo.suite.e4.rap.settings.AppDeployer.CMS_THEME_BUNDLE_PROPERTY;
+import static org.argeo.suite.e4.rap.settings.AppDeployer.DEFAULT_CMS_THEME_BUNDLE;
+
 import java.util.Enumeration;
+import java.util.Map;
 
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.logging.Log;
@@ -10,23 +14,42 @@ import org.argeo.cms.ui.util.CmsTheme;
 import org.eclipse.rap.rwt.application.Application;
 import org.eclipse.rap.rwt.client.WebClient;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 
 /** Argeo RAP app. */
 public class ArgeoRapApp extends AbstractRapE4App {
        private final static Log log = LogFactory.getLog(ArgeoRapApp.class);
 
-       private Bundle bundle;
        private CmsTheme cmsTheme;
        private String baseE4xmi = "/e4xmi";
+       private Bundle bundle;
 
-       public ArgeoRapApp(Bundle bundle, CmsTheme cmsTheme) {
-               this.bundle = bundle;
+       public ArgeoRapApp(BundleContext bundleContext, Bundle bundle, CmsTheme cmsTheme) {
+               setBundleContext(bundleContext);
                this.cmsTheme = cmsTheme;
+               this.bundle = bundle;
                setLifeCycleUri("bundleclass://org.argeo.suite.e4.rap/org.argeo.suite.e4.rap.ArgeoSuiteLoginLifecycle");
                String contextName = "argeo/" + FilenameUtils.getExtension(bundle.getSymbolicName());
                setContextName(contextName);
        }
 
+       public ArgeoRapApp() {
+               setLifeCycleUri("bundleclass://org.argeo.suite.e4.rap/org.argeo.suite.e4.rap.ArgeoSuiteLoginLifecycle");
+       }
+
+       @Override
+       public void init(BundleContext bundleContext, Map<String, Object> properties) {
+               super.init(bundleContext, properties);
+               // super must be first
+               if (getBaseProperties().containsKey(CMS_THEME_BUNDLE_PROPERTY)) {
+                       String cmsThemeBundle = getBaseProperties().get(CMS_THEME_BUNDLE_PROPERTY);
+                       cmsTheme = new CmsTheme(getBundleContext(), cmsThemeBundle);
+               } else {
+                       cmsTheme = new CmsTheme(getBundleContext(), DEFAULT_CMS_THEME_BUNDLE);
+               }
+               bundle = bundleContext.getBundle();
+       }
+
        @Override
        protected void addEntryPoints(Application application) {
                if (cmsTheme != null)