Make icon sizes configurable
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 21 Sep 2022 08:50:19 +0000 (10:50 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 21 Sep 2022 08:50:19 +0000 (10:50 +0200)
org.argeo.cms/src/org/argeo/cms/osgi/BundleCmsTheme.java

index de7eec8c2a39e19ea93faa507a8b1ef6fc2aa4b8..3443d73a67408f0f60a50c7bd2c0b6a87aa18f93 100644 (file)
@@ -31,11 +31,17 @@ import org.osgi.framework.BundleContext;
  * <code>/ ** /*.{png,gif,jpeg,...}</code>.<br>
  */
 public class BundleCmsTheme implements CmsTheme {
-       public final static String DEFAULT_CMS_THEME_BUNDLE = "org.argeo.theme.argeo2";
+//     public final static String DEFAULT_CMS_THEME_BUNDLE = "org.argeo.theme.argeo2";
 
-       public final static String CMS_THEME_PROPERTY = "argeo.cms.theme";
+//     public final static String CMS_THEME_PROPERTY = "argeo.cms.theme";
+       @Deprecated
        public final static String CMS_THEME_BUNDLE_PROPERTY = "argeo.cms.theme.bundle";
 
+       /** Declared theme ID, to be used by OSGi services to reference it as parent. */
+       public final static String THEME_ID_PROPERTY = "themeId";
+       public final static String SMALL_ICON_SIZE_PROPERTY = "smallIconSize";
+       public final static String BIG_ICON_SIZE_PROPERTY = "bigIconSize";
+
        private final static String HEADER_CSS = "header.css";
        private final static String FONTS_TXT = "fonts.txt";
        private final static String BODY_HTML = "body.html";
@@ -45,6 +51,8 @@ public class BundleCmsTheme implements CmsTheme {
        private CmsTheme parentTheme;
 
        private String themeId;
+       private String declaredThemeId;;
+
        private Set<String> webCssPaths = new TreeSet<>();
        private Set<String> rapCssPaths = new TreeSet<>();
        private Set<String> swtCssPaths = new TreeSet<>();
@@ -71,6 +79,12 @@ public class BundleCmsTheme implements CmsTheme {
        }
 
        public void init(BundleContext bundleContext, Map<String, String> properties) {
+               declaredThemeId = properties.get(THEME_ID_PROPERTY);
+               if (properties.containsKey(SMALL_ICON_SIZE_PROPERTY))
+                       smallIconSize = Integer.valueOf(properties.get(SMALL_ICON_SIZE_PROPERTY));
+               if (properties.containsKey(BIG_ICON_SIZE_PROPERTY))
+                       smallIconSize = Integer.valueOf(properties.get(BIG_ICON_SIZE_PROPERTY));
+
                initResources(bundleContext, null);
        }
 
@@ -103,6 +117,10 @@ public class BundleCmsTheme implements CmsTheme {
 //             swtCssPath = "/swt/";
 //             this.themeId = RWT.DEFAULT_THEME_ID;
                this.themeId = themeBundle.getSymbolicName();
+               if (declaredThemeId != null && !declaredThemeId.equals(themeId))
+                       throw new IllegalArgumentException(
+                                       "Declared theme id " + declaredThemeId + " is different from " + themeId);
+
                webCssPaths = addCss(themeBundle, "/css/");
                rapCssPaths = addCss(themeBundle, "/rap/");
                swtCssPaths = addCss(themeBundle, "/swt/");
@@ -373,4 +391,12 @@ public class BundleCmsTheme implements CmsTheme {
                this.parentTheme = parentTheme;
        }
 
+       public void setSmallIconSize(Integer smallIconSize) {
+               this.smallIconSize = smallIconSize;
+       }
+
+       public void setBigIconSize(Integer bigIconSize) {
+               this.bigIconSize = bigIconSize;
+       }
+
 }