Search in sources :

Example 1 with BasicPermissionTreeStyleProvider

use of com.haulmont.cuba.gui.app.security.role.edit.BasicPermissionTreeStyleProvider in project cuba by cuba-platform.

the class ScreenPermissionsFrame method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    screenPermissionsTree.setStyleProvider(new BasicPermissionTreeStyleProvider());
    screenPermissionsTree.addAction(new AbstractAction("actions.Allow") {

        @Override
        public void actionPerform(Component component) {
            markItemPermission(PermissionVariant.ALLOWED);
        }
    });
    screenPermissionsTree.addAction(new AbstractAction("actions.Disallow") {

        @Override
        public void actionPerform(Component component) {
            markItemPermission(PermissionVariant.DISALLOWED);
        }
    });
    screenPermissionsTree.addAction(new AbstractAction("actions.DropRule") {

        @Override
        public void actionPerform(Component component) {
            markItemPermission(PermissionVariant.NOTSET);
        }
    });
    companion.initPermissionColoredColumns(screenPermissionsTree);
    screenPermissionsTreeDs.addItemChangeListener(e -> {
        if (!selectedScreenPanel.isVisible() && (e.getItem() != null)) {
            selectedScreenPanel.setVisible(true);
        }
        if (selectedScreenPanel.isVisible() && (e.getItem() == null)) {
            selectedScreenPanel.setVisible(false);
        }
        updateCheckBoxes(e.getItem());
    });
    screenPermissionsTreeDs.addItemPropertyChangeListener(e -> {
        if ("permissionVariant".equals(e.getProperty())) {
            updateCheckBoxes(e.getItem());
        }
    });
    screenPermissionsTreeDs.setFilter(new ScreenNameFilter<>(screenFilter));
    screenFilter.addEnterPressListener(e -> applyFilter());
    allowCheckBox.addValueChangeListener(e -> {
        if (!itemChanging) {
            itemChanging = true;
            markItemPermission(PermissionUiHelper.getCheckBoxVariant(e.getValue(), PermissionVariant.ALLOWED));
            itemChanging = false;
        }
    });
    disallowCheckBox.addValueChangeListener(e -> {
        if (!itemChanging) {
            itemChanging = true;
            markItemPermission(PermissionUiHelper.getCheckBoxVariant(e.getValue(), PermissionVariant.DISALLOWED));
            itemChanging = false;
        }
    });
    boolean isCreatePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.CREATE);
    boolean isDeletePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.DELETE);
    boolean hasPermissionsToModifyPermission = isCreatePermitted && isDeletePermitted;
    allowCheckBox.setEditable(hasPermissionsToModifyPermission);
    disallowCheckBox.setEditable(hasPermissionsToModifyPermission);
    screensEditPane.setEnabled(security.isEntityOpPermitted(metadata.getClass(Role.class), EntityOp.UPDATE));
}
Also used : BasicPermissionTreeStyleProvider(com.haulmont.cuba.gui.app.security.role.edit.BasicPermissionTreeStyleProvider)

Example 2 with BasicPermissionTreeStyleProvider

use of com.haulmont.cuba.gui.app.security.role.edit.BasicPermissionTreeStyleProvider in project cuba by cuba-platform.

the class SpecificPermissionsFrame method init.

@Override
public void init(Map<String, Object> params) {
    super.init(params);
    specificPermissionsTree.setStyleProvider(new BasicPermissionTreeStyleProvider());
    companion.initPermissionColoredColumns(specificPermissionsTree);
    specificPermissionsTreeDs.addItemChangeListener(e -> {
        boolean visible = false;
        if (e.getItem() != null) {
            for (BasicPermissionTarget target : specificPermissionsTree.getSelected()) {
                visible |= !target.getId().startsWith(CATEGORY_PREFIX);
            }
        }
        selectedPermissionPanel.setVisible(visible);
        updateCheckBoxes(e.getItem());
    });
    specificPermissionsTreeDs.addItemPropertyChangeListener(e -> {
        if ("permissionVariant".equals(e.getProperty())) {
            updateCheckBoxes(e.getItem());
        }
    });
    allowCheckBox.addValueChangeListener(e -> {
        if (!itemChanging) {
            itemChanging = true;
            markItemPermission(PermissionUiHelper.getCheckBoxVariant(e.getValue(), PermissionVariant.ALLOWED));
            itemChanging = false;
        }
    });
    disallowCheckBox.addValueChangeListener(e -> {
        if (!itemChanging) {
            itemChanging = true;
            markItemPermission(PermissionUiHelper.getCheckBoxVariant(e.getValue(), PermissionVariant.DISALLOWED));
            itemChanging = false;
        }
    });
    specificPermissionsDs.refresh();
    specificPermissionsTreeDs.setPermissionDs(specificPermissionsDs);
    specificPermissionsTreeDs.refresh();
    specificPermissionsTree.expandAll();
    boolean isCreatePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.CREATE);
    boolean isDeletePermitted = security.isEntityOpPermitted(Permission.class, EntityOp.DELETE);
    boolean hasPermissionsToModifyPermission = isCreatePermitted && isDeletePermitted;
    applyPermissions(hasPermissionsToModifyPermission);
    specificEditPane.setEnabled(security.isEntityOpPermitted(metadata.getClass(Role.class), EntityOp.UPDATE));
}
Also used : BasicPermissionTreeStyleProvider(com.haulmont.cuba.gui.app.security.role.edit.BasicPermissionTreeStyleProvider) BasicPermissionTarget(com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)

Aggregations

BasicPermissionTreeStyleProvider (com.haulmont.cuba.gui.app.security.role.edit.BasicPermissionTreeStyleProvider)2 BasicPermissionTarget (com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget)1