use of com.haulmont.cuba.gui.components.DataGrid.Column in project cuba by cuba-platform.
the class DataGridLoader method loadColumn.
protected Column loadColumn(DataGrid component, Element element, Datasource ds) {
String id = element.attributeValue("id");
String property = element.attributeValue("property");
if (id == null) {
if (property != null) {
id = property;
} else {
throw new GuiDevelopmentException("A column must have whether id or property specified", context.getCurrentFrameId(), "DataGrid ID", component.getId());
}
}
Column column;
if (property != null) {
MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class).resolveMetaPropertyPath(ds.getMetaClass(), property);
column = component.addColumn(id, metaPropertyPath);
} else {
column = component.addColumn(id, null);
}
String expandRatio = element.attributeValue("expandRatio");
if (StringUtils.isNotEmpty(expandRatio)) {
column.setExpandRatio(Integer.parseInt(expandRatio));
}
String collapsed = element.attributeValue("collapsed");
if (StringUtils.isNotEmpty(collapsed)) {
column.setCollapsed(Boolean.parseBoolean(collapsed));
}
String collapsible = element.attributeValue("collapsible");
if (StringUtils.isNotEmpty(collapsible)) {
column.setCollapsible(Boolean.parseBoolean(collapsible));
}
String collapsingToggleCaption = element.attributeValue("collapsingToggleCaption");
if (StringUtils.isNotEmpty(collapsingToggleCaption)) {
collapsingToggleCaption = loadResourceString(collapsingToggleCaption);
column.setCollapsingToggleCaption(collapsingToggleCaption);
}
String sortable = element.attributeValue("sortable");
if (StringUtils.isNotEmpty(sortable)) {
column.setSortable(Boolean.parseBoolean(sortable));
}
String resizable = element.attributeValue("resizable");
if (StringUtils.isNotEmpty(resizable)) {
column.setResizable(Boolean.parseBoolean(resizable));
}
String editable = element.attributeValue("editable");
if (StringUtils.isNotEmpty(editable)) {
column.setEditable(Boolean.parseBoolean(editable));
}
// Default caption set to columns when it is added to a DataGrid,
// so we need to set caption as null to get caption from
// metaProperty if 'caption' attribute is empty
column.setCaption(null);
String caption = loadCaption(element);
if (caption == null) {
String columnCaption;
if (column.getPropertyPath() != null) {
MetaProperty metaProperty = column.getPropertyPath().getMetaProperty();
String propertyName = metaProperty.getName();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ? categoryAttribute.getLocaleName() : StringUtils.capitalize(categoryAttribute.getName());
} else {
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(column.getPropertyPath());
columnCaption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
}
} else {
Class<?> declaringClass = ds.getMetaClass().getJavaClass();
String className = declaringClass.getName();
int i = className.lastIndexOf('.');
if (i > -1) {
className = className.substring(i + 1);
}
columnCaption = messages.getMessage(declaringClass, className + "." + id);
}
column.setCaption(columnCaption);
} else {
column.setCaption(caption);
}
column.setXmlDescriptor(element);
Integer width = loadWidth(element, "width");
if (width != null) {
column.setWidth(width);
}
Integer minimumWidth = loadWidth(element, "minimumWidth");
if (minimumWidth != null) {
column.setMinimumWidth(minimumWidth);
}
Integer maximumWidth = loadWidth(element, "maximumWidth");
if (maximumWidth != null) {
column.setMaximumWidth(maximumWidth);
}
column.setFormatter(loadFormatter(element));
return column;
}
use of com.haulmont.cuba.gui.components.DataGrid.Column in project cuba by cuba-platform.
the class DataGridLoader method addDynamicAttributes.
protected void addDynamicAttributes(DataGrid component, Datasource ds, List<Column> availableColumns) {
if (metadataTools.isPersistent(ds.getMetaClass())) {
Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools.getAttributesToShowOnTheScreen(ds.getMetaClass(), context.getFullFrameId(), component.getId());
if (CollectionUtils.isNotEmpty(attributesToShow)) {
ds.setLoadDynamicAttributes(true);
for (CategoryAttribute attribute : attributesToShow) {
final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(ds.getMetaClass(), attribute);
Object columnWithSameId = IterableUtils.find(availableColumns, column -> {
MetaPropertyPath propertyPath = column.getPropertyPath();
return propertyPath != null && propertyPath.equals(metaPropertyPath);
});
if (columnWithSameId != null) {
continue;
}
final Column column = component.addColumn(metaPropertyPath.getMetaProperty().getName(), metaPropertyPath);
column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ? attribute.getLocaleName() : StringUtils.capitalize(attribute.getName()));
}
}
dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
}
}
use of com.haulmont.cuba.gui.components.DataGrid.Column in project cuba by cuba-platform.
the class DataGridLoader method loadComponent.
@Override
public void loadComponent() {
assignXmlDescriptor(resultComponent, element);
assignFrame(resultComponent);
loadEnable(resultComponent, element);
loadVisible(resultComponent, element);
loadSettingsEnabled(resultComponent, element);
loadAlign(resultComponent, element);
loadStyleName(resultComponent, element);
loadHeight(resultComponent, element);
loadWidth(resultComponent, element);
loadIcon(resultComponent, element);
loadCaption(resultComponent, element);
loadDescription(resultComponent, element);
loadEditorEnabled(resultComponent, element);
loadEditorBuffered(resultComponent, element);
loadEditorSaveCaption(resultComponent, element);
loadEditorCancelCaption(resultComponent, element);
loadActions(resultComponent, element);
loadContextMenuEnabled(resultComponent, element);
loadColumnsHidingAllowed(resultComponent, element);
loadColumnResizeMode(resultComponent, element);
loadSortable(resultComponent, element);
loadResponsive(resultComponent, element);
loadReorderingAllowed(resultComponent, element);
loadHeaderVisible(resultComponent, element);
loadTextSelectionEnabled(resultComponent, element);
Element columnsElement = element.element("columns");
loadButtonsPanel(resultComponent);
// must be before datasource setting
loadRowsCount(resultComponent, element);
String datasource = element.attributeValue("datasource");
if (StringUtils.isBlank(datasource)) {
throw new GuiDevelopmentException("DataGrid element doesn't have 'datasource' attribute", context.getCurrentFrameId(), "DataGrid ID", element.attributeValue("id"));
}
Datasource ds = context.getDsContext().get(datasource);
if (ds == null) {
throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context.getCurrentFrameId());
}
if (!(ds instanceof CollectionDatasource)) {
throw new GuiDevelopmentException("Not a CollectionDatasource: " + datasource, context.getCurrentFrameId());
}
CollectionDatasource cds = (CollectionDatasource) ds;
List<Column> availableColumns;
if (columnsElement != null) {
availableColumns = loadColumns(resultComponent, columnsElement, cds);
} else {
availableColumns = new ArrayList<>();
}
addDynamicAttributes(resultComponent, ds, availableColumns);
resultComponent.setDatasource(cds);
loadSelectionMode(resultComponent, element);
loadFrozenColumnCount(resultComponent, element);
loadTabIndex(resultComponent, element);
}
Aggregations