Search in sources :

Example 1 with ValuesSelectAction

use of io.jmix.ui.action.valuespicker.ValuesSelectAction in project jmix by jmix-framework.

the class CategoryAttrsEdit method initDependsOnAttributesField.

@SuppressWarnings("unchecked")
protected void initDependsOnAttributesField() {
    ValuesSelectAction<CategoryAttribute> selectAction = (ValuesSelectAction<CategoryAttribute>) dependsOnAttributesField.getActionNN("select");
    selectAction.setOptions(new ListEntityOptions<>(getAttributesOptions(), metadata));
    if (getEditedEntity().getConfiguration() != null && getEditedEntity().getConfiguration().getDependsOnAttributeCodes() != null) {
        dependsOnAttributesField.setValue(getAttributesOptions().stream().filter(o -> getEditedEntity().getConfiguration().getDependsOnAttributeCodes().contains(o.getCode())).collect(Collectors.toList()));
    }
    CrudEntityContext crudEntityContext = new CrudEntityContext(configurationDc.getEntityMetaClass());
    accessManager.applyRegisteredConstraints(crudEntityContext);
    if (!crudEntityContext.isUpdatePermitted()) {
        dependsOnAttributesField.setEnabled(false);
        dependsOnAttributesFieldClear.setEnabled(false);
        dependsOnAttributesFieldSelect.setEnabled(false);
    }
}
Also used : ValuesSelectAction(io.jmix.ui.action.valuespicker.ValuesSelectAction) CategoryAttribute(io.jmix.dynattr.model.CategoryAttribute) CrudEntityContext(io.jmix.core.accesscontext.CrudEntityContext)

Example 2 with ValuesSelectAction

use of io.jmix.ui.action.valuespicker.ValuesSelectAction in project jmix by jmix-framework.

the class JpqlFilterComponentGenerationStrategy method createCollectionField.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected Component createCollectionField(ComponentGenerationContext context) {
    JpqlFilterComponentGenerationContext cfContext = (JpqlFilterComponentGenerationContext) context;
    Class parameterClass = cfContext.getParameterClass();
    ValuesPicker valuesPicker = uiComponents.create(ValuesPicker.class);
    setValueSource(valuesPicker, cfContext);
    ValuesSelectAction selectAction = actions.create(ValuesSelectAction.class);
    if (Entity.class.isAssignableFrom(parameterClass)) {
        MetaClass metaClass = metadata.getClass(cfContext.getParameterClass());
        selectAction.setEntityName(metaClass.getName());
    } else if (EnumClass.class.isAssignableFrom(parameterClass)) {
        selectAction.setEnumClass(parameterClass);
    } else if (datatypeRegistry.find(parameterClass) != null) {
        Datatype datatype = datatypeRegistry.get(parameterClass);
        selectAction.setJavaClass(datatype.getJavaClass());
    }
    valuesPicker.addAction(selectAction);
    ValueClearAction valueClearAction = actions.create(ValueClearAction.class);
    valuesPicker.addAction(valueClearAction);
    return valuesPicker;
}
Also used : ValuesSelectAction(io.jmix.ui.action.valuespicker.ValuesSelectAction) ValueClearAction(io.jmix.ui.action.valuepicker.ValueClearAction) MetaClass(io.jmix.core.metamodel.model.MetaClass) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) MetaClass(io.jmix.core.metamodel.model.MetaClass) EnumClass(io.jmix.core.metamodel.datatype.impl.EnumClass) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 3 with ValuesSelectAction

use of io.jmix.ui.action.valuespicker.ValuesSelectAction in project jmix by jmix-framework.

the class DynAttrComponentGenerationStrategy method createCollectionField.

protected Component createCollectionField(ComponentGenerationContext context, AttributeDefinition attribute) {
    ValuesPicker valuesPicker = uiComponents.create(ValuesPicker.NAME);
    setValidators(valuesPicker, attribute);
    setValueSource(valuesPicker, context);
    ValuesSelectAction selectAction = actions.create(ValuesSelectAction.class);
    initValuesSelectActionByAttribute(selectAction, attribute);
    if (valuesPicker.getValueSource() instanceof ContainerValueSource && attribute.getConfiguration().isLookup()) {
        ContainerValueSource valueSource = (ContainerValueSource) valuesPicker.getValueSource();
        setValuesPickerOptionsLoader(valuesPicker, attribute, valueSource);
    }
    valuesPicker.addAction(selectAction);
    ValueClearAction valueClearAction = actions.create(ValueClearAction.class);
    valuesPicker.addAction(valueClearAction);
    return valuesPicker;
}
Also used : ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) ValuesSelectAction(io.jmix.ui.action.valuespicker.ValuesSelectAction) ValueClearAction(io.jmix.ui.action.valuepicker.ValueClearAction)

Example 4 with ValuesSelectAction

use of io.jmix.ui.action.valuespicker.ValuesSelectAction 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)

Example 5 with ValuesSelectAction

use of io.jmix.ui.action.valuespicker.ValuesSelectAction in project jmix by jmix-framework.

the class AbstractComponentGenerationStrategy method createCollectionField.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected Component createCollectionField(ComponentGenerationContext context, MetaPropertyPath mpp) {
    ValuesPicker valuesPicker = uiComponents.create(ValuesPicker.class);
    setValueSource(valuesPicker, context);
    ValuesSelectAction selectAction = actions.create(ValuesSelectAction.class);
    Range range = mpp.getRange();
    if (range.isClass()) {
        selectAction.setEntityName(range.asClass().getName());
    } else if (range.isDatatype()) {
        selectAction.setJavaClass(range.asDatatype().getJavaClass());
    } else if (range.isEnum()) {
        selectAction.setEnumClass(range.asEnumeration().getJavaClass());
    }
    valuesPicker.addAction(selectAction);
    ValueClearAction valueClearAction = actions.create(ValueClearAction.class);
    valuesPicker.addAction(valueClearAction);
    return valuesPicker;
}
Also used : ValuesSelectAction(io.jmix.ui.action.valuespicker.ValuesSelectAction) ValueClearAction(io.jmix.ui.action.valuepicker.ValueClearAction) Range(io.jmix.core.metamodel.model.Range)

Aggregations

ValuesSelectAction (io.jmix.ui.action.valuespicker.ValuesSelectAction)5 ValueClearAction (io.jmix.ui.action.valuepicker.ValueClearAction)3 CrudEntityContext (io.jmix.core.accesscontext.CrudEntityContext)1 Datatype (io.jmix.core.metamodel.datatype.Datatype)1 EnumClass (io.jmix.core.metamodel.datatype.impl.EnumClass)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 Range (io.jmix.core.metamodel.model.Range)1 CategoryAttribute (io.jmix.dynattr.model.CategoryAttribute)1 ListOptions (io.jmix.ui.component.data.options.ListOptions)1 ContainerValueSource (io.jmix.ui.component.data.value.ContainerValueSource)1