From de5957ef8a794147e3255785f26ef04d5cc47675 Mon Sep 17 00:00:00 2001 From: Neil C Smith Date: Mon, 8 Jul 2024 17:43:49 +0100 Subject: [PATCH] Add display hint annotation for table display on code root container. --- .../org/praxislive/core/ComponentInfo.java | 7 +++++++ .../praxislive/code/CodeRootContainer.java | 15 +++++++++++++ .../code/CodeRootContainerDelegate.java | 21 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/praxiscore-api/src/main/java/org/praxislive/core/ComponentInfo.java b/praxiscore-api/src/main/java/org/praxislive/core/ComponentInfo.java index 7b6378b7..e386f4d2 100644 --- a/praxiscore-api/src/main/java/org/praxislive/core/ComponentInfo.java +++ b/praxiscore-api/src/main/java/org/praxislive/core/ComponentInfo.java @@ -69,6 +69,13 @@ public class ComponentInfo extends PMap.MapBasedValue { */ public static final String KEY_DYNAMIC = "dynamic"; + /** + * Optional key for adding a hint how the component, and its children if a + * container, should be displayed. Value must be a map. The {@code type} key + * is mandatory. Other keys may be used to provide additional configuration. + */ + public static final String KEY_DISPLAY_HINT = "display-hint"; + private final OrderedMap controls; private final OrderedMap ports; private final List protocols; diff --git a/praxiscore-code/src/main/java/org/praxislive/code/CodeRootContainer.java b/praxiscore-code/src/main/java/org/praxislive/code/CodeRootContainer.java index ebba04d2..99a5b6b2 100644 --- a/praxiscore-code/src/main/java/org/praxislive/code/CodeRootContainer.java +++ b/praxiscore-code/src/main/java/org/praxislive/code/CodeRootContainer.java @@ -42,7 +42,9 @@ import org.praxislive.core.VetoException; import org.praxislive.core.protocols.ContainerProtocol; import org.praxislive.core.protocols.SerializableProtocol; +import org.praxislive.core.types.PArray; import org.praxislive.core.types.PMap; +import org.praxislive.core.types.PString; /** * A {@link Root} container instance that is rewritable at runtime. The @@ -222,6 +224,7 @@ public CodeRootContainer getComponent() { public static class Connector extends CodeRoot.Connector { private CodeContainerSupport.TypesInfo typesInfo; + private PMap displayHint; public Connector(CodeFactory.Task task, D delegate) { super(task, delegate); @@ -255,12 +258,24 @@ protected void analyseMethod(Method method) { if (typesInfo == null) { typesInfo = CodeContainerSupport.analyseMethod(method, true); } + var hint = method.getAnnotation(CodeRootContainerDelegate.DisplayTable.class); + if (hint != null) { + displayHint = PMap.of( + "type", "table", + "properties", Stream.of(hint.properties()) + .map(PString::of) + .collect(PArray.collector()) + ); + } } @Override protected void buildBaseComponentInfo(Info.ComponentInfoBuilder cmp) { super.buildBaseComponentInfo(cmp); cmp.merge(ContainerProtocol.API_INFO); + if (displayHint != null) { + cmp.property(ComponentInfo.KEY_DISPLAY_HINT, displayHint); + } } private ControlDescriptor containerControl(String id, ControlInfo info) { diff --git a/praxiscore-code/src/main/java/org/praxislive/code/CodeRootContainerDelegate.java b/praxiscore-code/src/main/java/org/praxislive/code/CodeRootContainerDelegate.java index d39f687c..1f2e610c 100644 --- a/praxiscore-code/src/main/java/org/praxislive/code/CodeRootContainerDelegate.java +++ b/praxiscore-code/src/main/java/org/praxislive/code/CodeRootContainerDelegate.java @@ -21,6 +21,10 @@ */ package org.praxislive.code; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.stream.Stream; /** @@ -46,4 +50,21 @@ public final Stream children() { } } + /** + * Annotation to add hint to display the component and its children in a + * table when editing. + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface DisplayTable { + + /** + * Array of properties to display as table columns. + * + * @return property columns + */ + String[] properties(); + + } + }