Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Inline inline(Collection<? extends Object> values) {

Assert.notNull(values, "Values must not be null!");

return new Inline(values, null, null, null, null, null);
return new Inline(values, null, null, null, null, null, null);
}

/**
Expand All @@ -76,7 +76,7 @@ public static Remote remote(Link link) {

Assert.notNull(link, "Link must not be null!");

return new Remote(link, null, null, null, null, null);
return new Remote(link, null, null, null, null, null, null);
}

/**
Expand Down Expand Up @@ -127,15 +127,19 @@ public static Remote remote(String href) {
@Nullable
Object getSelectedValue();

@Nullable
Object getSelectedValues();

public static abstract class AbstractHalFormsOptions<T extends AbstractHalFormsOptions<T>>
implements HalFormsOptions {

private final @Nullable String promptField, valueField;
private final @Nullable Long minItems, maxItems;
private final @Nullable Object selectedValue;
private final @Nullable Object selectedValues;

protected AbstractHalFormsOptions(@Nullable String promptRef, @Nullable String valueRef, @Nullable Long minItems,
@Nullable Long maxItems, @Nullable Object selectedValue) {
@Nullable Long maxItems, @Nullable Object selectedValue, @Nullable Object selectedValues) {

Assert.isTrue(minItems == null || minItems >= 0, "MinItems must be greater than or equal to 0!");

Expand All @@ -144,6 +148,7 @@ protected AbstractHalFormsOptions(@Nullable String promptRef, @Nullable String v
this.minItems = minItems;
this.maxItems = maxItems;
this.selectedValue = selectedValue;
this.selectedValues = selectedValues;
}

/*
Expand Down Expand Up @@ -201,6 +206,13 @@ public Object getSelectedValue() {
return selectedValue;
}

@Nullable
@Override
@JsonProperty
public Object getSelectedValues() {
return selectedValues;
}

/**
* Configures the given field to be used as prompt field.
*
Expand All @@ -213,7 +225,7 @@ public T withPromptField(String promptField) {
throw new IllegalArgumentException("Prompt field has to either be null or actually have text!");
}

return with(promptField, valueField, minItems, maxItems, selectedValue);
return with(promptField, valueField, minItems, maxItems, selectedValue, selectedValues);
}

/**
Expand All @@ -228,7 +240,7 @@ public T withValueField(String valueField) {
throw new IllegalArgumentException("Value field has to either be null or actually have text!");
}

return with(promptField, valueField, minItems, maxItems, selectedValue);
return with(promptField, valueField, minItems, maxItems, selectedValue, selectedValues);
}

/**
Expand All @@ -243,7 +255,7 @@ public T withMinItems(Long minItems) {
throw new IllegalArgumentException("minItems has to be null or greater or equal to zero!");
}

return with(promptField, valueField, minItems, maxItems, selectedValue);
return with(promptField, valueField, minItems, maxItems, selectedValue, selectedValues);
}

/**
Expand All @@ -258,17 +270,29 @@ public T withMaxItems(@Nullable Long maxItems) {
throw new IllegalArgumentException("maxItems has to be null or greater than zero!");
}

return with(promptField, valueField, minItems, maxItems, selectedValue);
return with(promptField, valueField, minItems, maxItems, selectedValue, selectedValues);
}

/**
* Configured the value to be initially selected
*
* @param value
* @return
* @deprecated Use {@link #withSelectedValues(Object)} instead
*/
@Deprecated(forRemoval = true)
public T withSelectedValue(@Nullable Object value) {
return with(promptField, valueField, minItems, maxItems, value);
return with(promptField, valueField, minItems, maxItems, value, selectedValues);
}

/**
* Configured the values to be initially selected
*
* @param values
* @return
*/
public T withSelectedValues(@Nullable Object values) {
return with(promptField, valueField, minItems, maxItems, selectedValue, values);
}

/**
Expand All @@ -281,7 +305,7 @@ public T withSelectedValue(@Nullable Object value) {
* @return
*/
protected abstract T with(@Nullable String promptRef, @Nullable String valueRef, @Nullable Long minItems,
@Nullable Long maxItems, @Nullable Object selectedValue);
@Nullable Long maxItems, @Nullable Object selectedValue, @Nullable Object selectedValues);
}

