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

Using the Condition Builder UI widget

Using the Condition Builder UI widget

The Condition Builder UI widget provides Commerce Manager client 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 that is created using the com.elasticpath.cmclient.conditionbuilder.impl.tag.ConditionBuilderFactoryImpl class. The following code sample shows how it works.

private Composite displayConditionBuilder(final Composite parentComposite) {

     Application application = Application.getInstance();

     // get the tag operator service
     TagOperatorService tagOpService = (TagOperatorService)
               application.getBean(ContextIdNames.TAG_OPERATOR_SERVICE);

     // get tag definitions from the custom dictionary
     TagDictionaryService dictionaryService = (TagDictionaryService)
               application.getBean(ContextIdNames.TAG_DICTIONARY_SERVICE);
     TagDictionary tagDictionary = dictionaryService.findByGuid(CUSTOM_DICTIONARY);
     Set<TagDefinition> tagDefinitions = tagDictionary.getTagDefinitions();

     ConditionBuilderFactoryImpl factory = new ConditionBuilderFactoryImpl();
     factory.setDataBindingContext(this.dataBindingCtx);
     factory.setLocale(CorePlugin.getDefault().getDefaultLocale());
     factory.setTagOperatorService(tagOpService);
     factory.setConditionBuilderTitle(""); //$NON-NLS-1$

     factory.getResourceAdapterFactory().setResourceAdapterForLogicalOperator(
               new ResourceAdapter<LogicalOperatorType>() {
                    public String getLocalizedResource(final LogicalOperatorType object) {
                         return AdminGCMessages.getMessage(object.getMessageKey());
                    } });

     factory.getResourceAdapterFactory().setResourceAdapterForUiElements(
               new ResourceAdapter<String>() {
                    public String getLocalizedResource(final String object) {
                         return AdminGCMessages.getMessage(object);
                    } });

     factory.setListenerForRefreshParentComposite(
               new ActionEventListener<Object>() {
                    public void onEvent(final Object object) {
                         parentComposite.pack();
                         parentComposite.layout();
                    } });

     final Composite composite = factory.createFullUiFromModel(parentComposite, SWT.FLAT, this.logicalOperator);
     return composite;
}

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);
    }
});