Search in sources :

Example 1 with DynamicAttributes

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

the class ConverterHelper method getActualMetaProperties.

public static List<MetaProperty> getActualMetaProperties(MetaClass metaClass, Entity entity) {
    List<MetaProperty> result = new ArrayList<MetaProperty>(metaClass.getProperties());
    if (entity instanceof BaseGenericIdEntity && ((BaseGenericIdEntity) entity).getDynamicAttributes() != null) {
        Collection<CategoryAttribute> dynamicAttributes = AppBeans.get(DynamicAttributes.NAME, DynamicAttributes.class).getAttributesForMetaClass(metaClass);
        for (CategoryAttribute dynamicAttribute : dynamicAttributes) {
            result.add(DynamicAttributesUtils.getMetaPropertyPath(metaClass, dynamicAttribute).getMetaProperty());
        }
    }
    Collections.sort(result, PROPERTY_COMPARATOR);
    return result;
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) MetaProperty(com.haulmont.chile.core.model.MetaProperty) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes)

Example 2 with DynamicAttributes

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

the class DynamicAttributesConditionFrame method fillCategorySelect.

protected void fillCategorySelect() {
    DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
    MetaClass metaClass = condition.getEntityMetaClass();
    if (!Strings.isNullOrEmpty(condition.getPropertyPath())) {
        MetaPropertyPath propertyPath = metaClass.getPropertyPath(condition.getPropertyPath());
        if (propertyPath == null) {
            throw new RuntimeException("Property path " + condition.getPropertyPath() + " doesn't exist");
        }
        metaClass = propertyPath.getRange().asClass();
    }
    Collection<Category> categories = dynamicAttributes.getCategoriesForMetaClass(metaClass);
    UUID catId = condition.getCategoryId();
    Category selectedCategory = null;
    Map<String, Category> categoriesMap = new TreeMap<>();
    if (categories.size() == 1 && (catId == null || Objects.equals(catId, categories.iterator().next().getId()))) {
        Category category = categories.iterator().next();
        categoryLookup.setVisible(false);
        categoryLabel.setVisible(false);
        attributeLookup.focus();
        categoriesMap.put(category.getName(), category);
        categoryLookup.setOptionsMap(categoriesMap);
        categoryLookup.setValue(category);
        fillAttributeSelect(category);
    } else {
        categoryLookup.setVisible(true);
        categoryLabel.setVisible(true);
        for (Category category : categories) {
            categoriesMap.put(category.getName(), category);
            if (category.getId().equals(catId)) {
                selectedCategory = category;
            }
        }
        categoryLookup.setOptionsMap(categoriesMap);
        categoryLookup.setValue(selectedCategory);
    }
}
Also used : Category(com.haulmont.cuba.core.entity.Category) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes)

Example 3 with DynamicAttributes

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

the class DynamicAttributesGuiTools method collectEntityClassesWithDynamicAttributes.

