use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
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 com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class DynamicAttributesConditionFrame method fillCategorySelect.
protected void fillCategorySelect() {
DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
MetaClass metaClass = condition.getDatasource().getMetaClass();
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<Category> categories = dynamicAttributes.getCategoriesForMetaClass(metaClass);
UUID catId = condition.getCategoryId();
Category selectedCategory = null;
Map<String, Object> categoriesMap = new TreeMap<>();
if (categories.size() == 1 && (catId == null || Objects.equals(catId, categories.iterator().next().getId()))) {
Category category = categories.iterator().next();
categoryLookup.setVisible(false);
categoryLabel.setVisible(false);
attributeLookup.requestFocus();
categoriesMap.put(category.getName(), category);
categoryLookup.setOptionsMap(categoriesMap);
categoryLookup.setValue(category);
fillAttributeSelect(category);
} else {
categoryLookup.setVisible(true);
categoryLabel.setVisible(true);
for (Category category : categories) {
categoriesMap.put(category.getName(), category);
if (category.getId().equals(catId)) {
selectedCategory = category;
}
}
categoryLookup.setOptionsMap(categoriesMap);
categoryLookup.setValue(selectedCategory);
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class ExcelExporter method createRow.
protected void createRow(Table table, List<Table.Column> columns, int startColumn, int rowNumber, Object itemId) {
if (startColumn >= columns.size()) {
return;
}
HSSFRow row = sheet.createRow(rowNumber);
Instance instance = table.getDatasource().getItem(itemId);
int level = 0;
if (table instanceof TreeTable) {
level = ((TreeTable) table).getLevel(itemId);
}
for (int c = startColumn; c < columns.size(); c++) {
HSSFCell cell = row.createCell(c);
Table.Column column = columns.get(c);
Object cellValue = null;
MetaPropertyPath propertyPath = null;
if (column.getId() instanceof MetaPropertyPath) {
propertyPath = (MetaPropertyPath) column.getId();
Table.Printable printable = table.getPrintable(column);
if (printable != null) {
cellValue = printable.getValue((Entity) instance);
} else {
Element xmlDescriptor = column.getXmlDescriptor();
if (xmlDescriptor != null && StringUtils.isNotEmpty(xmlDescriptor.attributeValue("captionProperty"))) {
String captionProperty = xmlDescriptor.attributeValue("captionProperty");
cellValue = InstanceUtils.getValueEx(instance, captionProperty);
} else {
cellValue = InstanceUtils.getValueEx(instance, propertyPath.getPath());
}
if (column.getFormatter() != null)
cellValue = column.getFormatter().format(cellValue);
}
} else {
Table.Printable printable = table.getPrintable(column);
if (printable != null) {
cellValue = printable.getValue((Entity) instance);
}
}
formatValueCell(cell, cellValue, propertyPath, c, rowNumber, level, null);
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class ExcelExporter method createGroupRow.
protected int createGroupRow(GroupTable table, List<Table.Column> columns, int rowNumber, GroupInfo groupInfo, int groupNumber) {
GroupDatasource ds = table.getDatasource();
HSSFRow row = sheet.createRow(rowNumber);
Map<Object, Object> aggregations = table.isAggregatable() ? table.getAggregationResults(groupInfo) : Collections.emptyMap();
int i = 0;
int initialGroupNumber = groupNumber;
for (Table.Column column : columns) {
if (i == initialGroupNumber) {
HSSFCell cell = row.createCell(i);
Object val = groupInfo.getValue();
if (val == null) {
val = messages.getMessage(getClass(), "excelExporter.empty");
}
Collection children = table.getDatasource().getGroupItemIds(groupInfo);
if (children.isEmpty()) {
return rowNumber;
}
Integer groupChildCount = null;
if (table.isShowItemsCountForGroup()) {
groupChildCount = children.size();
}
Object captionValue = val;
Element xmlDescriptor = column.getXmlDescriptor();
if (xmlDescriptor != null && StringUtils.isNotEmpty(xmlDescriptor.attributeValue("captionProperty"))) {
String captionProperty = xmlDescriptor.attributeValue("captionProperty");
Object itemId = children.iterator().next();
Instance item = ds.getItem(itemId);
captionValue = item.getValueEx(captionProperty);
}
@SuppressWarnings("unchecked") GroupTable.GroupCellValueFormatter<Entity> groupCellValueFormatter = table.getGroupCellValueFormatter();
if (groupCellValueFormatter != null) {
// disable separate "(N)" printing
groupChildCount = null;
List<Entity> groupItems = ((Collection<Object>) ds.getGroupItemIds(groupInfo)).stream().map((Function<Object, Entity>) ds::getItem).collect(Collectors.toList());
GroupTable.GroupCellContext<Entity> cellContext = new GroupTable.GroupCellContext<>(groupInfo, captionValue, metadataTools.format(captionValue), groupItems);
captionValue = groupCellValueFormatter.format(cellContext);
}
MetaPropertyPath columnId = (MetaPropertyPath) column.getId();
formatValueCell(cell, captionValue, columnId, groupNumber++, rowNumber, 0, groupChildCount);
} else {
AggregationInfo agr = column.getAggregation();
if (agr != null) {
Object aggregationResult = aggregations.get(agr.getPropertyPath());
if (aggregationResult != null) {
HSSFCell cell = row.createCell(i);
formatValueCell(cell, aggregationResult, null, i, rowNumber, 0, null);
}
}
}
i++;
}
int oldRowNumber = rowNumber;
List<GroupInfo> children = ds.getChildren(groupInfo);
if (children.size() > 0) {
for (GroupInfo child : children) {
rowNumber = createGroupRow(table, columns, ++rowNumber, child, groupNumber);
}
} else {
Collection<Object> itemIds = ds.getGroupItemIds(groupInfo);
for (Object itemId : itemIds) {
createRow(table, columns, groupNumber, ++rowNumber, itemId);
}
}
sheet.groupRow(oldRowNumber + 1, rowNumber);
return rowNumber;
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class ExcelExporter method createDataGridRow.
protected void createDataGridRow(DataGrid dataGrid, List<DataGrid.Column> columns, int startColumn, int rowNumber, Object itemId) {
if (startColumn >= columns.size()) {
return;
}
HSSFRow row = sheet.createRow(rowNumber);
Instance instance = dataGrid.getDatasource().getItem(itemId);
int level = 0;
for (int c = startColumn; c < columns.size(); c++) {
HSSFCell cell = row.createCell(c);
DataGrid.Column column = columns.get(c);
Object cellValue;
MetaPropertyPath propertyPath = null;
if (column.getPropertyPath() != null) {
propertyPath = column.getPropertyPath();
cellValue = InstanceUtils.getValueEx(instance, propertyPath.getPath());
if (column.getFormatter() != null) {
cellValue = column.getFormatter().format(cellValue);
}
} else {
DataGrid.ColumnGenerator generator = dataGrid.getColumnGenerator(column.getId());
DataGrid.ColumnGeneratorEvent event = new DataGrid.ColumnGeneratorEvent(dataGrid, instance, column.getId());
cellValue = generator.getValue(event);
}
formatValueCell(cell, cellValue, propertyPath, c, rowNumber, level, null);
}
}
Aggregations