Skip to content

Commit

Permalink
Add display hint annotation for table display on code root container.
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcsmith-net committed Jul 8, 2024
1 parent d0f1a5f commit de5957e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ControlInfo> controls;
private final OrderedMap<String, PortInfo> ports;
private final List<String> protocols;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -222,6 +224,7 @@ public CodeRootContainer<D> getComponent() {
public static class Connector<D extends CodeRootContainerDelegate> extends CodeRoot.Connector<D> {

private CodeContainerSupport.TypesInfo typesInfo;
private PMap displayHint;

public Connector(CodeFactory.Task<D> task, D delegate) {
super(task, delegate);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -46,4 +50,21 @@ public final Stream<String> 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();

}

}

0 comments on commit de5957e

Please sign in to comment.