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.

Using the Condition Builder UI widget

Using the Condition Builder UI widget

The Condition Builder UI widget provides Commerce Manager users with an easy way to build conditional expressions to evaluate tags.

Note:

You can also create conditional expressions programmatically using the ConditionBuilder service.

The "widget" is an RCP Composite created using the com.elasticpath.cmclient.conditionbuilder.impl.tag.ConditionBuilderFactoryImpl class. The following code sample shows how it works.

private Composite initializeModel() {

     this.tagOperatorService = ServiceLocator.getService(ContextIdNames.TAG_OPERATOR_SERVICE);
     TagDictionaryService tagDictionaryService = ServiceLocator.getService(ContextIdNames.TAG_DICTIONARY_SERVICE);
     TagGroupService tagGroupService = ServiceLocator.getService(ContextIdNames.TAG_GROUP_SERVICE);
     TagDictionary tagDictionary = tagDictionaryService.findByGuid(dictionary);

     if (tagDefinitionsList == null) {
          tagDefinitionsList = tagDictionary.getTagDefinitions();
     }

     Set<TagGroup> tagSet = new LinkedHashSet<>();
     for (TagDefinition tagDefinition : tagDefinitionsList) {
          if (tagDefinition.getGroup() == null) {
               continue;
          }
        TagGroup tagGroup = tagGroupService.findByGuid(tagDefinition.getGroup().getGuid());
        tagGroup.getTagDefinitions().retainAll(tagDefinitionsList);
        tagSet.add(tagGroup);
     }

     tagGroupsList = tagSet;
}
Then call com.elasticpath.cmclient.conditionbuilder.impl.tag.ConditionBuilderFactoryImpl from e,g com.elasticpath.cmclient.store.targetedselling.conditionalexpression.editors.ShopperConditionBuilderSection
public ShopperConditionBuilderSection(final FormPage formPage, final AbstractCmClientFormEditor editor) {
super(formPage, editor);

   conditionBuilderFactory = new ConditionBuilderFactoryImpl();
   conditionBuilderFactory.setLocale(CorePlugin.getDefault().getDefaultLocale());
   conditionBuilderFactory.setDataBindingContext(getEditor().getDataBindingContext());
   conditionBuilderFactory.setAddButtonText("ConditionBuilder_AddConditionButton");       //$NON-NLS-1$
   conditionBuilderFactory.setConditionBuilderTitle("ConditionBuilder_Title"); //$NON-NLS-1$
   conditionBuilderFactory.setTagDictionary(SHOPPER_DICTIONARY);
   
   conditionBuilderFactory.getResourceAdapterFactory().setResourceAdapterForLogicalOperator(
         object -> {
            return TargetedSellingMessages.get().getMessage(object.getMessageKey());
         });
   
   conditionBuilderFactory.setListenerForRefreshParentComposite(
         object -> {
            getSection().getParent().setRedraw(false);
            getSection().pack();
            getSection().getParent().layout(true);
            getSection().getParent().setRedraw(true);

            getManagedForm().reflow(false);
         });
   conditionBuilderFactory.setListenerForMarkEditorState(
         object -> {
if (!initConditionBuilder) {
               getEditor().pageModified();
               ShopperConditionBuilderSection.this.markDirty();
            }
         });

Making the Condition Builder State Policy Aware

The plugin's State Policy is not automatically applied to the constituent controls of the Condition Builder composite. You must add a StateChangeTarget to the state policy container and override StateChangeTarget's setState to call EpControlFactory.changeEpStateForComposite. The first parameter to the changeEpStateForComposite is the Condition Builder composite. The second parameter is the new state.

The following example shows how to apply the state policy to those controls.

// apply the state policy to the condition builder widget
policyContainer.addTarget(new StateChangeTarget() {
    public void setState(final EpState state) {
        EpControlFactory.changeEpStateForComposite(composite, state);
    }
});