Skip to content

Commit

Permalink
#6662 fixed checkbox group code interaction (#6692)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmitusinski authored and scottdraves committed Jan 22, 2018
1 parent 4c4192c commit 8b2e873
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.twosigma.beakerx.widgets.strings.Label;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -56,6 +57,17 @@ public void setHorizontal(final Boolean horizontal) {
this.horizontal = horizontal;
}

@Override
public List<String> formatValue(final Object value) {
List<String> result = new ArrayList<>();
if (value instanceof Object[]) {
result = Arrays.stream((Object[]) value).map(i -> (String) i).collect(Collectors.toList());
} else if (value instanceof List) {
result = (List<String>) value;
}
return result;
}

@Override
public String getLabel() {
return this.label.getValue();
Expand All @@ -75,6 +87,14 @@ private Collection<String> getValues() {
return this.checkboxes.stream().map(EasyFormComponent::getWidget).filter(BoolWidget::getValue).map(ValueWidget::getDescription).collect(Collectors.toList());
}

@Override
public void setValue(Object value) {
List<String> descList = (ArrayList<String>) value;
checkboxes.stream()
.map(c -> c.getWidget())
.forEach(w -> w.setValue(descList.contains(w.getDescription())));
}

public void setValues(Collection<String> values) {
values.forEach(item -> {
CheckBoxWidget checkbox = new CheckBoxWidget(item);
Expand All @@ -89,4 +109,9 @@ private void createWidget(Collection<String> values) {
this.widget = new HBox(asList(label, rightSide));
}

@Override
protected boolean checkValue(Object value) {
return value instanceof Object[] || value instanceof List;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<String> formatValue(final Object value) {

@Override
protected boolean checkValue(Object value) {
return !(value instanceof String);
return value instanceof Object[] || value instanceof List;
}

}

0 comments on commit 8b2e873

Please sign in to comment.