use of io.jmix.core.MessageTools in project jmix by jmix-framework.
the class DynamicAttributesCondition method getLocCaption.
@Override
public String getLocCaption() {
if (isBlank(caption) && !isBlank(propertyPath)) {
MessageTools messageTools = AppBeans.get(MessageTools.class);
String propertyCaption = messageTools.getPropertyCaption(metaClass, propertyPath);
if (!isBlank(propertyCaption)) {
return propertyCaption + "." + locCaption;
}
} else if (isNotBlank(caption)) {
MessageTools messageTools = AppBeans.get(MessageTools.class);
return messageTools.loadString(messagesPack, caption);
}
DynAttrMetadata dynamicModelMetadata = AppBeans.get(DynAttrMetadata.class);
AttributeDefinition attribute = dynamicModelMetadata.getAttributes(metaClass).stream().filter(attr -> Objects.equals(EntityValues.getId(attr.getSource()), getCategoryAttributeId())).findFirst().orElse(null);
if (attribute != null) {
MsgBundleTools msgBundleTools = AppBeans.get(MsgBundleTools.class);
return msgBundleTools.getLocalizedValue(attribute.getNameMsgBundle(), attribute.getName());
}
return super.getLocCaption();
}
use of io.jmix.core.MessageTools in project jmix by jmix-framework.
the class FilterConditionUtils method getPropertyLocCaption.
public static String getPropertyLocCaption(MetaClass metaClass, String propertyPath) {
MessageTools messageTools = AppBeans.get(MessageTools.class);
MetaPropertyPath mpp = metaClass.getPropertyPath(propertyPath);
if (mpp == null) {
return propertyPath;
} else {
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
MetaProperty[] metaProperties = mpp.getMetaProperties();
StringBuilder sb = new StringBuilder();
MetaPropertyPath parentMpp = null;
MetaClass tempMetaClass;
for (int i = 0; i < metaProperties.length; i++) {
if (i == 0) {
parentMpp = new MetaPropertyPath(metaClass, metaProperties[i]);
tempMetaClass = metaClass;
} else {
parentMpp = new MetaPropertyPath(parentMpp, metaProperties[i]);
tempMetaClass = metadataTools.getPropertyEnclosingMetaClass(parentMpp);
}
sb.append(messageTools.getPropertyCaption(tempMetaClass, metaProperties[i].getName()));
if (i < metaProperties.length - 1) {
sb.append(".");
}
}
return sb.toString();
}
}
use of io.jmix.core.MessageTools in project jmix by jmix-framework.
the class PropertyConditionDescriptor method getTreeCaption.
@Override
public String getTreeCaption() {
if (!Strings.isNullOrEmpty(this.caption)) {
return locCaption;
} else {
MessageTools messageTools = AppBeans.get(MessageTools.class);
MetaPropertyPath mpp = datasourceMetaClass.getPropertyPath(name);
return mpp != null ? messageTools.getPropertyCaption(datasourceMetaClass, name) : name;
}
}
use of io.jmix.core.MessageTools in project jmix by jmix-framework.
the class CustomConditionFrame method fillEntitySelect.
protected void fillEntitySelect(Param param) {
if (!entitySelect.isEnabled()) {
entitySelect.setValue(null);
return;
}
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
MessageTools messageTools = AppBeans.get(MessageTools.class);
Map<String, Object> items = new TreeMap<>();
Object selectedItem = null;
if (ParamType.ENTITY.equals(typeSelect.getValue())) {
for (MetaClass metaClass : metadataTools.getAllJpaEntityMetaClasses()) {
if (!metadataTools.isSystemLevel(metaClass)) {
items.put(messageTools.getEntityCaption(metaClass) + " (" + metaClass.getName() + ")", metaClass);
}
}
if (param != null && Param.Type.ENTITY.equals(param.getType())) {
Class javaClass = param.getJavaClass();
Metadata metadata = AppBeans.get(Metadata.class);
selectedItem = metadata.getClass(javaClass);
}
entitySelect.setOptionsMap(items);
entitySelect.setValue(selectedItem);
} else if (ParamType.ENUM.equals(typeSelect.getValue())) {
if (param != null && Param.Type.ENUM.equals(param.getType())) {
selectedItem = param.getJavaClass();
}
boolean selectedItemFound = false;
for (Class enumClass : metadataTools.getAllEnums()) {
items.put(getEnumClassName(enumClass), enumClass);
if (selectedItem == null || selectedItem.equals(enumClass))
selectedItemFound = true;
}
// the meta model, hence not in MetadataHelper.getAllEnums(). So we just add it here.
if (selectedItem != null && !selectedItemFound) {
items.put(getEnumClassName((Class) selectedItem), selectedItem);
}
entitySelect.setOptionsMap(items);
entitySelect.setValue(selectedItem);
}
}
Aggregations