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);
}
}
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;
}
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;
}
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);
}
}
});
}
}
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;
}
Aggregations