Improve CMS theming.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / web / MinimalWebApp.java
index 31c93af22c92dc0dbe1e2b03ffe49747de0e175d..188391c42e68d4b736d444fc88e374a06d142946 100644 (file)
@@ -1,12 +1,11 @@
 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 static org.argeo.cms.ui.util.BundleCmsTheme.CMS_THEME_BUNDLE_PROPERTY;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import org.argeo.cms.ui.util.CmsTheme;
+import org.argeo.cms.ui.util.BundleCmsTheme;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.application.Application;
 import org.eclipse.rap.rwt.application.ApplicationConfiguration;
@@ -16,14 +15,12 @@ import org.osgi.framework.BundleContext;
 /** Lightweight web app using only RWT and not the whole Eclipse platform. */
 public class MinimalWebApp implements ApplicationConfiguration {
 
-       private CmsTheme theme;
+       private BundleCmsTheme theme;
 
        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);
+                       theme = new BundleCmsTheme(bundleContext, cmsThemeBundle);
                }
        }
 
@@ -38,12 +35,22 @@ public class MinimalWebApp implements ApplicationConfiguration {
 
        @Override
        public void configure(Application application) {
-               theme.apply(application);
+               if (theme != null)
+                       WebThemeUtils.apply(application, theme);
 
                Map<String, String> properties = new HashMap<>();
-               properties.put(WebClient.THEME_ID, RWT.DEFAULT_THEME_ID);
-               properties.put(WebClient.HEAD_HTML, theme.getAdditionalHeaders());
+               if (theme != null) {
+                       properties.put(WebClient.THEME_ID, theme.getThemeId());
+                       properties.put(WebClient.HEAD_HTML, theme.getHtmlHeaders());
+               } else {
+                       properties.put(WebClient.THEME_ID, RWT.DEFAULT_THEME_ID);
+               }
                addEntryPoints(application, properties);
 
        }
+
+       public void setTheme(BundleCmsTheme theme) {
+               this.theme = theme;
+       }
+
 }