Search in sources :

Example 16 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class EntityLogBrowser method fillAttributes.

protected void fillAttributes(String metaClassName, LoggedEntity item, boolean editable) {
    clearAttributes();
    setSelectAllCheckBox(false);
    if (metaClassName != null) {
        MetaClass metaClass = metadata.getExtendedEntities().getEffectiveMetaClass(metadata.getClassNN(metaClassName));
        List<MetaProperty> metaProperties = new ArrayList<>(metaClass.getProperties());
        selectAllCheckBox.setEditable(editable);
        Set<LoggedAttribute> enabledAttr = null;
        if (item != null)
            enabledAttr = item.getAttributes();
        for (MetaProperty property : metaProperties) {
            if (allowLogProperty(property, null)) {
                if (metadata.getTools().isEmbedded(property)) {
                    MetaClass embeddedMetaClass = property.getRange().asClass();
                    for (MetaProperty embeddedProperty : embeddedMetaClass.getProperties()) {
                        if (allowLogProperty(embeddedProperty, null)) {
                            addAttribute(enabledAttr, String.format("%s.%s", property.getName(), embeddedProperty.getName()), editable);
                        }
                    }
                } else {
                    addAttribute(enabledAttr, property.getName(), editable);
                }
            }
        }
        Collection<CategoryAttribute> attributes = dynamicAttributes.getAttributesForMetaClass(metaClass);
        if (attributes != null) {
            for (CategoryAttribute categoryAttribute : attributes) {
                MetaPropertyPath propertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, categoryAttribute);
                MetaProperty property = propertyPath.getMetaProperty();
                if (allowLogProperty(property, categoryAttribute)) {
                    addAttribute(enabledAttr, property.getName(), editable);
                }
            }
        }
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 17 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class DesktopAbstractOptionsField method setDatasource.

@Override
public void setDatasource(Datasource datasource, String property) {
    this.datasource = datasource;
    if (datasource == null) {
        setValue(null);
        return;
    }
    MetaClass metaClass = datasource.getMetaClass();
    resolveMetaPropertyPath(metaClass, property);
    itemChangeListener = e -> {
        if (updatingInstance)
            return;
        Object value = InstanceUtils.getValueEx(e.getItem(), metaPropertyPath.getPath());
        updateComponent(value);
        fireChangeListeners(value);
    };
    // noinspection unchecked
    datasource.addItemChangeListener(new WeakItemChangeListener(datasource, itemChangeListener));
    itemPropertyChangeListener = e -> {
        if (updatingInstance)
            return;
        if (e.getProperty().equals(metaPropertyPath.toString())) {
            updateComponent(e.getValue());
            fireChangeListeners(e.getValue());
        }
    };
    // noinspection unchecked
    datasource.addItemPropertyChangeListener(new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener));
    initRequired(metaPropertyPath);
    if (metaProperty.getRange().isEnum()) {
        Enumeration enumeration = metaProperty.getRange().asEnumeration();
        @SuppressWarnings("unchecked") Class<Enum> javaClass = enumeration.getJavaClass();
        setOptionsList(Arrays.asList(javaClass.getEnumConstants()));
        setCaptionMode(CaptionMode.ITEM);
    }
    if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
        CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
        if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) {
            setOptionsMap(categoryAttribute.getLocalizedEnumerationMap());
        }
    }
    if ((datasource.getState() == Datasource.State.VALID) && (datasource.getItem() != null)) {
        Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
        updateComponent(newValue);
        fireChangeListeners(newValue);
    }
    if (metaProperty.isReadOnly()) {
        setEditable(false);
    }
    handleFilteredAttributes(this, this.datasource, metaPropertyPath);
    securityItemChangeListener = e -> handleFilteredAttributes(this, this.datasource, metaPropertyPath);
    // noinspection unchecked
    this.datasource.addItemChangeListener(new WeakItemChangeListener(this.datasource, securityItemChangeListener));
    initBeanValidator();
}
Also used : WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) Enumeration(com.haulmont.chile.core.datatypes.Enumeration) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaClass(com.haulmont.chile.core.model.MetaClass) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener)

Example 18 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class BulkEditorWindow method getManagedFields.

