Search in sources :

Example 6 with ContainerDataUnit

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();
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) Nested(com.haulmont.cuba.gui.model.Nested) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 7 with ContainerDataUnit

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);
    }
}
Also used : FtsFilterHelper(com.haulmont.cuba.gui.components.filter.FtsFilterHelper) java.util(java.util) GroupCondition(com.haulmont.cuba.gui.components.filter.condition.GroupCondition) DropLocation(com.vaadin.shared.ui.grid.DropLocation) Screen(com.haulmont.cuba.gui.screen.Screen) AppFolderEditWindow(com.haulmont.cuba.web.app.folders.AppFolderEditWindow) MetaClass(com.haulmont.chile.core.model.MetaClass) Inject(javax.inject.Inject) GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) Configuration(com.haulmont.cuba.core.global.Configuration) TreeGridDragSource(com.vaadin.ui.components.grid.TreeGridDragSource) ScreenFragment(com.haulmont.cuba.gui.screen.ScreenFragment) AppUI(com.haulmont.cuba.web.AppUI) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) Nullable(javax.annotation.Nullable) CubaTree(com.haulmont.cuba.web.widgets.CubaTree) Presentations(com.haulmont.cuba.gui.presentations.Presentations) DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) AbstractSearchFolder(com.haulmont.cuba.core.entity.AbstractSearchFolder) FoldersPane(com.haulmont.cuba.gui.components.mainwindow.FoldersPane) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) AbstractCondition(com.haulmont.cuba.gui.components.filter.condition.AbstractCondition) CubaTextField(com.haulmont.cuba.web.widgets.CubaTextField) TreeGridDropTarget(com.vaadin.ui.components.grid.TreeGridDropTarget) Folder(com.haulmont.cuba.core.entity.Folder) ConditionsTree(com.haulmont.cuba.gui.components.filter.ConditionsTree) FilterHelper(com.haulmont.cuba.gui.components.filter.FilterHelper) UiControllerUtils.getHostScreen(com.haulmont.cuba.gui.screen.UiControllerUtils.getHostScreen) WebConfig(com.haulmont.cuba.web.WebConfig) DatasourceDataUnit(com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit) ShortcutListenerDelegate(com.haulmont.cuba.web.gui.components.util.ShortcutListenerDelegate) Node(com.haulmont.bali.datastruct.Node) FolderEditWindow(com.haulmont.cuba.web.app.folders.FolderEditWindow) BeanLocator(com.haulmont.cuba.core.global.BeanLocator) CubaFoldersPane(com.haulmont.cuba.web.app.folders.CubaFoldersPane) UiComponents(com.haulmont.cuba.gui.UiComponents) DropMode(com.vaadin.shared.ui.grid.DropMode) Entity(com.haulmont.cuba.core.entity.Entity) Component(com.vaadin.ui.Component) Entity(com.haulmont.cuba.core.entity.Entity) GroupInfo(com.haulmont.cuba.gui.data.GroupInfo) DatasourceDataUnit(com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit) DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) DatasourceDataUnit(com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) FtsFilterHelper(com.haulmont.cuba.gui.components.filter.FtsFilterHelper)

Example 8 with ContainerDataUnit

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);
    }
}
Also used : DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 9 with ContainerDataUnit

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);
}
Also used : DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 10 with ContainerDataUnit

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;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) DatasourceDataUnit(com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) Nullable(javax.annotation.Nullable)

Aggregations

ContainerDataUnit (com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)12 MetaClass (com.haulmont.chile.core.model.MetaClass)5 MetaProperty (com.haulmont.chile.core.model.MetaProperty)4 DataUnit (com.haulmont.cuba.gui.components.data.DataUnit)3 Nested (com.haulmont.cuba.gui.model.Nested)3 Screens (com.haulmont.cuba.gui.Screens)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 DatasourceDataUnit (com.haulmont.cuba.gui.components.data.meta.DatasourceDataUnit)2 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)2 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)2 Screen (com.haulmont.cuba.gui.screen.Screen)2 Comment (com.haulmont.cuba.web.testmodel.compositecomponent.Comment)2 Node (com.haulmont.bali.datastruct.Node)1 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Folder (com.haulmont.cuba.core.entity.Folder)1 BeanLocator (com.haulmont.cuba.core.global.BeanLocator)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 UiComponents (com.haulmont.cuba.gui.UiComponents)1 HasValueSource (com.haulmont.cuba.gui.components.data.HasValueSource)1