Search in sources :

Example 1 with ContainerDataUnit

use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.

the class RemoveAction method checkRemovePermission.

protected boolean checkRemovePermission() {
    ContainerDataUnit<E> containerDataUnit = (ContainerDataUnit) target.getItems();
    MetaClass metaClass = containerDataUnit.getEntityMetaClass();
    if (metaClass == null) {
        return false;
    }
    boolean entityOpPermitted = security.isEntityOpPermitted(metaClass, EntityOp.DELETE);
    if (!entityOpPermitted) {
        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 true;
}
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 2 with ContainerDataUnit

use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.

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.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 3 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 4 with ContainerDataUnit

use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.

the class RefreshAction method execute.

/**
 * Executes the action.
 */
@Override
public void execute() {
    if (target == null) {
        throw new IllegalStateException("RefreshAction target is not set");
    }
    if (target.getItems() instanceof EmptyDataUnit) {
        return;
    }
    if (!(target.getItems() instanceof ContainerDataUnit)) {
        throw new IllegalStateException("RefreshAction target is null or does not implement SupportsContainerBinding");
    }
    CollectionContainer container = ((ContainerDataUnit) target.getItems()).getContainer();
    if (container == null) {
        throw new IllegalStateException("RefreshAction target is not bound to CollectionContainer");
    }
    DataLoader loader = null;
    if (container instanceof HasLoader) {
        loader = ((HasLoader) container).getLoader();
    }
    if (loader != null) {
        DataContext dataContext = loader.getDataContext();
        if (dataContext != null) {
            for (Object entity : container.getItems()) {
                dataContext.evict((Entity) entity);
            }
        }
        loader.load();
    } else {
        log.warn("RefreshAction '{}' target container has no loader, refresh is impossible", getId());
    }
}
Also used : DataLoader(com.haulmont.cuba.gui.model.DataLoader) DataContext(com.haulmont.cuba.gui.model.DataContext) EmptyDataUnit(com.haulmont.cuba.gui.components.data.meta.EmptyDataUnit) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) HasLoader(com.haulmont.cuba.gui.model.HasLoader) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 5 with ContainerDataUnit

use of com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit in project cuba by cuba-platform.

the class EditorBuilderProcessor method buildEditor.

@SuppressWarnings("unchecked")
public <E extends Entity, S extends Screen> S buildEditor(EditorBuilder<E> builder) {
    FrameOwner origin = builder.getOrigin();
    Screens screens = getScreenContext(origin).getScreens();
    ListComponent<E> listComponent = builder.getListComponent();
    CollectionContainer<E> container = builder.getContainer();
    if (container == null && listComponent != null) {
        DataUnit items = listComponent.getItems();
        container = items instanceof ContainerDataUnit ? ((ContainerDataUnit) items).getContainer() : null;
    }
    E entity = initEntity(builder, container);
    if (builder.getMode() == EditMode.EDIT && entity == null) {
        throw new IllegalStateException(String.format("Editor of %s cannot be open with mode EDIT, entity is not set", builder.getEntityClass()));
    }
    Screen screen = createScreen(builder, screens, entity);
    EditorScreen<E> editorScreen = (EditorScreen<E>) screen;
    editorScreen.setEntityToEdit(entity);
    DataContext parentDataContext = setupParentDataContext(origin, screen, container, builder.getParentDataContext());
    if (container != null) {
        CollectionContainer<E> ct = container;
        screen.addAfterCloseListener(event -> {
            CloseAction closeAction = event.getCloseAction();
            if (isCommitCloseAction(closeAction)) {
                E entityFromEditor = getCommittedEntity(editorScreen, parentDataContext);
                E reloadedEntity = reloadIfNeeded(entityFromEditor, ct, builder);
                E committedEntity = transform(reloadedEntity, builder);
                E mergedEntity = merge(committedEntity, origin, parentDataContext);
                if (builder.getMode() == EditMode.CREATE) {
                    boolean addsFirst;
                    if (!(ct instanceof Nested)) {
                        addsFirst = clientConfig.getCreateActionAddsFirst();
                        if (builder.getAddFirst() != null) {
                            addsFirst = builder.getAddFirst();
                        }
                    } else {
                        addsFirst = false;
                    }
                    if (ct instanceof Nested || !addsFirst) {
                        ct.getMutableItems().add(mergedEntity);
                    } else {
                        ct.getMutableItems().add(0, mergedEntity);
                    }
                } else {
                    ct.replaceItem(mergedEntity);
                }
            }
            if (listComponent instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
                ((com.haulmont.cuba.gui.components.Component.Focusable) listComponent).focus();
            }
        });
    }
    HasValue<E> field = builder.getField();
    if (field != null) {
        if (parentDataContext == null && field instanceof HasValueSource) {
            ValueSource fieldValueSource = ((HasValueSource) field).getValueSource();
            if (fieldValueSource instanceof EntityValueSource) {
                if (isCompositionProperty((EntityValueSource) fieldValueSource)) {
                    DataContext thisDataContext = UiControllerUtils.getScreenData(origin).getDataContext();
                    DataContext dataContext = UiControllerUtils.getScreenData(screen).getDataContext();
                    checkDataContext(screen, dataContext);
                    dataContext.setParent(thisDataContext);
                }
            }
        }
        screen.addAfterCloseListener(event -> {
            CloseAction closeAction = event.getCloseAction();
            if (isCommitCloseAction(closeAction)) {
                E entityFromEditor = editorScreen.getEditedEntity();
                E editedEntity = transform(entityFromEditor, builder);
                if (field instanceof LookupPickerField) {
                    LookupPickerField lookupPickerField = ((LookupPickerField) field);
                    Options options = lookupPickerField.getOptions();
                    if (options instanceof EntityOptions) {
                        EntityOptions entityOptions = (EntityOptions) options;
                        if (entityOptions.containsItem(editedEntity)) {
                            entityOptions.updateItem(editedEntity);
                        }
                    }
                }
                if (field instanceof SupportsUserAction) {
                    ((SupportsUserAction) field).setValueFromUser(editedEntity);
                } else {
                    field.setValue(editedEntity);
                }
            }
            if (field instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
                ((com.haulmont.cuba.gui.components.Component.Focusable) field).focus();
            }
        });
    }
    if (builder instanceof EditorClassBuilder) {
        @SuppressWarnings("unchecked") Consumer<AfterScreenCloseEvent> closeListener = ((EditorClassBuilder) builder).getCloseListener();
        if (closeListener != null) {
            screen.addAfterCloseListener(new AfterCloseListenerAdapter(closeListener));
        }
    }
    return (S) screen;
}
Also used : EntityOptions(com.haulmont.cuba.gui.components.data.meta.EntityOptions) Options(com.haulmont.cuba.gui.components.data.Options) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) EntityOptions(com.haulmont.cuba.gui.components.data.meta.EntityOptions) DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) Screens(com.haulmont.cuba.gui.Screens) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

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