Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Creating a State Policy aware editor

Creating a State Policy aware editor

Note: Before You Begin

Make sure that you have Creating a State Policy extension point in the plugin.

For a Commerce Manager editor to be State Policies aware, it must extend AbstractPolicyAwareFormEditor.

The following methods must be implemented:

  • getTargetIdentifier
  • addPages

getTargetIdentifier must return the unique identifier that will be used to map Creating a State Policy Contribution to this object.

public String getTargetIdentifier() {
	return "categoryEditor"; //$NON-NLS-1$
}

addPages is responsible for creating and adding the editor's pages. Before adding pages, you need to add a Policy Action Container. Then use addPage to add pages to the editor. addPage takes the PolicyActionContainer object as its second parameter. This ensures that StateChangeTarget objects are added to the PolicyActionContainer for the UI controls in each page that is added to the editor.

protected void addPages() {
    try {
        final PolicyActionContainer pageContainer = addPolicyActionContainer("categoryEditor"); //$NON-NLS-1$
        addPage(new CategorySummaryPage(this), pageContainer);
        addPage(new CategoryAttributePage(this), pageContainer);
        addPage(new CategorySeoPage(this), pageContainer);
        addPage(new CategoryFeaturedProductsPage(this), pageContainer);
    } catch (final PartInitException e) {
        throw new EpUiException(e);
    }
}
Note: Use IPolicyTargetComposite

Make sure the pages use PolicyTargetCompositeFactory to create an IPolicyTargetComposite and use its add methods to Adding State Policy aware UI controls.

Registering the editor for Change Sets

In order to edit an object from within a Change Sets, its editor must be registered as a Change Set supported component. To do this, edit the plugin's plugin.xml and add a supportedComponents extension point (if one doesn't already exist). Inside the extension point, add an editor element with an editorId attribute set to the name of your editor class and an objectType attribute containing a display name for the editor. The following example shows the registration for com.elasticpath.cmclient.catalog.editors.category.CategoryEditor.

<extension point="com.elasticpath.cmclient.changeset.supportedComponents">
    ...
    <editor
        editorId="com.elasticpath.cmclient.catalog.editors.category.CategoryEditor"
        objectType="Category">
    </editor>
</extension>