Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This site 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 dialog

Creating a State Policy aware dialog

Note: Before You Begin

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

For a Commerce Manager dialog to be State Policies aware, it must extend AbstractPolicyAwareDialog and implement ObjectGuidReceiver.

The dialog must also have a zero-parameter constructor and must be able to perform all persistence operations (retrieve, update, save, etc.) by itself.

The following methods must be implemented:

  • getTargetIdentifier
  • setObjectGuid
  • createDialogContent
  • getOkButtonPolicyActionContainer
  • refreshLayout

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

  1. com.elasticpath.cmclient.catalog/src/main/java/com/elasticpath/cmclient/catalog/dialogs/catalog/VirtualCatalogDialog.java
  2. public String getTargetIdentifier() {
  3. if (this.virtualCatalog.isPersisted()) {
  4. return "virtualCatalogDialogTarget"; //$NON-NLS-1$
  5. }
  6. return "virualCatalogDialogEditableTarget"; //$NON-NLS-1$
  7. }

Copy

setObjectGuid must be implemented to retrieve the dialog's dependent object from its GUID.

  1. com.elasticpath.cmclient.catalog/src/main/java/com/elasticpath/cmclient/catalog/dialogs/catalog/VirtualCatalogDialog.java
  2. public void setObjectGuid(final String objectGuid) {
  3. if (objectGuid == null) {
  4. virtualCatalog = getBeanFactory().getBean(ContextIdNames.CATALOG);
  5. virtualCatalog.setMaster(false);
  6. } else {
  7. virtualCatalog = catalogService.findByCode(objectGuid);
  8. if (virtualCatalog == null) {
  9. throw new IllegalArgumentException(
  10. NLS.bind(CoreMessages.Given_Object_Not_Exist, new String[] {"Virtual Catalog", objectGuid})); //$NON-NLS-1$
  11. }
  12. }
  13. }

Copy

createDialogContent is responsible for creating and laying out the dialog's UI controls. The first step is usually to add a Policy Action Container. Then use the IPolicyTargetLayoutComposite's add methods to add UI controls. These methods take the PolicyActionContainer object as their final argument. This ensures that a StateChangeTarget is added to the PolicyActionContainer for each UI control that is added to the dialog.

  1. com.elasticpath.cmclient.catalog/src/main/java/com/elasticpath/cmclient/catalog/dialogs/catalog/VirtualCatalogDialog.java
  2. protected void createDialogContent(final IPolicyTargetLayoutComposite dialogComposite) {
  3. // This name does not need to match anything necessarily
  4. readOnlyVirtualCatalogPolicyContainer = addPolicyActionContainer("readOnlyVirtualCatalogDialog"); //$NON-NLS-1$
  5. editableVirtualCatalogPolicyContainer = addPolicyActionContainer("virtualCatalogDialog"); //$NON-NLS-1$
  6. mainPolicyComposite = dialogComposite
  7. .addGridLayoutComposite(2, false, dialogComposite
  8. .createLayoutData(IEpLayoutData.FILL, IEpLayoutData.BEGINNING, true, false),
  9. editableVirtualCatalogPolicyContainer);
  10.  
  11. final IEpLayoutData mainCompositeFieldData = mainPolicyComposite
  12. .createLayoutData(IEpLayoutData.FILL, IEpLayoutData.BEGINNING, true, true);
  13. final IEpLayoutData mainCompositeLabelData = mainPolicyComposite

Copy

...
Read more

getOkButtonPolicyActionContainer returns the Policy Action Container that will control the state of the dialog's OK or Save button.

  1. com.elasticpath.cmclient.catalog/src/main/java/com/elasticpath/cmclient/catalog/dialogs/catalog/VirtualCatalogDialog.java
  2. protected PolicyActionContainer getOkButtonPolicyActionContainer() {
  3. return this.editableVirtualCatalogPolicyContainer;
  4. }

Copy

refreshLayout can be implemented to refresh the layout of parent composites if required.

  1. com.elasticpath.cmclient.catalog/src/main/java/com/elasticpath/cmclient/catalog/dialogs/catalog/VirtualCatalogDialog.java
  2. protected void refreshLayout() {
  3. if (mainPolicyComposite != null) {
  4. mainPolicyComposite.getSwtComposite().layout();
  5. mainPolicyComposite.getSwtComposite().getParent().layout();
  6. }
  7. }

Copy

Registering the dialog for Change Sets

In order to edit an object from within a Change Sets editor, its dialog 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 a dialog element with a class attribute set to the name of your dialog class and an objectType attribute containing a display name for the dialog. The following example shows the registration for com.elasticpath.cmclient.catalog.dialogs.catalog.VirtualCatalogDialog.

  1. <extension point="com.elasticpath.cmclient.changeset.supportedComponents">
  2. ...
  3. <dialog
  4. class="com.elasticpath.cmclient.catalog.dialogs.catalog.VirtualCatalogDialog"
  5. objectType="Catalog">
  6. </dialog>
  7. </extension>

Copy