use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.
the class ExcludeAction method isPermitted.
@Override
protected boolean isPermitted() {
if (target == null || !(target.getItems() instanceof ContainerDataUnit)) {
return false;
}
ContainerDataUnit<E> 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.getPropertyNN(nestedContainer.getProperty());
boolean attrPermitted = security.isEntityAttrUpdatePermitted(masterMetaClass, metaProperty.getName());
if (!attrPermitted) {
return false;
}
}
return super.isPermitted();
}
use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.
the class WebFilterHelper method initTableFtsTooltips.
@Override
public void initTableFtsTooltips(ListComponent listComponent, MetaClass metaClass, String searchTerm) {
FtsFilterHelper ftsFilterHelper;
if (beanLocator.containsBean(FtsFilterHelper.NAME)) {
ftsFilterHelper = beanLocator.get(FtsFilterHelper.class);
} else {
return;
}
if (listComponent instanceof Table) {
Map<Object, String> tooltipsCache = new HashMap<>();
Map<Object, String> metaClassesCache = new HashMap<>();
listComponent.withUnwrapped(com.vaadin.v7.ui.Table.class, vTable -> vTable.setItemDescriptionGenerator((source, itemId, propertyId) -> {
return tooltipsCache.computeIfAbsent(itemId, k -> {
if (k instanceof GroupInfo) {
return "";
}
return ftsFilterHelper.buildTableTooltip(metaClassesCache.computeIfAbsent(itemId, id -> {
DataUnit dataUnit = listComponent.getItems();
Entity<?> entity = null;
if (dataUnit instanceof DatasourceDataUnit) {
// legacy GUI
entity = ((DatasourceDataUnit) dataUnit).getDatasource().getItem(id);
} else if (dataUnit instanceof ContainerDataUnit) {
entity = ((ContainerDataUnit) dataUnit).getContainer().getItem(id);
}
if (entity != null)
return entity.getMetaClass().getName();
return metaClass.getName();
}), k, searchTerm);
});
}));
} else if (listComponent instanceof DataGrid) {
((DataGrid) listComponent).setRowDescriptionProvider(o -> {
if (o instanceof Entity) {
Entity entity = (Entity) o;
return ftsFilterHelper.buildTableTooltip(entity.getMetaClass().getName(), entity.getId(), searchTerm);
} else {
return null;
}
}, ContentMode.HTML);
}
}
use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.
the class WebEntityLinkField method afterCommitOpenedEntity.
protected void afterCommitOpenedEntity(Entity item) {
MetaProperty metaProperty = getMetaPropertyForEditedValue();
if (metaProperty != null && metaProperty.getRange().isClass()) {
if (getValueSource() != null) {
boolean ownerDsModified = false;
boolean nonModifiedInTable = false;
DatasourceImplementation ownerDs = null;
CollectionContainer ownerCollectionCont = null;
if (getCollectionDatasourceFromOwner() != null) {
ownerDs = ((DatasourceImplementation) getCollectionDatasourceFromOwner());
nonModifiedInTable = !ownerDs.getItemsToUpdate().contains(((EntityValueSource) getValueSource()).getItem());
ownerDsModified = ownerDs.isModified();
} else if (getCollectionContainerFromOwner() != null) {
ownerCollectionCont = ((ContainerDataUnit) owner.getItems()).getContainer();
ownerCollectionCont.mute();
}
// noinspection unchecked
setValueSilently((V) item);
// remove from items to update if it was not modified before setValue
if (ownerDs != null) {
if (nonModifiedInTable) {
ownerDs.getItemsToUpdate().remove(getDatasource().getItem());
}
ownerDs.setModified(ownerDsModified);
} else if (ownerCollectionCont != null) {
ownerCollectionCont.unmute();
}
} else {
// noinspection unchecked
setValue((V) item);
}
// if we edit property with non Entity type and set ListComponent owner
} else if (owner != null) {
if (getCollectionDatasourceFromOwner() != null) {
// noinspection unchecked
getCollectionDatasourceFromOwner().updateItem(item);
} else if (getCollectionContainerFromOwner() != null) {
// do not listen changes in collection
getCollectionContainerFromOwner().mute();
// noinspection unchecked
getCollectionContainerFromOwner().replaceItem(item);
setValueSilently(item.getValueEx(getMetaPropertyPath()));
// listen changes
getCollectionContainerFromOwner().unmute();
}
if (owner instanceof Focusable) {
// focus owner
((Focusable) owner).focus();
}
// if we edit property with non Entity type
} else {
// noinspection unchecked
setValueSilently((V) item);
}
}
use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.
the class RemoveOperation method builder.
/**
* Creates a remove builder using list component, e.g. {@link Table} or {@link DataGrid}.
*
* @param listComponent list component
* @param <E> type of entity
*/
public <E extends Entity> RemoveBuilder<E> builder(ListComponent<E> listComponent) {
checkNotNullArgument(listComponent);
checkNotNullArgument(listComponent.getFrame());
FrameOwner frameOwner = listComponent.getFrame().getFrameOwner();
Class<E> entityClass;
DataUnit items = listComponent.getItems();
if (items instanceof ContainerDataUnit) {
entityClass = ((ContainerDataUnit) items).getEntityMetaClass().getJavaClass();
} else {
throw new IllegalStateException(String.format("Component %s is not bound to data", listComponent));
}
return builder(entityClass, frameOwner).withListComponent(listComponent);
}
use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.
the class UiTestIds method getInferredTestId.
@Nullable
public static String getInferredTestId(DataUnit dataUnit, String suffix) {
if (dataUnit instanceof ContainerDataUnit) {
ContainerDataUnit dcDataUnit = (ContainerDataUnit) dataUnit;
MetaClass entityMetaClass = dcDataUnit.getEntityMetaClass();
return entityMetaClass.getName() + suffix;
} else if (dataUnit instanceof DatasourceDataUnit) {
DatasourceDataUnit dsDataUnit = (DatasourceDataUnit) dataUnit;
MetaClass entityMetaClass = dsDataUnit.getDatasource().getMetaClass();
return entityMetaClass.getName() + suffix;
}
return null;
}
Aggregations