Search in sources :

Example 1 with ListOptions

use of io.jmix.ui.component.data.options.ListOptions in project jmix by jmix-framework.

the class DynAttrComponentGenerationStrategy method setComboBoxOptionsLoader.

protected void setComboBoxOptionsLoader(ComboBox lookupField, AttributeDefinition attribute, ContainerValueSource valueSource) {
    InstanceContainer<?> container = valueSource.getContainer();
    Object entity = container.getItemOrNull();
    if (entity != null) {
        List options = optionsLoader.loadOptions(entity, attribute);
        // noinspection unchecked
        lookupField.setOptions(new ListOptions(options));
    }
    container.addItemChangeListener(e -> {
        List options = optionsLoader.loadOptions(e.getItem(), attribute);
        // noinspection unchecked
        lookupField.setOptions(new ListOptions(options));
    });
    List<String> dependsOnAttributeCodes = attribute.getConfiguration().getDependsOnAttributeCodes();
    if (dependsOnAttributeCodes != null && !dependsOnAttributeCodes.isEmpty()) {
        container.addItemPropertyChangeListener(e -> {
            if (dependsOnAttributeCodes.contains(e.getProperty())) {
                List options = optionsLoader.loadOptions(e.getItem(), attribute);
                // noinspection unchecked
                lookupField.setOptions(new ListOptions(options));
                if (!options.contains(lookupField.getValue())) {
                    // noinspection unchecked
                    lookupField.setValue(null);
                }
            }
        });
    }
}
Also used : ListOptions(io.jmix.ui.component.data.options.ListOptions)

Example 2 with ListOptions

use of io.jmix.ui.component.data.options.ListOptions in project jmix by jmix-framework.

the class DynAttrComponentGenerationStrategy method setValuesPickerOptionsLoader.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void setValuesPickerOptionsLoader(ValuesPicker valuesPicker, AttributeDefinition attribute, ContainerValueSource valueSource) {
    InstanceContainer<?> container = valueSource.getContainer();
    Object entity = container.getItemOrNull();
    if (entity != null) {
        List options = optionsLoader.loadOptions(entity, attribute);
        ((ValuesSelectAction) valuesPicker.getActionNN(ValuesSelectAction.ID)).setOptions(new ListOptions(options));
    }
    container.addItemChangeListener(e -> {
        List options = optionsLoader.loadOptions(e.getItem(), attribute);
        ((ValuesSelectAction) valuesPicker.getActionNN(ValuesSelectAction.ID)).setOptions(new ListOptions(options));
    });
    List<String> dependsOnAttributeCodes = attribute.getConfiguration().getDependsOnAttributeCodes();
    if (dependsOnAttributeCodes != null && !dependsOnAttributeCodes.isEmpty()) {
        container.addItemPropertyChangeListener(e -> {
            if (dependsOnAttributeCodes.contains(e.getProperty())) {
                List options = optionsLoader.loadOptions(e.getItem(), attribute);
                ((ValuesSelectAction) valuesPicker.getActionNN(ValuesSelectAction.ID)).setOptions(new ListOptions(options));
                if (!options.contains(valuesPicker.getValue())) {
                    valuesPicker.setValue(null);
                }
            }
        });
    }
}
Also used : ValuesSelectAction(io.jmix.ui.action.valuespicker.ValuesSelectAction) ListOptions(io.jmix.ui.component.data.options.ListOptions)

Aggregations

ListOptions (io.jmix.ui.component.data.options.ListOptions)2 ValuesSelectAction (io.jmix.ui.action.valuespicker.ValuesSelectAction)1