Search in sources :

Example 1 with AttributePermissionVariant

use of com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant in project cuba by cuba-platform.

the class AttributePermissionsFrame method attachAllCheckboxListener.

protected void attachAllCheckboxListener(CheckBox checkBox, final AttributePermissionVariant activeVariant) {
    checkBox.addValueChangeListener(e -> {
        if (itemChanging) {
            return;
        }
        if (propertyPermissionsTable.getSelected().isEmpty()) {
            return;
        }
        itemChanging = true;
        MultiplePermissionTarget item = propertyPermissionsTable.getSingleSelected();
        if (item != null) {
            for (AttributePermissionControl control : permissionControls) {
                AttributePermissionVariant permissionVariant = PermissionUiHelper.getCheckBoxVariant(e.getValue(), activeVariant);
                control.markTargetPermission(permissionVariant);
                control.updateCheckers(permissionVariant);
            }
            // todo enforce value change
            propertyPermissionsTable.repaint();
            allModifyCheck.setValue(isAllModified());
            allReadOnlyCheck.setValue(isAllReadOnly());
            allHideCheck.setValue(isAllHide());
        }
        itemChanging = false;
    });
}
Also used : AttributePermissionVariant(com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant) MultiplePermissionTarget(com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget)

Example 2 with AttributePermissionVariant

use of com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant in project cuba by cuba-platform.

the class AttributePermissionsFrameCompanion method initPermissionColoredColumn.

@Override
public void initPermissionColoredColumn(final Table<MultiplePermissionTarget> propertyPermissionsTable) {
    propertyPermissionsTable.addGeneratedColumn("permissionsInfo", target -> {
        List<AttributeTarget> permissions = target.getPermissions();
        if (permissions.size() == 0)
            return null;
        Label label = AppConfig.getFactory().createComponent(Label.class);
        label.setHtmlEnabled(true);
        int i = 0;
        StringBuilder builder = new StringBuilder();
        Iterator<AttributeTarget> iterator = permissions.iterator();
        while (iterator.hasNext() && i < MultiplePermissionTarget.SHOW_PERMISSIONS_COUNT) {
            AttributeTarget attributeTarget = iterator.next();
            AttributePermissionVariant permissionVariant = attributeTarget.getPermissionVariant();
            if (permissionVariant != AttributePermissionVariant.NOTSET) {
                if (i < MultiplePermissionTarget.SHOW_PERMISSIONS_COUNT - 1) {
                    if (i > 0)
                        builder.append(", ");
                    builder.append("<span class=\"role-permission-").append(permissionVariant.getColor()).append("\">").append(attributeTarget.getId()).append("</span>");
                } else {
                    builder.append(", ...");
                }
                i++;
            }
        }
        label.setValue(builder.toString());
        return label;
    });
}
Also used : AttributePermissionVariant(com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant) Label(com.haulmont.cuba.gui.components.Label) AttributeTarget(com.haulmont.cuba.gui.app.security.entity.AttributeTarget)

Aggregations

AttributePermissionVariant (com.haulmont.cuba.gui.app.security.entity.AttributePermissionVariant)2 AttributeTarget (com.haulmont.cuba.gui.app.security.entity.AttributeTarget)1 MultiplePermissionTarget (com.haulmont.cuba.gui.app.security.entity.MultiplePermissionTarget)1 Label (com.haulmont.cuba.gui.components.Label)1