mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-05 04:38:10 +08:00
PL-10153 A dynamic attribute name has to be displayed in tables, group tables and tree tables the same way as it is set in the localization
This commit is contained in:
parent
bfd56d78d8
commit
5c268e51f1
@ -20,16 +20,19 @@ import com.google.common.base.Joiner;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.UserSessionSource;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class LocaleHelper {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(LocaleHelper.class);
|
||||
|
||||
private LocaleHelper() {
|
||||
}
|
||||
|
||||
@ -160,8 +163,13 @@ public final class LocaleHelper {
|
||||
try {
|
||||
localeProperties = new Properties();
|
||||
localeProperties.load(reader);
|
||||
} catch (IOException ignored) {
|
||||
} catch (IOException e) {
|
||||
log.debug("Unable to load properties: {}", localeBundle, e);
|
||||
}
|
||||
return localeProperties;
|
||||
}
|
||||
|
||||
public static boolean isLocalizedValueDefined(String localeBundle) {
|
||||
return getLocalizedName(localeBundle) != null;
|
||||
}
|
||||
}
|
@ -194,7 +194,10 @@ public abstract class AbstractTableLoader<T extends Table> extends ActionsHolder
|
||||
}
|
||||
|
||||
final Table.Column column = new Table.Column(metaPropertyPath);
|
||||
column.setCaption(attribute.getLocaleName());
|
||||
|
||||
column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ?
|
||||
attribute.getLocaleName() :
|
||||
StringUtils.capitalize(attribute.getName()));
|
||||
|
||||
if (attribute.getDataType().equals(PropertyType.STRING)) {
|
||||
column.setMaxTextLength(clientConfig.getDynamicAttributesTableColumnMaxTextLength());
|
||||
@ -374,7 +377,10 @@ public abstract class AbstractTableLoader<T extends Table> extends ActionsHolder
|
||||
|
||||
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
|
||||
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
|
||||
columnCaption = categoryAttribute != null ? categoryAttribute.getLocaleName() : propertyName;
|
||||
|
||||
columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ?
|
||||
categoryAttribute.getLocaleName() :
|
||||
StringUtils.capitalize(categoryAttribute.getName());
|
||||
} else {
|
||||
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(mpp);
|
||||
columnCaption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
|
||||
|
@ -21,6 +21,7 @@ import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.chile.core.model.MetaPropertyPath;
|
||||
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
|
||||
import com.haulmont.cuba.core.entity.CategoryAttribute;
|
||||
import com.haulmont.cuba.core.entity.LocaleHelper;
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.core.global.MetadataTools;
|
||||
import com.haulmont.cuba.gui.ComponentsHelper;
|
||||
@ -329,7 +330,9 @@ public class DataGridLoader extends ActionsHolderLoader<DataGrid> {
|
||||
|
||||
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
|
||||
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
|
||||
columnCaption = categoryAttribute != null ? categoryAttribute.getLocaleName() : propertyName;
|
||||
columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ?
|
||||
categoryAttribute.getLocaleName() :
|
||||
StringUtils.capitalize(categoryAttribute.getName());
|
||||
} else {
|
||||
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(column.getPropertyPath());
|
||||
columnCaption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
|
||||
@ -419,7 +422,10 @@ public class DataGridLoader extends ActionsHolderLoader<DataGrid> {
|
||||
|
||||
final Column column =
|
||||
component.addColumn(metaPropertyPath.getMetaProperty().getName(), metaPropertyPath);
|
||||
column.setCaption(attribute.getLocaleName());
|
||||
|
||||
column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ?
|
||||
attribute.getLocaleName() :
|
||||
StringUtils.capitalize(attribute.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,9 @@ import com.haulmont.chile.core.model.MetaProperty;
|
||||
import com.haulmont.chile.core.model.MetaPropertyPath;
|
||||
import com.haulmont.cuba.client.ClientConfig;
|
||||
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
|
||||
import com.haulmont.cuba.core.entity.CategoryAttribute;
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.core.entity.LocaleHelper;
|
||||
import com.haulmont.cuba.core.entity.SoftDelete;
|
||||
import com.haulmont.cuba.core.global.*;
|
||||
import com.haulmont.cuba.gui.ComponentsHelper;
|
||||
@ -222,7 +224,7 @@ public abstract class WebAbstractTable<T extends com.vaadin.ui.Table & CubaEnhan
|
||||
WebComponentsHelper.convertColumnAlignment(column.getAlignment()));
|
||||
}
|
||||
|
||||
final String caption = StringUtils.capitalize(column.getCaption() != null ? column.getCaption() : getColumnCaption(columnId));
|
||||
final String caption = getColumnCaption(columnId, column);
|
||||
setColumnHeader(columnId, caption);
|
||||
|
||||
column.setOwner(this);
|
||||
@ -978,7 +980,7 @@ public abstract class WebAbstractTable<T extends com.vaadin.ui.Table & CubaEnhan
|
||||
|
||||
final String caption;
|
||||
if (column != null) {
|
||||
caption = StringUtils.capitalize(column.getCaption() != null ? column.getCaption() : getColumnCaption(columnId));
|
||||
caption = getColumnCaption(columnId, column);
|
||||
} else {
|
||||
caption = StringUtils.capitalize(getColumnCaption(columnId));
|
||||
}
|
||||
@ -1111,6 +1113,34 @@ public abstract class WebAbstractTable<T extends com.vaadin.ui.Table & CubaEnhan
|
||||
return columnId.toString();
|
||||
}
|
||||
|
||||
protected String getColumnCaption(Object columnId, Column column) {
|
||||
String caption = column.getCaption();
|
||||
|
||||
if (caption != null) {
|
||||
return caption;
|
||||
}
|
||||
|
||||
if (!(columnId instanceof MetaPropertyPath)) {
|
||||
return StringUtils.capitalize(getColumnCaption(columnId));
|
||||
}
|
||||
|
||||
MetaPropertyPath mpp = (MetaPropertyPath) columnId;
|
||||
MetaProperty metaProperty = mpp.getMetaProperty();
|
||||
|
||||
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
|
||||
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
|
||||
if (LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())) {
|
||||
return categoryAttribute.getLocaleName();
|
||||
}
|
||||
|
||||
caption = StringUtils.capitalize(categoryAttribute.getName());
|
||||
} else {
|
||||
caption = StringUtils.capitalize(getColumnCaption(columnId));
|
||||
}
|
||||
|
||||
return caption;
|
||||
}
|
||||
|
||||
protected void createStubsForGeneratedColumns() {
|
||||
com.vaadin.ui.Table.ColumnGenerator columnGeneratorStub = new com.vaadin.ui.Table.ColumnGenerator() {
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user