Search in sources :

Example 1 with CategoryDefinition

use of io.jmix.dynattr.CategoryDefinition in project jmix by jmix-framework.

the class DynamicAttributesConditionFrame method fillCategorySelect.

protected void fillCategorySelect() {
    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<CategoryDefinition> categories = dynAttrMetadata.getCategories(metaClass);
    CategoryDefinition firstCategory = Iterables.getFirst(categories, null);
    String currentId = condition.getCategoryId();
    if (categories.size() == 1 && firstCategory != null && (currentId == null || currentId.equals(firstCategory.getId()))) {
        categoryLookup.setVisible(false);
        categoryLabel.setVisible(false);
        attributeLookup.focus();
        Map<String, CategoryDefinition> options = new TreeMap<>();
        options.put(firstCategory.getName(), firstCategory);
        categoryLookup.setOptionsMap(options);
        categoryLookup.setValue(firstCategory);
        fillAttributeSelect(firstCategory);
    } else {
        categoryLookup.setVisible(true);
        categoryLabel.setVisible(true);
        CategoryDefinition selectedCategory = null;
        Map<String, CategoryDefinition> options = new TreeMap<>();
        for (CategoryDefinition item : categories) {
            options.put(item.getName(), item);
            if (Objects.equals(item.getId(), currentId)) {
                selectedCategory = item;
            }
        }
        categoryLookup.setOptionsMap(options);
        categoryLookup.setValue(selectedCategory);
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) CategoryDefinition(io.jmix.dynattr.CategoryDefinition)

Aggregations

MetaClass (io.jmix.core.metamodel.model.MetaClass)1 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)1 CategoryDefinition (io.jmix.dynattr.CategoryDefinition)1