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);
}
}
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);
}
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;
}
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();
}
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();
}
Aggregations