Search in sources :

Example 46 with Datasource

use of com.haulmont.cuba.gui.data.Datasource 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 47 with Datasource

use of com.haulmont.cuba.gui.data.Datasource 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 48 with Datasource

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

the class DesktopAbstractField method getAlternativeDebugId.

@Override
protected String getAlternativeDebugId() {
    if (id != null) {
        return id;
    }
    Datasource datasource = getDatasource();
    MetaPropertyPath metaPropertyPath = getMetaPropertyPath();
    if (datasource != null && StringUtils.isNotEmpty(datasource.getId()) && metaPropertyPath != null) {
        return getClass().getSimpleName() + "_" + datasource.getId() + "_" + metaPropertyPath.toString();
    }
    return getClass().getSimpleName();
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 49 with Datasource

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

the class DesktopFieldGroup method bindDeclarativeFieldConfigs.

protected void bindDeclarativeFieldConfigs() {
    List<Integer> reattachColumns = new ArrayList<>();
    for (FieldConfig fc : getColumnOrderedFields()) {
        if (!fc.isCustom() && !fc.isBound()) {
            FieldConfigImpl fci = (FieldConfigImpl) fc;
            Datasource targetDs = fc.getTargetDatasource();
            if (targetDs == null) {
                throw new IllegalStateException(String.format("Unable to get datasource for field '%s'", id));
            }
            FieldGroupFieldFactory.GeneratedField generatedField = fieldFactory.createField(fc);
            Component fieldComponent = generatedField.getComponent();
            fci.assignComponent(fieldComponent);
            fci.setAttachMode(generatedField.getAttachMode());
            setupFieldComponent(fci);
            DesktopAbstractComponent fieldImpl = (DesktopAbstractComponent) fieldComponent;
            fci.setComposition(fieldImpl);
            assignTypicalAttributes(fieldComponent);
            if (generatedField.getAttachMode() == FieldAttachMode.APPLY_DEFAULTS) {
                applyFieldDefaults(fci);
            }
            int columnIndex = fci.getColumn();
            if (!reattachColumns.contains(columnIndex)) {
                reattachColumns.add(columnIndex);
            }
        }
    }
    if (!reattachColumns.isEmpty()) {
        this.rows = detectRowsCount();
        for (Integer reattachColumnIndex : reattachColumns) {
            reattachColumnFields(reattachColumnIndex);
        }
    }
    impl.revalidate();
    impl.repaint();
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Component(com.haulmont.cuba.gui.components.Component)

Example 50 with Datasource

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

the class WebDataGrid method createItemDatasource.

protected Datasource createItemDatasource(Entity item) {
    Datasource fieldDatasource = DsBuilder.create().setAllowCommit(false).setMetaClass(datasource.getMetaClass()).setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setViewName(View.LOCAL).buildDatasource();
    ((DatasourceImplementation) fieldDatasource).valid();
    // noinspection unchecked
    fieldDatasource.setItem(item);
    return fieldDatasource;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) PropertyDatasource(com.haulmont.cuba.gui.data.PropertyDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Aggregations

Datasource (com.haulmont.cuba.gui.data.Datasource)111 Ignore (org.junit.Ignore)66 Test (org.junit.Test)66 Component (com.haulmont.cuba.gui.components.Component)61 User (com.haulmont.cuba.security.entity.User)56 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)53 Assert.assertTrue (org.junit.Assert.assertTrue)49 Assert.assertEquals (org.junit.Assert.assertEquals)44 Group (com.haulmont.cuba.security.entity.Group)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 Assert (org.junit.Assert)22 List (java.util.List)20 DsBuilder (com.haulmont.cuba.gui.data.DsBuilder)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)12 Date (java.util.Date)11 Entity (com.haulmont.cuba.core.entity.Entity)10 Role (com.haulmont.cuba.security.entity.Role)10 MetaClass (com.haulmont.chile.core.model.MetaClass)9 LookupField (com.haulmont.cuba.gui.components.LookupField)9