This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/master by this push:
     new 64263ab218 CAUSEWAY-3743: adds TimeZoneChoiceProvider SPI to customize 
zone choices
64263ab218 is described below

commit 64263ab218df3791db4f3b66de1f557e1fae45f4
Author: andi-huber <[email protected]>
AuthorDate: Sat May 18 07:03:00 2024 +0200

    CAUSEWAY-3743: adds TimeZoneChoiceProvider SPI to customize zone choices
    
    - for e.g. Wicket Viewer Login
---
 .../semantics/TemporalCharacteristicsProvider.java | 34 +-----------
 ...csProvider.java => TimeZoneChoiceProvider.java} | 62 ++++++----------------
 .../wicket/ui/pages/login/SignInPanelAbstract.java |  9 +++-
 3 files changed, 26 insertions(+), 79 deletions(-)

diff --git 
a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalCharacteristicsProvider.java
 
b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalCharacteristicsProvider.java
index 88d5805fec..597597ed94 100644
--- 
a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalCharacteristicsProvider.java
+++ 
b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalCharacteristicsProvider.java
@@ -18,15 +18,7 @@
  */
 package org.apache.causeway.applib.value.semantics;
 
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.ZoneOffset;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import lombok.val;
-
-public interface TemporalCharacteristicsProvider {
+public interface TemporalCharacteristicsProvider extends 
TimeZoneChoiceProvider {
 
     static enum TemporalCharacteristic {
 
@@ -70,27 +62,5 @@ public interface TemporalCharacteristicsProvider {
 
     TemporalCharacteristic getTemporalCharacteristic();
     OffsetCharacteristic getOffsetCharacteristic();
-
-    /**
-     * For temporal value editing, provides the list of available time zones 
to choose from.
-     */
-    default List<ZoneId> getAvailableZoneIds() {
-        return ZoneId.getAvailableZoneIds().stream()
-            .sorted()
-            .map(ZoneId::of)
-            .collect(Collectors.toList());
-    }
-
-    /**
-     * For temporal value editing, provides the list of available offsets to 
choose from.
-     */
-    default List<ZoneOffset> getAvailableOffsets() {
-        val now = LocalDateTime.now();
-        return getAvailableZoneIds().stream()
-            .map(ZoneId::getRules)
-            .flatMap(zoneIdRules->zoneIdRules.getValidOffsets(now).stream())
-            .sorted()
-            .distinct()
-            .collect(Collectors.toList());
-    }
+    
 }
diff --git 
a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalCharacteristicsProvider.java
 
b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TimeZoneChoiceProvider.java
similarity index 63%
copy from 
api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalCharacteristicsProvider.java
copy to 
api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TimeZoneChoiceProvider.java
index 88d5805fec..9109deb2fd 100644
--- 
a/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TemporalCharacteristicsProvider.java
+++ 
b/api/applib/src/main/java/org/apache/causeway/applib/value/semantics/TimeZoneChoiceProvider.java
@@ -26,51 +26,15 @@ import java.util.stream.Collectors;
 
 import lombok.val;
 
-public interface TemporalCharacteristicsProvider {
-
-    static enum TemporalCharacteristic {
-
-        /**
-         * Temporal value type has no date information, just time.
-         */
-        TIME_ONLY,
-
-        /**
-         * Temporal value type has no time information, just date.
-         */
-        DATE_ONLY,
-
-        /**
-         * Temporal value type has both date and time information.
-         */
-        DATE_TIME
-    }
-
-    static enum OffsetCharacteristic {
-
-        /**
-         * Temporal value type has no time-zone data.
-         */
-        LOCAL,
-
-        /**
-         * Temporal value type has time-zone offset data.
-         */
-        OFFSET,
-
-        /**
-         * Temporal value type has time-zone id data.
-         */
-        ZONED;
-
-        public boolean isLocal() {return this == LOCAL;}
-        public boolean isOffset() {return this == OFFSET;}
-        public boolean isZoned() {return this == ZONED;}
-    }
-
-    TemporalCharacteristic getTemporalCharacteristic();
-    OffsetCharacteristic getOffsetCharacteristic();
-
+/**
+ * When implemented by a service {@link #getAvailableZoneIds()} 
+ * can be customized to limit the time-zone choices 
+ * as e.g. offered by the <i>Wicket Viewer<i> login page.
+ * 
+ * @since 2.1, 3.1
+ */
+public interface TimeZoneChoiceProvider {
+    
     /**
      * For temporal value editing, provides the list of available time zones 
to choose from.
      */
@@ -93,4 +57,12 @@ public interface TemporalCharacteristicsProvider {
             .distinct()
             .collect(Collectors.toList());
     }
+    
+    /**
+     * Returns the fallback implementation, which provides all ZoneIds known 
to the JVM.
+     */
+    static TimeZoneChoiceProvider fallback() {
+        return new TimeZoneChoiceProvider() {};
+    }
+    
 }
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/pages/login/SignInPanelAbstract.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/pages/login/SignInPanelAbstract.java
index 3cecaef481..e77919133f 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/pages/login/SignInPanelAbstract.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/pages/login/SignInPanelAbstract.java
@@ -37,9 +37,9 @@ import 
org.apache.wicket.request.resource.JavaScriptResourceReference;
 import org.apache.wicket.request.resource.ResourceReference;
 import org.apache.wicket.util.cookies.CookieUtils;
 
+import org.apache.causeway.applib.value.semantics.TimeZoneChoiceProvider;
 import org.apache.causeway.commons.internal.base._Strings;
 import org.apache.causeway.core.metamodel.context.HasMetaModelContext;
-import 
org.apache.causeway.core.metamodel.valuesemantics.temporal.ZonedDateTimeValueSemantics;
 import org.apache.causeway.viewer.wicket.ui.util.Wkt;
 
 import lombok.Getter;
@@ -266,7 +266,7 @@ implements HasMetaModelContext {
 
             add(Wkt.dropDownChoice("timezone",
                     new PropertyModel<ZoneId>(SignInPanelAbstract.this, 
"timezone"),
-                    new ZonedDateTimeValueSemantics().getAvailableZoneIds())
+                    getTimeZoneChoiceProvider().getAvailableZoneIds())
                 .setRequired(true)
                 .setMarkupId(TIME_ZONE_SELECT));
 
@@ -309,6 +309,11 @@ implements HasMetaModelContext {
             }
         }
 
+        private TimeZoneChoiceProvider getTimeZoneChoiceProvider() {
+            return 
getMetaModelContext().getServiceRegistry().lookupService(TimeZoneChoiceProvider.class)
+                    .orElseGet(TimeZoneChoiceProvider::fallback);
+        }
+        
     }
 
     /**

Reply via email to