Search in sources :

Example 1 with DynamicAttributesMetaProperty

use of com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty 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;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) DynamicAttributesMetaProperty(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)

Example 2 with DynamicAttributesMetaProperty

use of com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty 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;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) DynamicAttributesMetaProperty(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty) ArrayList(java.util.ArrayList)

Example 3 with DynamicAttributesMetaProperty

use of com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty in project cuba by cuba-platform.

the class AbstractComponentGenerationStrategy method createEntityField.

protected Component createEntityField(ComponentGenerationContext context, MetaPropertyPath mpp) {
    String linkAttribute = null;
    Element xmlDescriptor = context.getXmlDescriptor();
    if (xmlDescriptor != null) {
        linkAttribute = xmlDescriptor.attributeValue("link");
    }
    if (!Boolean.parseBoolean(linkAttribute)) {
        CollectionDatasource optionsDatasource = context.getOptionsDatasource();
        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);
            if (mpp.getMetaProperty().getType() == MetaProperty.Type.ASSOCIATION) {
                pickerField.addLookupAction();
                if (DynamicAttributesUtils.isDynamicAttribute(mpp.getMetaProperty())) {
                    DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.class);
                    DynamicAttributesMetaProperty dynamicAttributesMetaProperty = (DynamicAttributesMetaProperty) mpp.getMetaProperty();
                    dynamicAttributesGuiTools.initEntityPickerField(pickerField, dynamicAttributesMetaProperty.getAttribute());
                }
                boolean actionsByMetaAnnotations = ComponentsHelper.createActionsByMetaAnnotations(pickerField);
                if (!actionsByMetaAnnotations) {
                    pickerField.addClearAction();
                }
            } else {
                pickerField.addOpenAction();
                pickerField.addClearAction();
            }
        } else {
            LookupPickerField lookupPickerField = componentsFactory.createComponent(LookupPickerField.class);
            setDatasource(lookupPickerField, context);
            lookupPickerField.setOptionsDatasource(optionsDatasource);
            pickerField = lookupPickerField;
            ComponentsHelper.createActionsByMetaAnnotations(pickerField);
        }
        if (xmlDescriptor != null) {
            String captionProperty = xmlDescriptor.attributeValue("captionProperty");
            if (StringUtils.isNotEmpty(captionProperty)) {
                pickerField.setCaptionMode(CaptionMode.PROPERTY);
                pickerField.setCaptionProperty(captionProperty);
            }
        }
        return pickerField;
    } else {
        EntityLinkField linkField = componentsFactory.createComponent(EntityLinkField.class);
        setDatasource(linkField, context);
        setLinkFieldAttributes(linkField, context);
        return linkField;
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) DynamicAttributesMetaProperty(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Element(org.dom4j.Element) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)

Aggregations

DynamicAttributesMetaProperty (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty)3 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 DynamicAttributesGuiTools (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)2 ArrayList (java.util.ArrayList)1 Element (org.dom4j.Element)1