Search in sources :

Example 51 with Datasource

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

the class WebEntityLinkField method setMetaClass.

@Override
public void setMetaClass(MetaClass metaClass) {
    final Datasource ds = getDatasource();
    if (ds != null) {
        throw new IllegalStateException("Datasource is not null");
    }
    this.metaClass = metaClass;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource)

Example 52 with Datasource

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

the class WebFieldGroup 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());
            com.vaadin.ui.Field fieldImpl = getFieldImplementation(fieldComponent);
            fci.setComposition(fieldImpl);
            assignTypicalAttributes(fieldComponent);
            if (generatedField.getAttachMode() == FieldAttachMode.APPLY_DEFAULTS) {
                applyFieldDefaults(fci);
            }
            assignDebugId(fc, fieldImpl);
            int columnIndex = fci.getColumn();
            if (!reattachColumns.contains(columnIndex)) {
                reattachColumns.add(columnIndex);
            }
        }
    }
    if (!reattachColumns.isEmpty()) {
        component.setRows(detectRowsCount());
        for (Integer reattachColumnIndex : reattachColumns) {
            reattachColumnFields(reattachColumnIndex);
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource)

Example 53 with Datasource

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

the class PermissionUiHelper method createPermissionItem.

/**
 * Add or edit permission item in datasource
 * @param ds Datasource
 * @param roleDs Role datasource
 * @param permissionTarget Permission identifier
 * @param type Permission type
 * @param value Permission value
 */
public static void createPermissionItem(CollectionDatasource<Permission, UUID> ds, Datasource<Role> roleDs, final String permissionTarget, PermissionType type, Integer value) {
    Permission permission = null;
    for (Permission p : ds.getItems()) {
        if (Objects.equals(p.getTarget(), permissionTarget)) {
            permission = p;
            break;
        }
    }
    if (permission == null) {
        // restore entity instead of create
        if (ds instanceof RestorablePermissionDatasource) {
            RestorablePermissionDatasource datasource = (RestorablePermissionDatasource) ds;
            permission = datasource.findRemovedEntity(p -> p != null && Objects.equals(p.getTarget(), permissionTarget));
            if (permission != null) {
                datasource.restoreEntity(permission);
            }
        }
    }
    if (permission == null) {
        Metadata metadata = AppBeans.get(Metadata.NAME);
        Permission newPermission = metadata.create(Permission.class);
        newPermission.setRole(roleDs.getItem());
        newPermission.setTarget(permissionTarget);
        newPermission.setType(type);
        newPermission.setValue(value);
        ds.addItem(newPermission);
    } else {
        permission.setValue(value);
    }
}
Also used : RestorablePermissionDatasource(com.haulmont.cuba.gui.app.security.ds.RestorablePermissionDatasource) PermissionVariant(com.haulmont.cuba.gui.app.security.entity.PermissionVariant) AttributePermissionVariant(com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant) Datasource(com.haulmont.cuba.gui.data.Datasource) PermissionType(com.haulmont.cuba.security.entity.PermissionType) RestorablePermissionDatasource(com.haulmont.cuba.gui.app.security.ds.RestorablePermissionDatasource) UUID(java.util.UUID) AppBeans(com.haulmont.cuba.core.global.AppBeans) Metadata(com.haulmont.cuba.core.global.Metadata) Objects(java.util.Objects) UiPermissionVariant(com.haulmont.cuba.gui.app.security.entity.UiPermissionVariant) Permission(com.haulmont.cuba.security.entity.Permission) Role(com.haulmont.cuba.security.entity.Role) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) Permission(com.haulmont.cuba.security.entity.Permission) Metadata(com.haulmont.cuba.core.global.Metadata)

Example 54 with Datasource

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

the class DesktopPickerField method setMetaClass.

@Override
public void setMetaClass(MetaClass metaClass) {
    Datasource ds = getDatasource();
    if (ds != null)
        throw new IllegalStateException("Datasource is not null");
    this.metaClass = metaClass;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource)

Example 55 with Datasource

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

the class WindowManager method openEditor.

public Window.Editor openEditor(WindowInfo windowInfo, Entity item, OpenType openType, Map<String, Object> params, Datasource parentDs) {
    if (params == null) {
        params = Collections.emptyMap();
    }
    checkCanOpenWindow(windowInfo, openType, params);
    Integer hashCode = getHash(windowInfo, params);
    String template = windowInfo.getTemplate();
    if (openType.getOpenMode() != OpenMode.DIALOG) {
        Window existingWindow = getWindow(hashCode);
        if (existingWindow != null) {
            params = createParametersMap(windowInfo, params);
            String caption = loadCaption(existingWindow, params);
            String description = loadDescription(existingWindow, params);
            showWindow(existingWindow, caption, description, openType, false);
            return (Window.Editor) existingWindow;
        }
    }
    params = createParametersMap(windowInfo, params);
    WindowParams.ITEM.set(params, item instanceof Datasource ? ((Datasource) item).getItem() : item);
    Window window;
    if (template != null) {
        window = createWindow(windowInfo, openType, params, LayoutLoaderConfig.getEditorLoaders(), false);
    } else {
        Class windowClass = windowInfo.getScreenClass();
        if (windowClass != null) {
            window = createWindow(windowInfo, params);
            if (!(window instanceof Window.Editor)) {
                throw new IllegalStateException(String.format("Class %s does't implement Window.Editor interface", windowClass));
            }
        } else {
            throw new IllegalStateException("Invalid WindowInfo: " + windowInfo);
        }
    }
    ((Window.Editor) window).setParentDs(parentDs);
    StopWatch setItemWatch = new Slf4JStopWatch(windowInfo.getId() + "#" + LifeCycle.SET_ITEM, LoggerFactory.getLogger(UIPerformanceLogger.class));
    ((Window.Editor) window).setItem(item);
    setItemWatch.stop();
    String caption = loadCaption(window, params);
    String description = loadDescription(window, params);
    showWindow(window, caption, description, openType, false);
    userActionsLog.trace("Editor {} was opened", windowInfo.getId());
    return (Window.Editor) window;
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) UIPerformanceLogger(com.haulmont.cuba.gui.logging.UIPerformanceLogger) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch)

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