public static class Inline extends AbstractHalFormsOptions<Inline> {
Expand All @@ -294,9 +318,9 @@ public static class Inline extends AbstractHalFormsOptions<Inline> {
* @param valueRef
*/
private Inline(Collection<? extends Object> values, @Nullable String promptRef, @Nullable String valueRef,
@Nullable Long minItems, @Nullable Long maxItems, @Nullable Object selectedValue) {
@Nullable Long minItems, @Nullable Long maxItems, @Nullable Object selectedValue, @Nullable Object selectedValues) {

super(promptRef, valueRef, minItems, maxItems, selectedValue);
super(promptRef, valueRef, minItems, maxItems, selectedValue, selectedValues);

Assert.notNull(values, "Values must not be null!");

Expand All @@ -319,8 +343,8 @@ public Collection<? extends Object> getInline() {
*/
@Override
protected Inline with(@Nullable String promptRef, @Nullable String valueRef, @Nullable Long minItems,
@Nullable Long maxItems, @Nullable Object selectedValue) {
return new Inline(inline, promptRef, valueRef, minItems, maxItems, selectedValue);
@Nullable Long maxItems, @Nullable Object selectedValue, @Nullable Object selectedValues) {
return new Inline(inline, promptRef, valueRef, minItems, maxItems, selectedValue, selectedValues);
}
}

Expand All @@ -334,9 +358,9 @@ public static class Remote extends AbstractHalFormsOptions<Remote> {
private final Link link;

private Remote(Link link, @Nullable String promptRef, @Nullable String valueRef, @Nullable Long minItems,
@Nullable Long maxItems, @Nullable Object selectedValue) {
@Nullable Long maxItems, @Nullable Object selectedValue, @Nullable Object selectedValues) {

super(promptRef, valueRef, minItems, maxItems, selectedValue);
super(promptRef, valueRef, minItems, maxItems, selectedValue, selectedValues);

Assert.notNull(link, "Link must not be null!");

Expand All @@ -359,8 +383,8 @@ public Link getLink() {
*/
@Override
protected Remote with(@Nullable String promptRef, @Nullable String valueRef, @Nullable Long minItems,
@Nullable Long maxItems, @Nullable Object selectedValue) {
return new Remote(link, promptRef, valueRef, minItems, maxItems, selectedValue);
@Nullable Long maxItems, @Nullable Object selectedValue, @Nullable Object selectedValues) {
return new Remote(link, promptRef, valueRef, minItems, maxItems, selectedValue, selectedValues);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ void rendersFullInlineOptions() {
.withPromptField("my-prompt-field")
.withValueField("my-value-field")
.withMinItems(2L)
.withMaxItems(3L);
.withMaxItems(3L)
.withSelectedValues(List.of("bar", "baz"));

getCuriedMapper()
.assertSerializes(options)
Expand All @@ -478,6 +479,7 @@ void rendersFullInlineOptions() {
assertThat(result.read("$.valueField", String.class)).isEqualTo("my-value-field");
assertThat(result.read("$.minItems", Long.class)).isEqualTo(2L);
assertThat(result.read("$.maxItems", Long.class)).isEqualTo(3L);
assertThat(result.read("$.selectedValues", List.class)).isEqualTo(List.of("bar", "baz"));
});
}

Expand All @@ -490,7 +492,8 @@ void rendersFullRemoteOptions() {
.withPromptField("my-prompt-field")
.withValueField("my-value-field")
.withMinItems(2L)
.withMaxItems(3L);
.withMaxItems(3L)
.withSelectedValues(List.of("bar", "baz"));

getCuriedMapper()
.assertSerializes(options)
Expand All @@ -503,6 +506,7 @@ void rendersFullRemoteOptions() {
assertThat(result.read("$.valueField", String.class)).isEqualTo("my-value-field");
assertThat(result.read("$.minItems", Long.class)).isEqualTo(2L);
assertThat(result.read("$.maxItems", Long.class)).isEqualTo(3L);
assertThat(result.read("$.selectedValues", List.class)).isEqualTo(List.of("bar", "baz"));
});

}
Expand Down
Loading