Search in sources :

Example 26 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class EditAction method isPermitted.

/**
 * Check permissions for Action
 */
@Override
protected boolean isPermitted() {
    if (target == null || target.getDatasource() == null) {
        return false;
    }
    CollectionDatasource ownerDatasource = target.getDatasource();
    boolean entityOpPermitted = security.isEntityOpPermitted(ownerDatasource.getMetaClass(), EntityOp.READ);
    if (!entityOpPermitted) {
        return false;
    }
    return super.isPermitted();
}
Also used : CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 27 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class EditAction method actionPerform.

/**
 * This method is invoked by the action owner component.
 *
 * @param component component invoking the action
 */
@Override
public void actionPerform(Component component) {
    if (beforeActionPerformedHandler != null) {
        if (!beforeActionPerformedHandler.beforeActionPerformed())
            return;
    }
    final Set selected = target.getSelected();
    if (selected.size() == 1) {
        Datasource parentDs = null;
        final CollectionDatasource datasource = target.getDatasource();
        if (datasource instanceof PropertyDatasource) {
            MetaProperty metaProperty = ((PropertyDatasource) datasource).getProperty();
            if (metaProperty.getType().equals(MetaProperty.Type.COMPOSITION)) {
                parentDs = datasource;
            }
        }
        Map<String, Object> params = prepareWindowParams();
        internalOpenEditor(datasource, datasource.getItem(), parentDs, params);
    } else if (selected.size() > 1 && bulkEditorIntegration.isEnabled()) {
        boolean isBulkEditorPermitted = userSession.isSpecificPermitted(BulkEditor.PERMISSION);
        if (isBulkEditorPermitted) {
            // if bulk editor integration enabled and permitted for user
            Map<String, Object> params = ParamsMap.of("metaClass", target.getDatasource().getMetaClass(), "selected", selected, "exclude", bulkEditorIntegration.getExcludePropertiesRegex(), "fieldValidators", bulkEditorIntegration.getFieldValidators(), "modelValidators", bulkEditorIntegration.getModelValidators());
            Window bulkEditor = target.getFrame().openWindow("bulkEditor", bulkEditorIntegration.getOpenType(), params);
            bulkEditor.addCloseListener(actionId -> {
                if (Window.COMMIT_ACTION_ID.equals(actionId)) {
                    target.getDatasource().refresh();
                }
                target.requestFocus();
                Consumer<BulkEditorCloseEvent> afterEditorCloseHandler = bulkEditorIntegration.getAfterEditorCloseHandler();
                if (afterEditorCloseHandler != null) {
                    afterEditorCloseHandler.accept(new BulkEditorCloseEvent(this, bulkEditor, actionId));
                }
            });
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) java.util(java.util) Datasource(com.haulmont.cuba.gui.data.Datasource) DynamicAttributesGuiTools(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ParamsMap(com.haulmont.bali.util.ParamsMap) CubaIcon(com.haulmont.cuba.gui.icons.CubaIcon) BaseGenericIdEntity(com.haulmont.cuba.core.entity.BaseGenericIdEntity) Icons(com.haulmont.cuba.gui.icons.Icons) Supplier(java.util.function.Supplier) MetaClass(com.haulmont.chile.core.model.MetaClass) Scope(org.springframework.context.annotation.Scope) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Consumer(java.util.function.Consumer) EntityOp(com.haulmont.cuba.security.entity.EntityOp) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) ClientConfig(com.haulmont.cuba.client.ClientConfig) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Entity(com.haulmont.cuba.core.entity.Entity) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Consumer(java.util.function.Consumer) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty) ParamsMap(com.haulmont.bali.util.ParamsMap)

Example 28 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class ExcludeAction method doRemove.

@SuppressWarnings("unchecked")
@Override
protected void doRemove(Set<Entity> selected, boolean autocommit) {
    @SuppressWarnings({ "unchecked" }) CollectionDatasource ds = target.getDatasource();
    if (ds instanceof NestedDatasource) {
        // Clear reference to master entity
        Datasource masterDs = ((NestedDatasource) ds).getMaster();
        MetaProperty metaProperty = ((NestedDatasource) ds).getProperty();
        if (masterDs != null && metaProperty != null) {
            MetaProperty inverseProp = metaProperty.getInverse();
            if (inverseProp != null) {
                ExtendedEntities extendedEntities = metadata.getExtendedEntities();
                Class inversePropClass = extendedEntities.getEffectiveClass(inverseProp.getDomain());
                Class dsClass = extendedEntities.getEffectiveClass(ds.getMetaClass());
                if (inversePropClass.isAssignableFrom(dsClass)) {
                    for (Entity item : selected) {
                        item.setValue(inverseProp.getName(), null);
                    }
                }
            }
        }
    }
    for (Entity item : selected) {
        ds.modifyItem(item);
        ds.excludeItem(item);
    }
    if (autocommit && (ds.getCommitMode() != Datasource.CommitMode.PARENT)) {
        try {
            ds.commit();
        } catch (RuntimeException e) {
            ds.refresh();
            throw e;
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) ExtendedEntities(com.haulmont.cuba.core.global.ExtendedEntities) Entity(com.haulmont.cuba.core.entity.Entity) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 29 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class ExcludeAction method checkRemovePermission.

@Override
protected boolean checkRemovePermission() {
    CollectionDatasource ds = target.getDatasource();
    if (ds instanceof PropertyDatasource) {
        PropertyDatasource propertyDatasource = (PropertyDatasource) ds;
        MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass();
        MetaProperty metaProperty = propertyDatasource.getProperty();
        boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
        if (!attrPermitted) {
            return false;
        }
    }
    return true;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 30 with CollectionDatasource

use of com.haulmont.cuba.gui.data.CollectionDatasource in project cuba by cuba-platform.

the class DesktopTokenList method setLookup.

@Override
public void setLookup(boolean lookup) {
    if (this.lookup != lookup) {
        if (lookup) {
            lookupAction = new PickerField.LookupAction(lookupPickerField) {

                @Nonnull
                @Override
                protected Map<String, Object> prepareScreenParams() {
                    Map<String, Object> screenParams = super.prepareScreenParams();
                    if (isMultiSelect()) {
                        screenParams = new HashMap<>(screenParams);
                        WindowParams.MULTI_SELECT.set(screenParams, true);
                        // for backward compatibility
                        screenParams.put("multiSelect", "true");
                    }
                    return screenParams;
                }

                @SuppressWarnings("unchecked")
                @Override
                protected void handleLookupWindowSelection(Collection items) {
                    if (items.isEmpty()) {
                        return;
                    }
                    @SuppressWarnings("unchecked") Collection<Entity> selected = items;
                    CollectionDatasource optionsDatasource = lookupPickerField.getOptionsDatasource();
                    if (optionsDatasource != null && lookupPickerField.isRefreshOptionsOnLookupClose()) {
                        optionsDatasource.refresh();
                        if (datasource != null) {
                            for (Object obj : getDatasource().getItems()) {
                                Entity entity = (Entity) obj;
                                if (getOptionsDatasource().containsItem(entity.getId())) {
                                    datasource.updateItem(getOptionsDatasource().getItem(entity.getId()));
                                }
                            }
                        }
                    }
                    // add all selected items to tokens
                    if (itemChangeHandler != null) {
                        for (Entity newItem : selected) {
                            itemChangeHandler.addItem(newItem);
                        }
                    } else if (datasource != null) {
                        // get master entity and inverse attribute in case of nested datasource
                        Entity masterEntity = getMasterEntity(datasource);
                        MetaProperty inverseProp = getInverseProperty(datasource);
                        for (Entity newItem : selected) {
                            if (!datasource.containsItem(newItem.getId())) {
                                // Initialize reference to master entity
                                if (inverseProp != null && isInitializeMasterReference(inverseProp)) {
                                    newItem.setValue(inverseProp.getName(), masterEntity);
                                }
                                datasource.addItem(newItem);
                            }
                        }
                    }
                    afterSelect(items);
                    if (afterLookupSelectionHandler != null) {
                        afterLookupSelectionHandler.onSelect(items);
                    }
                }
            };
            lookupPickerField.addAction(lookupAction);
            if (getLookupScreen() != null) {
                lookupAction.setLookupScreen(getLookupScreen());
            }
            lookupAction.setLookupScreenOpenType(lookupOpenMode);
            lookupAction.setLookupScreenParams(lookupScreenParams);
            lookupAction.setLookupScreenDialogParams(lookupScreenDialogParams);
        } else {
            lookupPickerField.removeAction(lookupAction);
        }
        lookupAction.setAfterLookupCloseHandler((window, actionId) -> {
            if (afterLookupCloseHandler != null) {
                afterLookupCloseHandler.onClose(window, actionId);
            }
        });
        lookupAction.setAfterLookupSelectionHandler(items -> {
            if (afterLookupSelectionHandler != null) {
                afterLookupSelectionHandler.onSelect(items);
            }
        });
    }
    this.lookup = lookup;
    rootPanel.refreshComponent();
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) Nonnull(javax.annotation.Nonnull) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)67 Datasource (com.haulmont.cuba.gui.data.Datasource)39 UUID (java.util.UUID)24 Group (com.haulmont.cuba.security.entity.Group)23 User (com.haulmont.cuba.security.entity.User)23 ArrayList (java.util.ArrayList)23 Ignore (org.junit.Ignore)23 Test (org.junit.Test)23 Component (com.haulmont.cuba.gui.components.Component)20 List (java.util.List)19 Assert.assertEquals (org.junit.Assert.assertEquals)19 Assert.assertTrue (org.junit.Assert.assertTrue)19 Entity (com.haulmont.cuba.core.entity.Entity)15 MetaClass (com.haulmont.chile.core.model.MetaClass)10 MetaProperty (com.haulmont.chile.core.model.MetaProperty)10 LookupField (com.haulmont.cuba.gui.components.LookupField)8 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)7 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)7 Element (org.dom4j.Element)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7