Search in sources :

Example 51 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.

the class OriginalEntityLoadInfo method create.

/**
 * Create a new info instance.
 * @param entity    entity instance
 * @return          info instance
 */
public static OriginalEntityLoadInfo create(Entity entity) {
    Objects.requireNonNull(entity, "entity is null");
    Metadata metadata = AppBeans.get(Metadata.NAME);
    MetaClass metaClass = metadata.getSession().getClassNN(entity.getClass());
    MetaClass originalMetaClass = metadata.getExtendedEntities().getOriginalMetaClass(metaClass);
    if (originalMetaClass != null) {
        metaClass = originalMetaClass;
    }
    MetaProperty primaryKeyProperty = metadata.getTools().getPrimaryKeyProperty(metaClass);
    boolean stringKey = primaryKeyProperty != null && primaryKeyProperty.getJavaType().equals(String.class);
    return new OriginalEntityLoadInfo((UUID) entity.getId(), metaClass, stringKey);
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 52 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.

the class RuntimePropertiesFrame method loadValidators.

protected void loadValidators(FieldGroup fieldGroup, FieldGroup.FieldConfig field) {
    MetaPropertyPath metaPropertyPath = rds.getMetaClass().getPropertyPath(field.getProperty());
    if (metaPropertyPath != null) {
        MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
        Field.Validator validator = getValidator(metaProperty);
        if (validator != null) {
            field.addValidator(validator);
        }
    }
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) DynamicAttributesMetaProperty(com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaProperty) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 53 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.

the class CreateAction method isPermitted.

/**
 * Check permissions for Action
 */
@Override
protected boolean isPermitted() {
    if (target == null || target.getDatasource() == null) {
        return false;
    }
    CollectionDatasource ownerDatasource = target.getDatasource();
    MetaClass metaClass = ownerDatasource.getMetaClass();
    boolean createPermitted = security.isEntityOpPermitted(metaClass, EntityOp.CREATE);
    if (!createPermitted) {
        return false;
    }
    if (ownerDatasource instanceof PropertyDatasource) {
        PropertyDatasource propertyDatasource = (PropertyDatasource) ownerDatasource;
        MetaClass parentMetaClass = propertyDatasource.getMaster().getMetaClass();
        MetaProperty metaProperty = propertyDatasource.getProperty();
        boolean attrPermitted = security.isEntityAttrPermitted(parentMetaClass, metaProperty.getName(), EntityAttrAccess.MODIFY);
        if (!attrPermitted) {
            return false;
        }
    }
    return super.isPermitted();
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 54 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty 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 55 with MetaProperty

use of com.haulmont.chile.core.model.MetaProperty 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)

Aggregations

MetaProperty (com.haulmont.chile.core.model.MetaProperty)157 MetaClass (com.haulmont.chile.core.model.MetaClass)102 Entity (com.haulmont.cuba.core.entity.Entity)44 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)26 BaseGenericIdEntity (com.haulmont.cuba.core.entity.BaseGenericIdEntity)21 Range (com.haulmont.chile.core.model.Range)13 Nullable (javax.annotation.Nullable)11 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)9 java.util (java.util)9 Element (org.dom4j.Element)9 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)8 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Query (com.haulmont.cuba.core.Query)5 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)5 Collection (java.util.Collection)5 MessageTools (com.haulmont.cuba.core.global.MessageTools)4 PropertyDatasource (com.haulmont.cuba.gui.data.PropertyDatasource)4 Logger (org.slf4j.Logger)4