You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2019/10/01 07:18:25 UTC
[isis] 04/04: ISIS-2086: converts 'isis.viewer.wicket.themes.*' (3
of em) to type-safe config
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2086
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 6e246a81200115846e481979b43ba303c3dbf335
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Oct 1 08:18:03 2019 +0100
ISIS-2086: converts 'isis.viewer.wicket.themes.*' (3 of em) to type-safe config
---
.../org/apache/isis/config/IsisConfiguration.java | 23 ++++++++++++++++---
.../additional-spring-configuration-metadata.json | 9 ++++++++
.../themepicker/IsisWicketThemeSupport.java | 19 ++++------------
.../themepicker/IsisWicketThemeSupportDefault.java | 26 ++++++++--------------
4 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/core/config/src/main/java/org/apache/isis/config/IsisConfiguration.java b/core/config/src/main/java/org/apache/isis/config/IsisConfiguration.java
index be292b1..5772864 100644
--- a/core/config/src/main/java/org/apache/isis/config/IsisConfiguration.java
+++ b/core/config/src/main/java/org/apache/isis/config/IsisConfiguration.java
@@ -20,9 +20,7 @@ package org.apache.isis.config;
import lombok.Data;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.StringTokenizer;
+import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -655,6 +653,25 @@ public class IsisConfiguration {
private String encryptionKey;
}
+ private final Themes themes = new Themes();
+ @Data
+ public static class Themes {
+ /**
+ * A comma separated list of enabled theme names, as defined by https://bootswatch.com.
+ */
+ private List<String> enabled = new ArrayList<>();
+
+ /**
+ * The initial theme to use.
+ *
+ * <p>
+ * Expected to be in the list of {@link #getEnabled()} themes.
+ * </p>
+ */
+ private String initial = "Flatly";
+
+ private String provider = "org.apache.isis.viewer.wicket.ui.components.widgets.themepicker.IsisWicketThemeSupportDefault";
+ }
private final WhereAmI whereAmI = new WhereAmI();
@Data
public static class WhereAmI {
diff --git a/core/config/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/core/config/src/main/resources/META-INF/additional-spring-configuration-metadata.json
index 8c63e9b..51d9684 100644
--- a/core/config/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ b/core/config/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -47,6 +47,15 @@
}
],
"hints": [
+ {
+ "name": "isis.viewer.wicket.themes.provider",
+ "providers": [{
+ "name": "class-reference",
+ "parameters": {
+ "target": "org.apache.isis.viewer.wicket.ui.components.widgets.themepicker.IsisWicketThemeSupport"
+ }
+ }]
+ }
]
}
diff --git a/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/themepicker/IsisWicketThemeSupport.java b/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/themepicker/IsisWicketThemeSupport.java
index 6ce7cd8..bb471a2 100644
--- a/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/themepicker/IsisWicketThemeSupport.java
+++ b/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/themepicker/IsisWicketThemeSupport.java
@@ -37,16 +37,6 @@ public interface IsisWicketThemeSupport {
ThemeProvider getThemeProvider();
List<String> getEnabledThemeNames();
- // -- CONSTANTS
-
- /**
- * A configuration setting which value could be a comma separated list of enabled theme names
- */
- static final String ENABLED_THEMES_KEY = "isis.viewer.wicket.themes.enabled";
- static final String DEFAULT_THEME_KEY = "isis.viewer.wicket.themes.initial";
- static final String THEME_SUPPORT_PROVIDER_KEY = "isis.viewer.wicket.themes.provider";
- static final Class<? extends IsisWicketThemeSupport> THEME_SUPPORT_DEFAULT_CLASS =
- IsisWicketThemeSupportDefault.class;
// -- LOOKUP
@@ -59,10 +49,9 @@ public interface IsisWicketThemeSupport {
/*private*/ static IsisWicketThemeSupport createInstance() {
- val configuration = IsisContext.getConfigurationLegacy();
+ val configuration = IsisContext.getConfiguration();
- val themeSupportClassName = configuration.getString(
- THEME_SUPPORT_PROVIDER_KEY, THEME_SUPPORT_DEFAULT_CLASS.getName());
+ val themeSupportClassName = configuration.getViewer().getWicket().getThemes().getProvider();
try {
@@ -74,10 +63,10 @@ public interface IsisWicketThemeSupport {
val log = org.apache.logging.log4j.LogManager.getLogger(IsisWicketThemeSupport.class);
log.warn("Could not instantiate configured theme support class '{}', defaulting to '{}'",
themeSupportClassName,
- THEME_SUPPORT_DEFAULT_CLASS.getName());
+ IsisWicketThemeSupportDefault.class.getName());
}
- return (IsisWicketThemeSupport) InstanceUtil.createInstance(THEME_SUPPORT_DEFAULT_CLASS);
+ return (IsisWicketThemeSupport) InstanceUtil.createInstance(IsisWicketThemeSupportDefault.class);
}
diff --git a/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/themepicker/IsisWicketThemeSupportDefault.java b/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/themepicker/IsisWicketThemeSupportDefault.java
index e58e7e8..a3eab17 100644
--- a/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/themepicker/IsisWicketThemeSupportDefault.java
+++ b/core/viewer-wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/themepicker/IsisWicketThemeSupportDefault.java
@@ -30,6 +30,7 @@ import com.google.common.collect.Iterables;
import org.apache.isis.commons.internal.base._Lazy;
import org.apache.isis.commons.internal.base._NullSafe;
import org.apache.isis.commons.internal.collections._Lists;
+import org.apache.isis.config.IsisConfiguration;
import org.apache.isis.config.IsisConfigurationLegacy;
import org.apache.isis.runtime.system.context.IsisContext;
@@ -46,10 +47,7 @@ import lombok.extern.log4j.Log4j2;
@Log4j2
public class IsisWicketThemeSupportDefault implements IsisWicketThemeSupport {
- private static final BootswatchTheme BOOTSWATCH_THEME_DEFAULT = BootswatchTheme.Flatly;
-
- private final _Lazy<ThemeProvider> themeProvider = _Lazy.of(this::createThemeProvider);
-
+ private final _Lazy<ThemeProvider> themeProvider = _Lazy.of(this::createThemeProvider);
@Override
public ThemeProvider getThemeProvider() {
@@ -83,13 +81,12 @@ public class IsisWicketThemeSupportDefault implements IsisWicketThemeSupport {
private ThemeProvider createThemeProvider() {
- final String themeName = getConfiguration().getString(
- DEFAULT_THEME_KEY, BOOTSWATCH_THEME_DEFAULT.name());
+ final String themeName = getConfiguration().getViewer().getWicket().getThemes().getInitial();
BootswatchTheme bootswatchTheme;
try {
bootswatchTheme = BootswatchTheme.valueOf(themeName);
} catch(Exception ex) {
- bootswatchTheme = BOOTSWATCH_THEME_DEFAULT;
+ bootswatchTheme = BootswatchTheme.Flatly;
log.warn("Did not recognise configured bootswatch theme '{}', defaulting to '{}'",
themeName,
bootswatchTheme);
@@ -126,7 +123,7 @@ public class IsisWicketThemeSupportDefault implements IsisWicketThemeSupport {
/**
* Filters which themes to show in the drop up by using the provided values
- * in {@value #ENABLED_THEMES_KEY}
+ * in {@link IsisConfiguration.Viewer.Wicket.Themes#getEnabled()}
*
* @param allThemes All available themes
* @return A list of all enabled themes
@@ -134,17 +131,12 @@ public class IsisWicketThemeSupportDefault implements IsisWicketThemeSupport {
private List<String> filterThemes(List<String> allThemes) {
List<String> enabledThemes;
- final String[] enabledThemesArray = getConfiguration().getList(ENABLED_THEMES_KEY);
+ final String[] enabledThemesArray = getConfiguration().getViewer().getWicket().getThemes().getEnabled().toArray(new String[]{});
if (enabledThemesArray.length > 0) {
final Set<String> enabledThemesSet = _NullSafe.stream(enabledThemesArray)
.collect(Collectors.toSet());
- Iterable<String> enabled = Iterables.filter(allThemes, new Predicate<String>() {
- @Override
- public boolean apply(String themeName) {
- return enabledThemesSet.contains(themeName);
- }
- });
+ Iterable<String> enabled = allThemes.stream().filter(enabledThemesSet::contains).collect(Collectors.toList());
enabledThemes = _Lists.newArrayList(enabled);
} else {
@@ -154,8 +146,8 @@ public class IsisWicketThemeSupportDefault implements IsisWicketThemeSupport {
return enabledThemes;
}
- private IsisConfigurationLegacy getConfiguration() {
- return IsisContext.getConfigurationLegacy();
+ private IsisConfiguration getConfiguration() {
+ return IsisContext.getConfiguration();
}
}