Search in sources :

Example 6 with MetaPropertyPath

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;
}
Also used : GroupInfo(io.jmix.ui.component.data.GroupInfo) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) Nullable(javax.annotation.Nullable)

Example 7 with MetaPropertyPath

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));
    }
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) ImmutableList(com.google.common.collect.ImmutableList)

Example 8 with MetaPropertyPath

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;
    }
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Property(com.vaadin.v7.data.Property) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 9 with MetaPropertyPath

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();
}
Also used : Entity(io.jmix.core.Entity) Table(io.jmix.ui.component.Table) Messages(io.jmix.core.Messages) EditorScreen(io.jmix.ui.screen.EditorScreen) Screen(io.jmix.ui.screen.Screen) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) Metadata(io.jmix.core.Metadata) OpenMode(io.jmix.ui.screen.OpenMode) ScreenContext(io.jmix.ui.screen.ScreenContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) EditorScreen(io.jmix.ui.screen.EditorScreen) ScreenBuilders(io.jmix.ui.ScreenBuilders)

Example 10 with MetaPropertyPath

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;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) Nullable(javax.annotation.Nullable)

Aggregations

MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)134 MetaClass (io.jmix.core.metamodel.model.MetaClass)68 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)52 Nullable (javax.annotation.Nullable)19 Table (io.jmix.ui.component.Table)15 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)12 MetadataTools (io.jmix.core.MetadataTools)10 Element (org.dom4j.Element)10 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)8 JmixEnhancedTable (io.jmix.ui.widget.JmixEnhancedTable)7 EntityTableItems (io.jmix.ui.component.data.meta.EntityTableItems)6 java.util (java.util)6 Collectors (java.util.stream.Collectors)6 Range (io.jmix.core.metamodel.model.Range)5 HasValueSource (io.jmix.ui.component.data.HasValueSource)5 ValueSource (io.jmix.ui.component.data.ValueSource)4 AbstractTable (io.jmix.ui.component.impl.AbstractTable)4 TableSettings (io.jmix.ui.settings.component.TableSettings)4