Class DefaultUiComponentPolicyApplier
- All Implemented Interfaces:
UiComponentPolicyApplier
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AccessManagerprotected static final StringKey of the component data that marks a tab content the policies have already been applied to.protected UiConstraintsProperties -
Constructor Summary
ConstructorsConstructorDescriptionDefaultUiComponentPolicyApplier(CurrentUserUiComponentPolicies currentUserUiComponentPolicies) -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyUiComponentPolicies(com.vaadin.flow.component.Component component) Applies UI component policies assigned to the current user to the given component and its children.voidapplyUiComponentPolicies(View<?> view) Applies UI component policies assigned to the current user to the given view.voidapplyUiComponentPolicies(View<?> view, com.vaadin.flow.component.Component component) Applies UI component policies assigned to the current user to the given component and its children within the given view.protected voidapplyUiComponentPoliciesToSubtree(View<?> view, com.vaadin.flow.component.Component subtree) Applies the policies of the given view to the components of the given subtree only.protected Set<com.vaadin.flow.component.Component> collectSubtreeComponents(com.vaadin.flow.component.Component subtree) protected @Nullable JmixTabSheetfindEnclosingTabSheet(com.vaadin.flow.component.tabs.Tab tab) protected booleanisActionHolderWithin(View<?> view, String componentId, Set<com.vaadin.flow.component.Component> subtreeComponents) An action is considered a part of the subtree when the component holding it is.protected booleanisPoliciesApplied(com.vaadin.flow.component.Component content) protected voidmarkExistingTabContentsApplied(JmixTabSheet tabSheet) The contents that already exist are covered by the pass this registration belongs to, so selecting their tabs later must not apply the policies over them a second time.protected voidmarkPoliciesApplied(com.vaadin.flow.component.Component content) protected voidonTabSelected(View<?> view, JmixTabSheet.SelectedChangeEvent event) protected voidregisterTabSelectionListeners(View<?> view, com.vaadin.flow.component.Component root) The content of a lazy tab is created by the tabSheet loader when the tab is selected for the first time, so the policies cannot be applied to it at view opening.protected voidreselectTabSheetIfSelectedTabHidden(com.vaadin.flow.component.Component component) When aTabis hidden by a policy, and it is the currently selected tab of itsJmixTabSheet, the tabSheet would keep the hidden tab selected and stay in a loading state on the client (the next tab is never activated).protected voidselectNextVisibleTab(JmixTabSheet tabSheet, com.vaadin.flow.component.tabs.Tab hiddenTab) Selects the next visible tab relative to the hidden tab: the closest visible tab after it, or, if there is none, the closest visible tab before it.
-
Field Details
-
POLICIES_APPLIED_KEY
Key of the component data that marks a tab content the policies have already been applied to.- See Also:
-
accessManager
-
uiConstraintsProperties
-
-
Constructor Details
-
DefaultUiComponentPolicyApplier
public DefaultUiComponentPolicyApplier(CurrentUserUiComponentPolicies currentUserUiComponentPolicies)
-
-
Method Details
-
applyUiComponentPolicies
Description copied from interface:UiComponentPolicyApplierApplies UI component policies assigned to the current user to the given view.- Specified by:
applyUiComponentPoliciesin interfaceUiComponentPolicyApplier- Parameters:
view- view the view to which the security policies should be applied
-
applyUiComponentPolicies
public void applyUiComponentPolicies(com.vaadin.flow.component.Component component) Description copied from interface:UiComponentPolicyApplierApplies UI component policies assigned to the current user to the given component and its children. Intended for content created after the view has been opened, for example the content of a lazy tab or components added programmatically.The component must be reachable from its view through the component tree: the policies address components by a path relative to the view, so an owner has to be found for it. Nothing is applied otherwise.
The content of a tab is the notable exception, because a
JmixTabSheetkeeps only the content of the selected tab in the tree, and attaches even that before the client response rather than when it is added. UseUiComponentPolicyApplier.applyUiComponentPolicies(View, Component)for content installed into a tab.- Specified by:
applyUiComponentPoliciesin interfaceUiComponentPolicyApplier- Parameters:
component- the component to apply the policies to
-
applyUiComponentPolicies
Description copied from interface:UiComponentPolicyApplierApplies UI component policies assigned to the current user to the given component and its children within the given view.Unlike
UiComponentPolicyApplier.applyUiComponentPolicies(Component), the component does not have to be reachable from the view through the component tree. That matters for the content of a tab: aJmixTabSheetkeeps only the content of the selected tab in the tree, so content installed into a tab that is not open can only be handed over this way. The default implementation applies the policies to the whole view, which is correct but wider than asked: an implementation that supports subtrees is expected to override it.- Specified by:
applyUiComponentPoliciesin interfaceUiComponentPolicyApplier- Parameters:
view- the view the component belongs tocomponent- the component to apply the policies to
-
applyUiComponentPoliciesToSubtree
protected void applyUiComponentPoliciesToSubtree(View<?> view, com.vaadin.flow.component.Component subtree) Applies the policies of the given view to the components of the given subtree only. A policy whose component is not a part of the subtree is skipped: the subtree is only a part of the view, so most policies of the view do not belong to it. -
isActionHolderWithin
protected boolean isActionHolderWithin(View<?> view, String componentId, Set<com.vaadin.flow.component.Component> subtreeComponents) An action is considered a part of the subtree when the component holding it is. For an action of the view itself the holder is the view. -
registerTabSelectionListeners
protected void registerTabSelectionListeners(View<?> view, com.vaadin.flow.component.Component root) The content of a lazy tab is created by the tabSheet loader when the tab is selected for the first time, so the policies cannot be applied to it at view opening. The listener registered here applies them as soon as the content exists. The loader registers its own listener while the view is being loaded, hence this one is notified after the content has been created. -
markExistingTabContentsApplied
The contents that already exist are covered by the pass this registration belongs to, so selecting their tabs later must not apply the policies over them a second time. A lazy tab holds a placeholder until it is selected, and its real content is a different component, so marking the placeholder costs nothing. -
onTabSelected
-
isPoliciesApplied
protected boolean isPoliciesApplied(com.vaadin.flow.component.Component content) -
markPoliciesApplied
protected void markPoliciesApplied(com.vaadin.flow.component.Component content) -
collectSubtreeComponents
protected Set<com.vaadin.flow.component.Component> collectSubtreeComponents(com.vaadin.flow.component.Component subtree) -
reselectTabSheetIfSelectedTabHidden
protected void reselectTabSheetIfSelectedTabHidden(com.vaadin.flow.component.Component component) When aTabis hidden by a policy, and it is the currently selected tab of itsJmixTabSheet, the tabSheet would keep the hidden tab selected and stay in a loading state on the client (the next tab is never activated). This selects the next accessible tab instead.The currently selected tab is only reselected when it is actually hidden: a visible selected tab (which may have been selected by the user or programmatically in advance) is left untouched, even if some other tab of the same tabSheet is hidden by the policy.
- Parameters:
component- the component theVISIBLE/DENYpolicy has just been applied to
-
findEnclosingTabSheet
Returns theJmixTabSheetthe given tab belongs to, ornullif the tab is not inside aJmixTabSheet. The runtime component hierarchy isTab -> Tabs -> JmixTabSheet. -
selectNextVisibleTab
protected void selectNextVisibleTab(JmixTabSheet tabSheet, com.vaadin.flow.component.tabs.Tab hiddenTab) Selects the next visible tab relative to the hidden tab: the closest visible tab after it, or, if there is none, the closest visible tab before it. If there are no visible tabs at all, clears the selection so that the tabSheet does not stay on a hidden tab.- Parameters:
tabSheet- the tabSheet whose selection must be updatedhiddenTab- the currently selected but hidden tab that must be replaced
-