andi-huber commented on code in PR #3584:
URL: https://github.com/apache/causeway/pull/3584#discussion_r3305577383
##########
viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/widgets/themepicker/ThemeChooser.java:
##########
@@ -67,95 +59,81 @@ public ThemeChooser(final String id) {
super(id);
}
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getWicketViewerSettings().themes().showChooser());
+ }
+
@Override
protected void onInitialize() {
super.onInitialize();
+ initializeActiveThemeFromCookie();
+ Wkt.ajaxEnable(this);
+ }
- if(getThemeSupport()==null) {
- super.getMetaModelContext().injectServicesInto(this);
- }
+ @Override
+ protected void onBeforeRender() {
+ super.onBeforeRender();
+ buildGui();
+ }
- final ActiveThemeProvider activeThemeProvider =
getActiveThemeProvider();
- if(activeThemeProvider.getClass() == SessionThemeProvider.class) {
- initializeActiveThemeFromCookie();
- } else {
- // if anything other than the default, then we do NOT initialize
- // (on the assumption that it is a persistent store and we don't
want to overwrite).
- }
+ void buildGui() {
+ final String activeThemeName = getActiveTheme().name();
- Wkt.listViewAdd(this, "themes",
getThemeSupport().getEnabledThemeNames(), item->{
+ Wkt.listViewAdd(this, "themes", themeSupport().availableNames(),
item->{
final String themeName = item.getModelObject();
- if
(themeName.equals(getActiveThemeProvider().getActiveTheme().name())) {
- item.add(AttributeModifier.append("class", "active"));
- }
-
// use Ajax link because Link's url looks like /object:3 and this
confuses the browser
- Wkt.add(item,
- Wkt.link("themeLink", target->{
- setActiveTheme(themeName);
- saveActiveThemeToCookie(themeName);
- target.add(getPage()); // repaint the whole page
- })
- .setBody(Model.of(themeName)));
+ var link = Wkt.link("themeLink", target->{
+ setActiveTheme(themeName);
+ target.add(getPage()); // repaint the whole page
+ })
+ .setBody(Model.of(themeName));
+
+ if (themeName.equals(activeThemeName)) {
+ Wkt.cssAppend(link, "active");
+ }
+ Wkt.add(item, link);
});
-
}
- private void saveActiveThemeToCookie(final String themeName) {
- CookieUtils cookieUtils = new CookieUtils();
- cookieUtils.save(CAUSEWAY_THEME_COOKIE_NAME, themeName);
+ @Override
+ protected void onComponentTag(final ComponentTag tag) {
+ super.onComponentTag(tag);
+ tag.setName("li");
+ Attributes.addClass(tag, "dropdown");
}
- private void initializeActiveThemeFromCookie() {
- CookieUtils cookieUtils = new CookieUtils();
- String activeTheme = cookieUtils.load(CAUSEWAY_THEME_COOKIE_NAME);
- if (!Strings.isEmpty(activeTheme)) {
+ // -- HELPER
- var isAvailable =
getThemeSupport().getThemeProvider().available().stream()
- .anyMatch(theme->activeTheme.equals(theme.name()));
-
- if(isAvailable) {
- setActiveTheme(activeTheme);
- }
- }
- }
-
- private void setActiveTheme(final String activeTheme) {
- IBootstrapSettings bootstrapSettings = Bootstrap.getSettings();
- ITheme theme =
getThemeSupport().getThemeProvider().byName(activeTheme);
- getActiveThemeProvider().setActiveTheme(theme);
- if (theme instanceof BootstrapThemeTheme) {
Review Comment:
There seems some correlation with removing this code snipped and static
resource lookup errors now being reported. However, testing this against
demo-app has no visual issues.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]