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);
}
}
Aggregations