Search in sources :

Example 11 with ContainerDataUnit

use of io.jmix.ui.component.data.meta.ContainerDataUnit in project jmix by jmix-framework.

the class ItemOrderableAction method sortTableDsByItemsOrderNum.

protected void sortTableDsByItemsOrderNum() {
    DataUnit dataUnit = target.getItems();
    if (dataUnit instanceof ContainerDataUnit) {
        ContainerDataUnit containerDataUnit = (ContainerDataUnit) dataUnit;
        CollectionContainer<? extends OrderableEntity> collectionContainer = containerDataUnit.getContainer();
        List sortedItems = collectionContainer.getItems().stream().sorted(Comparator.comparingLong(OrderableEntity::getOrderNum)).collect(Collectors.toList());
        collectionContainer.setItems(sortedItems);
    }
}
Also used : ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) OrderableEntity(io.jmix.reports.entity.wizard.OrderableEntity) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 12 with ContainerDataUnit

use of io.jmix.ui.component.data.meta.ContainerDataUnit in project jmix by jmix-framework.

the class ListPrintFormAction method printAll.

protected void printAll() {
    ContainerDataUnit unit = (ContainerDataUnit) target.getItems();
    CollectionContainer container = unit.getContainer();
    if (container instanceof CollectionPropertyContainer) {
        // as CollectionPropertyContainer does not have loader it always fetches all records,
        // so print these records as selected
        printSelected(new HashSet(container.getMutableItems()));
        return;
    }
    CollectionLoader loader = (CollectionLoader) ((HasLoader) unit.getContainer()).getLoader();
    MetaClass metaClass = container.getEntityMetaClass();
    LoadContext loadContext = loader.createLoadContext();
    ParameterPrototype parameterPrototype = new ParameterPrototype(metaClass.getName());
    parameterPrototype.setMetaClassName(metaClass.getName());
    LoadContext.Query query = loadContext.getQuery();
    parameterPrototype.setQueryString(query.getQueryString());
    parameterPrototype.setQueryParams(query.getParameters());
    parameterPrototype.setCondition(query.getCondition());
    parameterPrototype.setSort(query.getSort());
    if (!Strings.isNullOrEmpty(loadContext.getFetchPlan().getName())) {
        parameterPrototype.setFetchPlanName(loadContext.getFetchPlan().getName());
    } else {
        parameterPrototype.setFetchPlan(loadContext.getFetchPlan());
    }
    Window window = ComponentsHelper.getWindowNN(target);
    openRunReportScreen(window.getFrameOwner(), parameterPrototype, metaClass);
}
Also used : Window(io.jmix.ui.component.Window) ParameterPrototype(io.jmix.reports.app.ParameterPrototype) MetaClass(io.jmix.core.metamodel.model.MetaClass) LoadContext(io.jmix.core.LoadContext) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) HashSet(java.util.HashSet)

Example 13 with ContainerDataUnit

use of io.jmix.ui.component.data.meta.ContainerDataUnit in project jmix by jmix-framework.

the class PivotScreenBuilder method getPropertiesWithLocale.

