Creating a State Policy aware UI plugin class
Creating a State Policy aware UI plugin class
You must add the com.elasticpath.cmclient.policy plugin to the Required Plug-ins list in your plugin's Dependencies.
UI plugins that need State Policies support must extend AbstractPolicyAwareUIPlugin. Two methods in AbstractPolicyAwareUIPlugin must be implemented:
- getStatePolicyExtensionRetriever
- getStatePolicyResolver
getStatePolicyExtensionRetriever must be implemented as follows:
protected StatePolicyExtensionRetriever getStatePolicyExtensionRetriever() { return new StatePolicyExtensionRetriever(PLUGIN_ID); }
The State Policy Extension Retriever is responsible for ensuring that the State Policy Contributions from the Change Set plugin are included when the Change Sets feature is enabled. (If the Change Sets feature is disabled, the state policy contributions from the Change Set plugin are ignored.)
getStatePolicyResolver must be implemented to return a StatePolicyResolver object. The State Policy Resolver is responsible for merging all State Policy Contributions them into a single State Policy that can be applied to the relevant State Policy Targets.
protected StatePolicyResolver getStatePolicyResolver() { return PolicyPlugin.getDefault().getDefaultPolicyResolver(); }
In this example, the default State Policy Resolver is returned. The default is a PriorityStatePolicyResolver object, which uses the priority of the State Policy Contributions to determine which rules take precedence (highest priority wins). If two policies have the same priority, the policies will be combined with a logical AND to determine editability.
A plugin that is State Policy aware can choose to use its own resolver, or request the default one from the Policy plugin. To use a different resolver as the default, modify the extension in the Policy plugin's statePolicyResolver extension point.
The plugin's start method must also call the following:
PolicyPlugin.getDefault().registerStatePolicyFactory(PLUGIN_ID, getStatePolicyFactory());