Improve minimal web app.
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 27 Sep 2020 10:45:52 +0000 (12:45 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 27 Sep 2020 10:45:52 +0000 (12:45 +0200)
org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsTheme.java
org.argeo.cms.ui/src/org/argeo/cms/web/MinimalWebApp.java

index 8b1f874f7de4c6d45b29c25bf6f850410b2e2852..a20b1a228ff6c39dc13ce2a97dfc3932aaddb8b4 100644 (file)
@@ -32,6 +32,10 @@ import org.osgi.framework.BundleContext;
  * <code>/ ** /*.{png,gif,jpeg,...}</code>.<br>
  */
 public class CmsTheme {
+       public final static String DEFAULT_CMS_THEME_BUNDLE = "org.argeo.theme.argeo2";
+
+       public final static String CMS_THEME_BUNDLE_PROPERTY = "argeo.cms.theme.bundle";
+
        private final static Log log = LogFactory.getLog(CmsTheme.class);
 
        private String themeId;
@@ -43,13 +47,13 @@ public class CmsTheme {
 
        private String basePath;
        private String cssPath;
+       private final Bundle themeBundle;
 
        public CmsTheme(BundleContext bundleContext) {
                this(bundleContext, null);
        }
 
        public CmsTheme(BundleContext bundleContext, String symbolicName) {
-               Bundle themeBundle;
                if (symbolicName == null) {
                        themeBundle = bundleContext.getBundle();
 //                     basePath = "/theme/";
@@ -93,12 +97,12 @@ public class CmsTheme {
                                continue resources; // skip maven output
                        application.addResource(name, resources.get(name));
                        if (log.isTraceEnabled())
-                               log.trace("Added resource " + name);
+                               log.trace("Theme " + themeBundle + ": added resource " + name);
                }
                for (String name : css.keySet()) {
                        application.addStyleSheet(themeId, name, css.get(name));
                        if (log.isDebugEnabled())
-                               log.debug("Added RAP CSS " + name);
+                               log.debug("Theme " + themeBundle + ": added RAP CSS " + name);
                }
        }
 
index b4af7595d231604e8f07e3696faebb92ace33eb0..31c93af22c92dc0dbe1e2b03ffe49747de0e175d 100644 (file)
@@ -1,18 +1,16 @@
 package org.argeo.cms.web;
 
+import static org.argeo.cms.ui.util.CmsTheme.CMS_THEME_BUNDLE_PROPERTY;
+import static org.argeo.cms.ui.util.CmsTheme.DEFAULT_CMS_THEME_BUNDLE;
+
 import java.util.HashMap;
 import java.util.Map;
 
 import org.argeo.cms.ui.util.CmsTheme;
 import org.eclipse.rap.rwt.RWT;
-import org.eclipse.rap.rwt.application.AbstractEntryPoint;
 import org.eclipse.rap.rwt.application.Application;
 import org.eclipse.rap.rwt.application.ApplicationConfiguration;
 import org.eclipse.rap.rwt.client.WebClient;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
 import org.osgi.framework.BundleContext;
 
 /** Lightweight web app using only RWT and not the whole Eclipse platform. */
@@ -20,14 +18,24 @@ public class MinimalWebApp implements ApplicationConfiguration {
 
        private CmsTheme theme;
 
-       public void init(BundleContext bundleContext) {
-               theme = new CmsTheme(bundleContext);
+       public void init(BundleContext bundleContext, Map<String, Object> properties) {
+               if (properties.containsKey(CMS_THEME_BUNDLE_PROPERTY)) {
+                       String cmsThemeBundle = properties.get(CMS_THEME_BUNDLE_PROPERTY).toString();
+                       theme = new CmsTheme(bundleContext, cmsThemeBundle);
+               } else {
+                       theme = new CmsTheme(bundleContext, DEFAULT_CMS_THEME_BUNDLE);
+               }
        }
 
        public void destroy() {
 
        }
 
+       /** To be overridden. Does nothing by default. */
+       protected void addEntryPoints(Application application, Map<String, String> properties) {
+
+       }
+
        @Override
        public void configure(Application application) {
                theme.apply(application);
@@ -35,19 +43,7 @@ public class MinimalWebApp implements ApplicationConfiguration {
                Map<String, String> properties = new HashMap<>();
                properties.put(WebClient.THEME_ID, RWT.DEFAULT_THEME_ID);
                properties.put(WebClient.HEAD_HTML, theme.getAdditionalHeaders());
-               application.addEntryPoint("/test", TextEntryPoint.class, properties);
+               addEntryPoints(application, properties);
 
        }
-
-       static class TextEntryPoint extends AbstractEntryPoint {
-               private static final long serialVersionUID = 2245808564950897823L;
-
-               @Override
-               protected void createContents(Composite parent) {
-                       parent.setLayout(new GridLayout());
-                       new Label(parent, SWT.NONE).setText("Hello World!");
-               }
-
-       }
-
 }