use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.
the class EmbeddedDatasourceImpl method getItem.
@Override
public T getItem() {
backgroundWorker.checkUIAccess();
final Instance item = masterDs.getItem();
return getItem(item);
}
use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.
the class EmbeddedDatasourceImpl method setItem.
@Override
public void setItem(T item) {
backgroundWorker.checkUIAccess();
if (getItem() != null) {
metadata.getTools().copy(item, getItem());
itemsToUpdate.add(item);
} else {
final Instance parentItem = masterDs.getItem();
parentItem.setValue(metaProperty.getName(), item);
}
setModified(true);
((DatasourceImplementation) masterDs).modified(masterDs.getItem());
}
use of com.haulmont.chile.core.model.Instance 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) {
GroupTableItems<Entity> groupTableSource = (GroupTableItems) table.getItems();
Row 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) {
Cell cell = row.createCell(i);
Object val = groupInfo.getValue();
if (val == null) {
val = messages.getMessage(getClass(), "excelExporter.empty");
}
Collection children = groupTableSource.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 = groupTableSource.getItemNN(itemId);
captionValue = item.getValueEx(captionProperty);
}
GroupTable.GroupCellValueFormatter<Entity> groupCellValueFormatter = table.getGroupCellValueFormatter();
if (groupCellValueFormatter != null) {
// disable separate "(N)" printing
groupChildCount = null;
List<Entity> groupItems = ((Collection<Object>) groupTableSource.getGroupItemIds(groupInfo)).stream().map(groupTableSource::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 key = agr.getPropertyPath() != null ? agr.getPropertyPath() : column.getId();
Object aggregationResult = aggregations.get(key);
if (aggregationResult != null) {
Cell cell = row.createCell(i);
formatValueCell(cell, aggregationResult, null, i, rowNumber, 0, null);
}
}
}
i++;
}
int oldRowNumber = rowNumber;
List<GroupInfo> children = groupTableSource.getChildren(groupInfo);
if (children.size() > 0) {
for (GroupInfo child : children) {
rowNumber = createGroupRow(table, columns, ++rowNumber, child, groupNumber);
}
} else {
Collection<?> itemIds = groupTableSource.getGroupItemIds(groupInfo);
for (Object itemId : itemIds) {
createRow(table, columns, groupNumber, ++rowNumber, itemId);
}
}
if (checkIsRowNumberExceed(rowNumber)) {
sheet.groupRow(oldRowNumber + 1, excelOptions.getMaxRowCount());
} else {
sheet.groupRow(oldRowNumber + 1, rowNumber);
}
return rowNumber;
}
use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.
the class AbstractComparator method compareAsc.
protected int compareAsc(Object o1, Object o2) {
int c;
if (o1 instanceof String && o2 instanceof String) {
c = ((String) o1).compareToIgnoreCase((String) o2);
} else if (o1 instanceof Comparable && o2 instanceof Comparable) {
c = ((Comparable) o1).compareTo(o2);
} else if (o1 instanceof Instance && o2 instanceof Instance) {
MetaClass metaClass = metadata.getClassNN(o1.getClass());
Collection<MetaProperty> namePatternProperties = metadata.getTools().getNamePatternProperties(metaClass, true);
if (namePatternProperties.isEmpty()) {
c = ((Instance) o1).getInstanceName().compareToIgnoreCase(((Instance) o2).getInstanceName());
} else {
c = 0;
for (MetaProperty property : namePatternProperties) {
Object v1 = ((Instance) o1).getValue(property.getName());
Object v2 = ((Instance) o2).getValue(property.getName());
c = compareAsc(v1, v2);
if (c != 0)
break;
}
}
} else if (Objects.equals(o1, o2)) {
c = 0;
} else if (o1 == null && o2 != null) {
c = nullsLast;
} else {
c = -nullsLast;
}
return c;
}
use of com.haulmont.chile.core.model.Instance in project cuba by cuba-platform.
the class WebGroupTable method formatGroupPropertyValue.
protected String formatGroupPropertyValue(GroupInfo<MetaPropertyPath> groupId, @Nullable Object value) {
if (value == null) {
return "";
}
MetaPropertyPath propertyPath = groupId.getProperty();
Table.Column<E> column = columns.get(propertyPath);
if (column != null) {
if (column.getFormatter() != null) {
return column.getFormatter().apply(value);
} else if (column.getXmlDescriptor() != null) {
// vaadin8 move to Column
String captionProperty = column.getXmlDescriptor().attributeValue("captionProperty");
if (StringUtils.isNotEmpty(captionProperty)) {
Collection<?> children = component.getGroupItemIds(groupId);
if (children.isEmpty()) {
return null;
}
Object itemId = children.iterator().next();
TableDataContainer container = (TableDataContainer) component.getContainerDataSource();
Instance item = (Instance) container.getInternalItem(itemId);
Object captionValue = item.getValueEx(captionProperty);
// vaadin8 use metadataTools format with metaproperty
return metadataTools.format(captionValue);
}
}
}
return metadataTools.format(value, propertyPath.getMetaProperty());
}
Aggregations