protected Set<Class> collectEntityClassesWithDynamicAttributes(@Nullable View view) {
    if (view == null) {
        return Collections.emptySet();
    }
    DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.class);
    Metadata metadata = AppBeans.get(Metadata.class);
    return collectEntityClasses(view, new HashSet<>()).stream().filter(BaseGenericIdEntity.class::isAssignableFrom).filter(aClass -> !dynamicAttributes.getAttributesForMetaClass(metadata.getClassNN(aClass)).isEmpty()).collect(Collectors.toSet());
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) com.haulmont.cuba.gui.components.validation(com.haulmont.cuba.gui.components.validation) LookupAction(com.haulmont.cuba.gui.actions.picker.LookupAction) DsBuilder(com.haulmont.cuba.gui.data.DsBuilder) DynamicAttributesEntity(com.haulmont.cuba.gui.data.DynamicAttributesEntity) DecimalFormatSymbols(java.text.DecimalFormatSymbols) ZonedDateTime(java.time.ZonedDateTime) DatatypeRegistry(com.haulmont.chile.core.datatypes.DatatypeRegistry) AdaptiveNumberDatatype(com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype) StringUtils(org.apache.commons.lang3.StringUtils) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) BigDecimal(java.math.BigDecimal) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) PickerField(com.haulmont.cuba.gui.components.PickerField) OpenMode(com.haulmont.cuba.gui.screen.OpenMode) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) GuiActionSupport(com.haulmont.cuba.gui.components.actions.GuiActionSupport) WindowParams(com.haulmont.cuba.gui.WindowParams) EntityOp(com.haulmont.cuba.security.entity.EntityOp) java.util(java.util) DatasourceValueSource(com.haulmont.cuba.gui.components.data.value.DatasourceValueSource) ContainerValueSource(com.haulmont.cuba.gui.components.data.value.ContainerValueSource) ParamsMap(com.haulmont.bali.util.ParamsMap) DynamicAttributesUtils(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils) BooleanUtils(org.apache.commons.lang3.BooleanUtils) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) MetaClass(com.haulmont.chile.core.model.MetaClass) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Datatype(com.haulmont.chile.core.datatypes.Datatype) HasValue(com.haulmont.cuba.gui.components.HasValue) com.haulmont.cuba.core.entity(com.haulmont.cuba.core.entity) MapScreenOptions(com.haulmont.cuba.gui.screen.MapScreenOptions) Nullable(javax.annotation.Nullable) DynamicAttributesRecalculationTools(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesRecalculationTools) CommonLookupController(com.haulmont.cuba.gui.commonlookup.CommonLookupController) DecimalFormat(java.text.DecimalFormat) ScreensHelper(com.haulmont.cuba.gui.sys.ScreensHelper) Preconditions(com.haulmont.bali.util.Preconditions) Consumer(java.util.function.Consumer) Component(org.springframework.stereotype.Component) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) PropertyType(com.haulmont.cuba.core.app.dynamicattributes.PropertyType) Action(com.haulmont.cuba.gui.components.Action) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes)

Example 4 with DynamicAttributes

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

