You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/12/12 11:12:58 UTC

[isis] branch master updated: ISIS-2882: not every ComponentType is mandatory

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/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new af554cc  ISIS-2882: not every ComponentType is mandatory
af554cc is described below

commit af554cc0d86b77d93867cde52ff810b6355e2aae
Author: andi-huber <ah...@apache.org>
AuthorDate: Sun Dec 12 12:12:45 2021 +0100

    ISIS-2882: not every ComponentType is mandatory
---
 .../apache/isis/applib/annotation/Optionality.java    |  4 +++-
 .../viewer/common/model/components/ComponentType.java | 19 ++++++++++++++++++-
 .../components/ComponentFactoryRegistryDefault.java   |  5 +++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/api/applib/src/main/java/org/apache/isis/applib/annotation/Optionality.java b/api/applib/src/main/java/org/apache/isis/applib/annotation/Optionality.java
index fcbc434..63f059a 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/annotation/Optionality.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/annotation/Optionality.java
@@ -63,6 +63,8 @@ public enum Optionality {
      * Ignore the value provided by this annotation (meaning that the framework will keep searching, in meta
      * annotations or superclasses/interfaces).
      */
-    NOT_SPECIFIED
+    NOT_SPECIFIED;
+
+    public boolean isOptional() { return this == OPTIONAL; }
 
 }
diff --git a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/components/ComponentType.java b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/components/ComponentType.java
index 888be23..0018f85 100644
--- a/viewers/common/src/main/java/org/apache/isis/viewer/common/model/components/ComponentType.java
+++ b/viewers/common/src/main/java/org/apache/isis/viewer/common/model/components/ComponentType.java
@@ -20,8 +20,12 @@ package org.apache.isis.viewer.common.model.components;
 
 import org.springframework.lang.Nullable;
 
+import org.apache.isis.applib.annotation.Optionality;
 import org.apache.isis.core.metamodel.commons.StringExtensions;
 
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
 /**
  * Enumerates the different types of UI <i>Components</i> that can be constructed
  * using component factories.
@@ -32,6 +36,7 @@ import org.apache.isis.core.metamodel.commons.StringExtensions;
  * somewhat larger (such as {@link ComponentType#ENTITY}, representing an
  * entity, with its actions, properties and collections).
  */
+@RequiredArgsConstructor
 public enum ComponentType {
 
     /**
@@ -119,7 +124,7 @@ public enum ComponentType {
     /**
      * A collection of entities (the value of)
      */
-    COLLECTION_CONTENTS_EXPORT,
+    COLLECTION_CONTENTS_EXPORT(Optionality.OPTIONAL),
     /**
      * A link to an entity.
      */
@@ -153,6 +158,10 @@ public enum ComponentType {
      */
     FOOTER;
 
+    private ComponentType() {
+        this.optionality = Optionality.MANDATORY;
+    }
+
     @Override
     public String toString() {
         return getId();
@@ -169,6 +178,12 @@ public enum ComponentType {
         return StringExtensions.toCamelCase(name());
     }
 
+    /**
+     * Whether there must be a ComponentFactory for this type.
+     */
+    @Getter
+    private final Optionality optionality;
+
     @Nullable
     public static ComponentType lookup(final String id) {
         for (final ComponentType componentType : values()) {
@@ -179,4 +194,6 @@ public enum ComponentType {
         return null;
     }
 
+
+
 }
diff --git a/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/registries/components/ComponentFactoryRegistryDefault.java b/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/registries/components/ComponentFactoryRegistryDefault.java
index b3aaba9..36ee05b 100644
--- a/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/registries/components/ComponentFactoryRegistryDefault.java
+++ b/viewers/wicket/viewer/src/main/java/org/apache/isis/viewer/wicket/viewer/registries/components/ComponentFactoryRegistryDefault.java
@@ -109,6 +109,11 @@ implements ComponentFactoryRegistry {
 
     private void ensureAllComponentTypesRegistered() {
         for (val componentType : ComponentType.values()) {
+
+            if(componentType.getOptionality().isOptional()) {
+                continue;
+            }
+
             if (componentFactoriesByType.getOrElseEmpty(componentType).isEmpty()) {
                 throw new IllegalStateException("No component factories registered for " + componentType);
             }