Search in sources :

Example 1 with SelectorFieldBaseDefinition

use of org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorFieldBaseDefinition in project kie-wb-common by kiegroup.

the class SelectorOptionsProvider method getSelectorData.

@Override
public SelectorData getSelectorData(FormRenderingContext context) {
    SelectorData data = new SelectorData<>();
    Map<Object, String> values = new HashMap<>();
    Object selectedValue = null;
    if (context.getModel() instanceof SelectorFieldBaseDefinition) {
        SelectorFieldBaseDefinition selector = (SelectorFieldBaseDefinition) context.getModel();
        selectedValue = selector.getDefaultValue();
        List<SelectorOption> options = selector.getOptions();
        options.forEach(option -> values.put(option.getValue(), option.getText()));
        if (!values.containsKey(selectedValue)) {
            selectedValue = null;
            selector.setDefaultValue(null);
        }
    }
    data.setValues(values);
    data.setSelectedValue(selectedValue);
    return data;
}
Also used : SelectorOption(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorOption) HashMap(java.util.HashMap) SelectorFieldBaseDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorFieldBaseDefinition) SelectorData(org.kie.workbench.common.forms.dynamic.model.config.SelectorData)

Aggregations

HashMap (java.util.HashMap)1 SelectorData (org.kie.workbench.common.forms.dynamic.model.config.SelectorData)1 SelectorFieldBaseDefinition (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorFieldBaseDefinition)1 SelectorOption (org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.selectors.SelectorOption)1