protected Map<String, String> getPropertiesWithLocale() {
    Map<String, String> resultMap = new HashMap<>();
    ContainerDataUnit containerDataUnit = (ContainerDataUnit) target.getItems();
    FetchPlan fetchPlan = containerDataUnit.getContainer().getFetchPlan();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    List<String> appliedProperties = includedProperties == null ? new ArrayList<>() : new ArrayList<>(includedProperties);
    if (appliedProperties.isEmpty()) {
        appliedProperties.addAll(getPropertiesFromView(metaClass, fetchPlan));
        appliedProperties.addAll(getEmbeddedIdProperties(metaClass));
    }
    appliedProperties.addAll(additionalProperties == null ? Collections.emptyList() : additionalProperties);
    // exclude properties
    if (!CollectionUtils.isEmpty(excludedProperties)) {
        appliedProperties.removeAll(excludedProperties);
    }
    appliedProperties = removeNonExistingProperties(appliedProperties, metaClass, fetchPlan);
    for (String property : appliedProperties) {
        MetaPropertyPath mpp = metaClass.getPropertyPath(property);
        if (mpp == null) {
            continue;
        }
        MetaProperty metaProperty = mpp.getMetaProperty();
        Class<?> declaringClass = metaProperty.getDeclaringClass();
        MetaClass propertyMetaClass = declaringClass == null ? null : metadata.getClass(declaringClass);
        if (!isManagedProperty(metaProperty, propertyMetaClass)) {
            continue;
        }
        resultMap.put(property, messageTools.getPropertyCaption(metaProperty));
    }
    return resultMap;
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 14 with ContainerDataUnit

use of io.jmix.ui.component.data.meta.ContainerDataUnit in project jmix by jmix-framework.

the class ShowPivotAction method showPivotTable.

@SuppressWarnings("unchecked")
protected void showPivotTable(ShowPivotMode mode) {
    Frame frame = target.getFrame();
    if (frame == null) {
        throw new IllegalStateException(String.format("ShowPivotAction cannot be used by component '%s' which is not added to frame", target.getId()));
    }
    Collection items;
    if (ShowPivotMode.ALL_ROWS.equals(mode)) {
        if (target.getItems() instanceof ContainerDataUnit) {
            CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
            items = container.getItems();
        } else {
            items = Collections.emptyList();
        }
    } else {
        items = target.getSelected();
    }
    PivotScreenBuilder showPivotManager = applicationContext.getBean(PivotScreenBuilder.class, target);
    showPivotManager.withItems(items).withIncludedProperties(parseProperties(includedProperties)).withExcludedProperties(parseProperties(excludedProperties)).build().show();
}
Also used : Frame(io.jmix.ui.component.Frame) Collection(java.util.Collection) CollectionContainer(io.jmix.ui.model.CollectionContainer) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 15 with ContainerDataUnit

use of io.jmix.ui.component.data.meta.ContainerDataUnit in project jmix by jmix-framework.

the class AddAction method isPermitted.

@Override
protected boolean isPermitted() {
    if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
        return false;
    }
    ContainerDataUnit containerDataUnit = (ContainerDataUnit) target.getItems();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    if (metaClass == null) {
        return false;
    }
    if (containerDataUnit.getContainer() instanceof Nested) {
        Nested nestedContainer = (Nested) containerDataUnit.getContainer();
        MetaClass masterMetaClass = nestedContainer.getMaster().getEntityMetaClass();
        MetaProperty metaProperty = masterMetaClass.getProperty(nestedContainer.getProperty());
        UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(masterMetaClass, metaProperty.getName());
        accessManager.applyRegisteredConstraints(attributeContext);
        if (!attributeContext.canModify()) {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) Nested(io.jmix.ui.model.Nested) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Aggregations

ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)20 MetaClass (io.jmix.core.metamodel.model.MetaClass)8 DataUnit (io.jmix.ui.component.data.DataUnit)6 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)5 Nested (io.jmix.ui.model.Nested)4 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)3 EmptyDataUnit (io.jmix.ui.component.data.meta.EmptyDataUnit)3 EntityDataUnit (io.jmix.ui.component.data.meta.EntityDataUnit)3 CollectionContainer (io.jmix.ui.model.CollectionContainer)3 Screens (io.jmix.ui.Screens)2 io.jmix.ui.component (io.jmix.ui.component)2 Frame (io.jmix.ui.component.Frame)2 Window (io.jmix.ui.component.Window)2 PaginationDataBinder (io.jmix.ui.component.pagination.data.PaginationDataBinder)2 PaginationDataUnitBinder (io.jmix.ui.component.pagination.data.PaginationDataUnitBinder)2 PaginationEmptyBinder (io.jmix.ui.component.pagination.data.PaginationEmptyBinder)2 DataContext (io.jmix.ui.model.DataContext)2 DataLoader (io.jmix.ui.model.DataLoader)2 HasLoader (io.jmix.ui.model.HasLoader)2 FrameOwner (io.jmix.ui.screen.FrameOwner)2