the class BaseGenericIdEntityTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    dynamicAttributes = new DynamicAttributes() {

        @Override
        public Collection<Category> getCategoriesForMetaClass(MetaClass metaClass) {
            return null;
        }

        @Override
        public Collection<CategoryAttribute> getAttributesForMetaClass(MetaClass metaClass) {
            return null;
        }

        @Nullable
        @Override
        public CategoryAttribute getAttributeForMetaClass(MetaClass metaClass, String code) {
            CategoryAttribute categoryAttribute = new CategoryAttribute();
            categoryAttribute.setCode(code);
            return categoryAttribute;
        }
    };
    metadata = new Metadata() {

        @Override
        public Session getSession() {
            return new SessionImpl() {

                @Override
                public MetaClass getClassNN(String name) {
                    return new MetaClassImpl(new MetaModelImpl(this, name), name);
                }

                @Override
                public MetaClass getClassNN(Class clazz) {
                    return new MetaClassImpl(new MetaModelImpl(this, clazz.getName()), clazz.getName());
                }
            };
        }

        @Override
        public ViewRepository getViewRepository() {
            return null;
        }

        @Override
        public ExtendedEntities getExtendedEntities() {
            return null;
        }

        @Override
        public MetadataTools getTools() {
            return null;
        }

        @Override
        public DatatypeRegistry getDatatypes() {
            return null;
        }

        @Override
        public <T extends Entity> T create(Class<T> entityClass) {
            if (User.class.equals(entityClass)) {
                return (T) new User();
            }
            if (CategoryAttributeValue.class.equals(entityClass)) {
                CategoryAttributeValue attributeValue = new CategoryAttributeValue();
                attributeValue.setEntity(new ReferenceToEntity());
                return (T) attributeValue;
            }
            throw new IllegalArgumentException("Add support for " + entityClass.getSimpleName() + " to Mock");
        }

        @Override
        public Entity create(MetaClass metaClass) {
            return null;
        }

        @Override
        public Entity create(String entityName) {
            return null;
        }

        @Override
        public List<String> getRootPackages() {
            return null;
        }

        @Override
        public MetaModel getModel(String name) {
            return null;
        }

        @Override
        public Collection<MetaModel> getModels() {
            return null;
        }

        @Nullable
        @Override
        public MetaClass getClass(String name) {
            return null;
        }

        @Override
        public MetaClass getClassNN(String name) {
            return null;
        }

        @Nullable
        @Override
        public MetaClass getClass(Class<?> clazz) {
            return null;
        }

        @Override
        public MetaClass getClassNN(Class<?> clazz) {
            return null;
        }

        @Override
        public Collection<MetaClass> getClasses() {
            return null;
        }
    };
    new Expectations() {

        {
            AppBeans.get(DynamicAttributes.NAME);
            result = dynamicAttributes;
            minTimes = 0;
            AppBeans.get(Metadata.NAME);
            result = metadata;
            minTimes = 0;
            AppBeans.get(ReferenceToEntitySupport.class);
            result = referenceToEntitySupport;
            minTimes = 0;
        }
    };
}
Also used : User(com.haulmont.cuba.security.entity.User) MetaModelImpl(com.haulmont.chile.core.model.impl.MetaModelImpl) DatatypeRegistry(com.haulmont.chile.core.datatypes.DatatypeRegistry) List(java.util.List) MetaClassImpl(com.haulmont.chile.core.model.impl.MetaClassImpl) Expectations(mockit.Expectations) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes) MetaModel(com.haulmont.chile.core.model.MetaModel) MetaClass(com.haulmont.chile.core.model.MetaClass) Collection(java.util.Collection) MetaClass(com.haulmont.chile.core.model.MetaClass) SessionImpl(com.haulmont.chile.core.model.impl.SessionImpl) Nullable(javax.annotation.Nullable) Session(com.haulmont.chile.core.model.Session) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with DynamicAttributes

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

the class RuntimePropsDatasourceImpl method getDefaultCategory.

@Nullable
public Category getDefaultCategory() {
    MetaClass metaClass = resolveCategorizedEntityClass();
    DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.class);
    Collection<Category> categoriesForMetaClass = dynamicAttributes.getCategoriesForMetaClass(metaClass);
    for (Category category : categoriesForMetaClass) {
        if (Boolean.TRUE.equals(category.getIsDefault())) {
            return category;
        }
    }
    return null;
}
Also used : DynamicAttributesMetaClass(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) DynamicAttributes(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes) Nullable(javax.annotation.Nullable)

Aggregations

DynamicAttributes (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes)5 MetaClass (com.haulmont.chile.core.model.MetaClass)4 DatatypeRegistry (com.haulmont.chile.core.datatypes.DatatypeRegistry)2 Nullable (javax.annotation.Nullable)2 Strings (com.google.common.base.Strings)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Preconditions (com.haulmont.bali.util.Preconditions)1 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 AdaptiveNumberDatatype (com.haulmont.chile.core.datatypes.impl.AdaptiveNumberDatatype)1 MetaModel (com.haulmont.chile.core.model.MetaModel)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 Session (com.haulmont.chile.core.model.Session)1 MetaClassImpl (com.haulmont.chile.core.model.impl.MetaClassImpl)1 MetaModelImpl (com.haulmont.chile.core.model.impl.MetaModelImpl)1 SessionImpl (com.haulmont.chile.core.model.impl.SessionImpl)1 DynamicAttributesMetaClass (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaClass)1 DynamicAttributesRecalculationTools (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesRecalculationTools)1 DynamicAttributesUtils (com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils)1 PropertyType (com.haulmont.cuba.core.app.dynamicattributes.PropertyType)1