/** * Apply attribute access rules to a given frame according to the state of the given entities. All passed entities * will be sent to the middleware and their security state will be recalculated. All screen components * bound to datasources will adjust their visible/read-only/required state according to security state of entity * instances contained in the datasources. * * @param entities list of instances that should recalculate their security state * @param frameOwner frame or screen * @param reset whether to reset the components to the default state specified by role-based security and model * annotations. If you invoke this method to apply attribute access to already opened screen, set * the parameter to true, but keep in mind that previous programmatic changes in the components * visible/read-only/required state will be lost. */ public void applyAttributeAccess(FrameOwner frameOwner, boolean reset, Entity... entities) { for (Entity entity : entities) { attributeAccessUpdater.updateAttributeAccess(entity); } applyAttributeAccess(frameOwner, reset); }
protected ComponentState calculateComponentState(Entity entity, MetaPropertyPath propertyPath) { MetaProperty[] metaProperties = propertyPath.getMetaProperties(); ComponentState componentState = new ComponentState(); for (int i = 0; i < metaProperties.length; i++) { MetaProperty metaProperty = metaProperties[i]; String name = metaProperty.getName(); SecurityState securityState = getSecurityState(entity); if (securityState != null) { componentState.hidden = test(componentState.hidden, securityState.getHiddenAttributes(), name); componentState.readOnly = test(componentState.readOnly, securityState.getReadonlyAttributes(), name); if (i == metaProperties.length - 1) { componentState.required = test(componentState.required, securityState.getRequiredAttributes(), name); } } if (i != metaProperties.length - 1) { entity = entity.getValue(name); if (entity == null) { break; } } } return componentState; }
/** * Apply attribute access rules to a given frame. It means that all components bound to datasources will adjust * their visible/read-only/required state according to security state of entity instances contained in the datasources. * * @param frameOwner frame or screen * @param reset whether to reset the components to the default state specified by role-based security and model * annotations. If you invoke this method to apply attribute access to already opened screen, set * the parameter to true, but keep in mind that previous programmatic changes in the components * visible/read-only/required state will be lost. */ public void applyAttributeAccess(FrameOwner frameOwner, boolean reset) { ComponentContainer componentContainer; if (frameOwner instanceof Screen) { componentContainer = ((Screen) frameOwner).getWindow(); } else { componentContainer = (Window) frameOwner; } ComponentsHelper.walkComponents(componentContainer, (component, name) -> visitComponent(component, reset)); }
ComponentState componentState = calculateComponentState(entityValueSource.getItem(), propertyPath); if (componentState.hidden) { component.setVisible(false);
protected void afterShowWindow(Screen screen) { WindowContext windowContext = screen.getWindow().getContext(); if (!WindowParams.DISABLE_APPLY_SETTINGS.getBool(windowContext)) { applySettings(screen, getSettingsImpl(screen.getId())); } if (screen instanceof LegacyFrame) { if (!WindowParams.DISABLE_RESUME_SUSPENDED.getBool(windowContext)) { DsContext dsContext = ((LegacyFrame) screen).getDsContext(); if (dsContext != null) { ((DsContextImplementation) dsContext).resumeSuspended(); } } } if (screen instanceof AbstractWindow) { AbstractWindow abstractWindow = (AbstractWindow) screen; if (abstractWindow.isAttributeAccessControlEnabled()) { attributeAccessSupport.applyAttributeAccess(abstractWindow, false); } } else { DisableAttributeAccessControl annotation = screen.getClass().getAnnotation(DisableAttributeAccessControl.class); if (annotation == null || !annotation.value()) { attributeAccessSupport.applyAttributeAccess(screen, false); } } }