use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class DynamicAttributesCache method getAttributesForMetaClass.
public Collection<CategoryAttribute> getAttributesForMetaClass(MetaClass metaClass) {
MetaClass targetMetaClass = resolveTargetMetaClass(metaClass);
Collection<Category> categories = categoriesCache.get(targetMetaClass.getName());
List<CategoryAttribute> categoryAttributes = new ArrayList<>();
for (Category category : categories) {
categoryAttributes.addAll(Collections2.filter(category.getCategoryAttrs(), new Predicate<CategoryAttribute>() {
@Override
public boolean apply(@Nullable CategoryAttribute input) {
return input != null && StringUtils.isNotBlank(input.getCode());
}
}));
}
return categoryAttributes;
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class DynamicAttributesUtils method getDynamicAttributeValueAsString.
/**
* For collection dynamic attributes the method returns a list of formatted collection items joined with the comma,
* for non-collection dynamic attribute a formatted value is returned
*/
public static String getDynamicAttributeValueAsString(MetaProperty metaProperty, Object value) {
CategoryAttribute categoryAttribute = getCategoryAttribute(metaProperty);
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
if (categoryAttribute.getIsCollection()) {
if (value instanceof Collection) {
List<String> valuesList = ((Collection<Object>) value).stream().map(item -> metadataTools.format(item, metaProperty)).collect(Collectors.toList());
return Joiner.on(", ").join(valuesList);
}
}
return metadataTools.format(value, metaProperty);
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class AbstractComponentGenerationStrategy method createStringField.
protected Component createStringField(ComponentGenerationContext context, MetaPropertyPath mpp) {
TextInputField textField = null;
Element xmlDescriptor = context.getXmlDescriptor();
if (xmlDescriptor != null) {
final String rows = xmlDescriptor.attributeValue("rows");
if (!StringUtils.isEmpty(rows)) {
TextArea textArea = componentsFactory.createComponent(TextArea.class);
textArea.setRows(Integer.parseInt(rows));
textField = textArea;
}
}
if (DynamicAttributesUtils.isDynamicAttribute(context.getProperty()) && mpp != null) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(mpp.getMetaProperty());
if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.STRING && categoryAttribute.getRowsCount() != null && categoryAttribute.getRowsCount() > 1) {
TextArea textArea = componentsFactory.createComponent(TextArea.class);
textArea.setRows(categoryAttribute.getRowsCount());
textField = textArea;
}
}
if (textField == null) {
textField = componentsFactory.createComponent(TextField.class);
}
setDatasource(textField, context);
String maxLength = xmlDescriptor != null ? xmlDescriptor.attributeValue("maxLength") : null;
if (StringUtils.isNotEmpty(maxLength)) {
((TextInputField.MaxLengthLimited) textField).setMaxLength(Integer.parseInt(maxLength));
}
return textField;
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class DataGridEditorComponentGenerationStrategy method createEntityField.
@Override
protected Field createEntityField(ComponentGenerationContext context, MetaPropertyPath mpp) {
CollectionDatasource optionsDatasource = null;
if (DynamicAttributesUtils.isDynamicAttribute(mpp.getMetaProperty())) {
DynamicAttributesMetaProperty metaProperty = (DynamicAttributesMetaProperty) mpp.getMetaProperty();
CategoryAttribute attribute = metaProperty.getAttribute();
if (Boolean.TRUE.equals(attribute.getLookup())) {
DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.class);
optionsDatasource = dynamicAttributesGuiTools.createOptionsDatasourceForLookup(metaProperty.getRange().asClass(), attribute.getJoinClause(), attribute.getWhereClause());
}
}
PickerField pickerField;
if (optionsDatasource == null) {
pickerField = componentsFactory.createComponent(PickerField.class);
setDatasource(pickerField, context);
pickerField.addLookupAction();
if (DynamicAttributesUtils.isDynamicAttribute(mpp.getMetaProperty())) {
DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.class);
DynamicAttributesMetaProperty dynamicAttributesMetaProperty = (DynamicAttributesMetaProperty) mpp.getMetaProperty();
dynamicAttributesGuiTools.initEntityPickerField(pickerField, dynamicAttributesMetaProperty.getAttribute());
}
PickerField.LookupAction lookupAction = (PickerField.LookupAction) pickerField.getActionNN(PickerField.LookupAction.NAME);
// Opening lookup screen in another mode will close editor
lookupAction.setLookupScreenOpenType(WindowManager.OpenType.DIALOG);
// In case of adding special logic for lookup screen opened from DataGrid editor
lookupAction.setLookupScreenParams(ParamsMap.of("dataGridEditor", true));
boolean actionsByMetaAnnotations = ComponentsHelper.createActionsByMetaAnnotations(pickerField);
if (!actionsByMetaAnnotations) {
pickerField.addClearAction();
}
} else {
LookupPickerField lookupPickerField = componentsFactory.createComponent(LookupPickerField.class);
setDatasource(lookupPickerField, context);
lookupPickerField.setOptionsDatasource(optionsDatasource);
pickerField = lookupPickerField;
ComponentsHelper.createActionsByMetaAnnotations(pickerField);
}
return pickerField;
}
use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class RuntimePropertiesFrame method createFieldsForAttributes.
protected java.util.List<FieldGroup.FieldConfig> createFieldsForAttributes(FieldGroup newRuntimeFieldGroup) {
@SuppressWarnings("unchecked") Collection<DynamicAttributesMetaProperty> metaProperties = rds.getPropertiesFilteredByCategory();
java.util.List<FieldGroup.FieldConfig> fields = new ArrayList<>();
for (DynamicAttributesMetaProperty property : metaProperties) {
FieldGroup.FieldConfig field = newRuntimeFieldGroup.createField(property.getName());
field.setProperty(property.getName());
CategoryAttribute attribute = property.getAttribute();
if (attribute != null) {
field.setCaption(attribute.getName());
if (StringUtils.isNotBlank(attribute.getWidth())) {
field.setWidth(attribute.getWidth());
} else {
field.setWidth(fieldWidth);
}
} else {
field.setCaption(property.getName());
field.setWidth(fieldWidth);
}
fields.add(field);
}
return fields;
}
Aggregations