use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class ContainerGroupTableItems method groupItems.
@Nullable
protected GroupInfo<MetaPropertyPath> groupItems(int propertyIndex, @Nullable GroupInfo parent, List<GroupInfo> children, E item, LinkedMap<MetaPropertyPath, Object> groupValues) {
MetaPropertyPath property = (MetaPropertyPath) groupProperties[propertyIndex++];
Object itemValue = getValueByProperty(item, property);
groupValues.put(property, itemValue);
GroupInfo<MetaPropertyPath> groupInfo = new GroupInfo<>(groupValues);
itemGroups.put(EntityValues.getId(item), groupInfo);
if (!parents.containsKey(groupInfo)) {
parents.put(groupInfo, parent);
}
if (!children.contains(groupInfo)) {
children.add(groupInfo);
}
List<GroupInfo> groupChildren = this.children.computeIfAbsent(groupInfo, k -> new ArrayList<>());
if (propertyIndex < groupProperties.length) {
groupInfo = groupItems(propertyIndex, groupInfo, groupChildren, item, groupValues);
}
return groupInfo;
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class ContainerGroupTableItems method doGroup.
protected void doGroup() {
roots = new LinkedList<>();
parents = new LinkedHashMap<>();
children = new LinkedHashMap<>();
groupItems = new HashMap<>();
itemGroups = new HashMap<>();
for (E item : container.getItems()) {
GroupInfo<MetaPropertyPath> groupInfo = groupItems(0, null, roots, item, new LinkedMap<>());
if (groupInfo == null) {
throw new IllegalStateException("Item group cannot be NULL");
}
List itemsIds = groupItems.computeIfAbsent(groupInfo, k -> new ArrayList<>());
itemsIds.add(EntityValues.getId(item));
}
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class AbbreviatedColumnGenerator method generateCell.
@Nullable
@Override
public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) {
Property property = source.getItem(itemId).getItemProperty(columnId);
Object value = property.getValue();
if (value == null) {
return null;
}
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
String stringValue = metadataTools.format(value, metaProperty);
String cellValue = stringValue;
boolean isMultiLineCell = StringUtils.contains(stringValue, "\n");
if (isMultiLineCell) {
cellValue = StringUtils.replaceChars(cellValue, '\n', ' ');
}
int maxTextLength = column.getMaxTextLength();
if (stringValue.length() > maxTextLength + MAX_TEXT_LENGTH_GAP || isMultiLineCell) {
return StringUtils.abbreviate(cellValue, maxTextLength);
} else {
return cellValue;
}
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class LinkCellClickListener method accept.
@Override
public void accept(Table.Column.ClickEvent clickEvent) {
if (!clickEvent.isText()) {
return;
}
Table.Column<?> column = clickEvent.getSource();
Table owner = column.getOwner();
if (owner == null || owner.getFrame() == null) {
return;
}
Object rowItem = clickEvent.getItem();
MetaPropertyPath mpp = column.getMetaPropertyPathNN();
Object item = EntityValues.getValueEx(rowItem, mpp);
Entity entity;
if (EntityValues.isEntity(item)) {
entity = (Entity) item;
} else {
entity = (Entity) rowItem;
}
if (EntityValues.isSoftDeleted(entity)) {
ScreenContext context = ComponentsHelper.getScreenContext(owner);
context.getNotifications().create(Notifications.NotificationType.HUMANIZED).withCaption(applicationContext.getBean(Messages.class).getMessage("OpenAction.objectIsDeleted")).show();
return;
}
entity = loadEntity(entity);
MetaClass metaClass = applicationContext.getBean(Metadata.class).getClass(entity);
String linkScreenId = loadLinkScreenId(column, metaClass);
OpenMode openMode = loadLinkScreenOpenMode(column);
Screen editor = applicationContext.getBean(ScreenBuilders.class).editor(metaClass.getJavaClass(), owner.getFrame().getFrameOwner()).withScreenId(linkScreenId).editEntity(entity).withOpenMode(openMode).build();
editor.addAfterCloseListener(afterCloseEvent -> {
// move focus to component
owner.focus();
if (afterCloseEvent.closedWith(StandardOutcome.COMMIT) && editor instanceof EditorScreen) {
onEditScreenAfterCommit(mpp, rowItem, (EditorScreen) editor, owner);
}
});
editor.show();
}
use of io.jmix.core.metamodel.model.MetaPropertyPath in project jmix by jmix-framework.
the class PropertyFilterConverter method convertDefaultValueToModel.
@Nullable
protected String convertDefaultValueToModel(PropertyFilter component) {
Object defaultValue = component.getValue();
MetaClass metaClass = filter.getDataLoader().getContainer().getEntityMetaClass();
MetaPropertyPath mpp = metadataTools.resolveMetaPropertyPathOrNull(metaClass, component.getProperty());
String modelDefaultValue = null;
if (mpp != null) {
modelDefaultValue = propertyFilterSupport.formatDefaultValue(mpp.getMetaProperty(), component.getOperation().getType(), defaultValue);
}
return modelDefaultValue;
}
Aggregations