protected List<ManagedField> getManagedFields(MetaClass metaClass) {
    List<ManagedField> managedFields = new ArrayList<>();
    // sort Fields
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        if (isManagedAttribute(metaClass, metaProperty)) {
            String propertyCaption = messageTools.getPropertyCaption(metaClass, metaProperty.getName());
            if (!metadataTools.isEmbedded(metaProperty)) {
                managedFields.add(new ManagedField(metaProperty.getName(), metaProperty, propertyCaption, null));
            } else {
                List<ManagedField> nestedFields = getManagedFields(metaProperty, metaProperty.getName(), propertyCaption);
                if (nestedFields.size() > 0) {
                    managedEmbeddedProperties.add(metaProperty.getName());
                }
                managedFields.addAll(nestedFields);
            }
        }
    }
    if (loadDynamicAttributes) {
        List<CategoryAttribute> categoryAttributes = (List<CategoryAttribute>) dynamicAttributes.getAttributesForMetaClass(metaClass);
        if (!categoryAttributes.isEmpty()) {
            for (CategoryAttribute attribute : categoryAttributes) {
                MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, attribute);
                String propertyCaption = attribute.getLocaleName();
                if (isManagedDynamicAttribute(metaClass, metaPropertyPath.getMetaProperty())) {
                    managedFields.add(new ManagedField(metaPropertyPath.getMetaProperty().getName(), metaPropertyPath.getMetaProperty(), propertyCaption, null));
                }
            }
        }
    }
    return managedFields;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 19 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class AttributeEditor method fillAttributeCode.

protected void fillAttributeCode() {
    CategoryAttribute attribute = getItem();
    if (StringUtils.isBlank(attribute.getCode()) && StringUtils.isNotBlank(attribute.getName())) {
        String categoryName = StringUtils.EMPTY;
        if (attribute.getCategory() != null) {
            categoryName = StringUtils.defaultString(attribute.getCategory().getName());
        }
        attribute.setCode(StringUtils.deleteWhitespace(categoryName + attribute.getName()));
    }
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute)

Example 20 with CategoryAttribute

use of com.haulmont.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.

the class CategoryAttrsFrame method initMoveButtons.

protected void initMoveButtons() {
    Action moveUpAction = new ItemTrackingAction("moveUp").withCaption("").withHandler(event -> {
        Set<CategoryAttribute> selected = categoryAttrsTable.getSelected();
        if (selected.isEmpty())
            return;
        CategoryAttribute currentAttr = selected.iterator().next();
        UUID prevId = categoryAttrsDs.prevItemId(currentAttr.getId());
        if (prevId == null)
            return;
        Integer tmp = currentAttr.getOrderNo();
        CategoryAttribute prevAttr = categoryAttrsDs.getItemNN(prevId);
        currentAttr.setOrderNo(prevAttr.getOrderNo());
        prevAttr.setOrderNo(tmp);
        sortTableByOrderNo();
    });
    ((Button) getComponentNN("moveUp")).setAction(moveUpAction);
    Action moveDownAction = new ItemTrackingAction("moveDown").withCaption("").withHandler(event -> {
        Set<CategoryAttribute> selected = categoryAttrsTable.getSelected();
        if (selected.isEmpty())
            return;
        CategoryAttribute currentAttr = selected.iterator().next();
        UUID nextId = categoryAttrsDs.nextItemId(currentAttr.getId());
        if (nextId == null)
            return;
        Integer tmp = currentAttr.getOrderNo();
        CategoryAttribute nextAttr = categoryAttrsDs.getItemNN(nextId);
        currentAttr.setOrderNo(nextAttr.getOrderNo());
        nextAttr.setOrderNo(tmp);
        sortTableByOrderNo();
    });
    ((Button) getComponentNN("moveDown")).setAction(moveDownAction);
    categoryAttrsTable.addAction(moveUpAction);
    categoryAttrsTable.addAction(moveDownAction);
}
Also used : RefreshAction(com.haulmont.cuba.gui.components.actions.RefreshAction) RemoveAction(com.haulmont.cuba.gui.components.actions.RemoveAction) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) ItemTrackingAction(com.haulmont.cuba.gui.components.actions.ItemTrackingAction) UUID(java.util.UUID)

Aggregations

CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)34 MetaClass (com.haulmont.chile.core.model.MetaClass)15 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)12 MetaProperty (com.haulmont.chile.core.model.MetaProperty)10 Nullable (javax.annotation.Nullable)6 Element (org.dom4j.Element)5 DynamicAttributesMetaProperty (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty)4 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)4 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)4 DynamicAttributesGuiTools (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools)4 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)3 Joiner (com.google.common.base.Joiner)2 Strings (com.google.common.base.Strings)2 Dom4j (com.haulmont.bali.util.Dom4j)2 Enumeration (com.haulmont.chile.core.datatypes.Enumeration)2 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)2 Category (com.haulmont.cuba.core.entity.Category)2 Entity (com.haulmont.cuba.core.entity.Entity)2 AppBeans (com.haulmont.cuba.core.global.AppBeans)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2