Search in sources :

Example 26 with ConnectiveConstraint

use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools-wb by kiegroup.

the class ConstraintValueEditor method showTypeChoice.

/**
 * Show a list of possibilities for the value type.
 */
private void showTypeChoice(final BaseSingleFieldConstraint con) {
    CustomFormConfiguration customFormConfiguration = getWorkingSetManager().getCustomFormConfiguration(modeller.getPath(), factType, fieldName);
    if (customFormConfiguration != null) {
        if (!(con instanceof SingleFieldConstraint)) {
            Window.alert("Unexpected constraint type!");
            return;
        }
        final CustomFormPopUp customFormPopUp = new CustomFormPopUp(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.FieldValue(), customFormConfiguration);
        final SingleFieldConstraint sfc = (SingleFieldConstraint) con;
        customFormPopUp.addOkButtonHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                sfc.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
                sfc.setId(customFormPopUp.getFormId());
                sfc.setValue(customFormPopUp.getFormValue());
                doTypeChosen(customFormPopUp);
            }
        });
        customFormPopUp.show(sfc.getId(), sfc.getValue());
        return;
    }
    final FormStylePopup form = new FormStylePopup(GuidedRuleEditorImages508.INSTANCE.Wizard(), GuidedRuleEditorResources.CONSTANTS.FieldValue());
    Button lit = new Button(GuidedRuleEditorResources.CONSTANTS.LiteralValue());
    int litValueType = isDropDownDataEnum && dropDownData != null ? SingleFieldConstraint.TYPE_ENUM : SingleFieldConstraint.TYPE_LITERAL;
    lit.addClickHandler(getValueTypeFormOnClickHandler(con, form, litValueType));
    boolean showLiteralSelector = true;
    boolean showFormulaSelector = !OperatorsOracle.operatorRequiresList(con.getOperator());
    boolean showVariableSelector = !OperatorsOracle.operatorRequiresList(con.getOperator());
    boolean showExpressionSelector = !OperatorsOracle.operatorRequiresList(con.getOperator());
    if (con instanceof SingleFieldConstraint) {
        SingleFieldConstraint sfc = (SingleFieldConstraint) con;
        String fieldName = sfc.getFieldName();
        if (fieldName.equals(DataType.TYPE_THIS)) {
            showLiteralSelector = CEPOracle.isCEPOperator(sfc.getOperator());
            showFormulaSelector = showFormulaSelector && showLiteralSelector;
        }
    } else if (con instanceof ConnectiveConstraint) {
        ConnectiveConstraint cc = (ConnectiveConstraint) con;
        String fieldName = cc.getFieldName();
        if (fieldName.equals(DataType.TYPE_THIS)) {
            showLiteralSelector = CEPOracle.isCEPOperator(cc.getOperator());
            showFormulaSelector = showFormulaSelector && showLiteralSelector;
        }
    }
    // Literal value selector
    if (showLiteralSelector) {
        form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.LiteralValue(), GuidedRuleEditorResources.CONSTANTS.LiteralValue(), GuidedRuleEditorResources.CONSTANTS.LiteralValTip(), lit);
    }
    // Template key selector
    if (modeller.isTemplate()) {
        String templateKeyLabel = GuidedRuleEditorResources.CONSTANTS.TemplateKey();
        Button templateKeyButton = new Button(templateKeyLabel);
        templateKeyButton.addClickHandler(getValueTypeFormOnClickHandler(con, form, SingleFieldConstraint.TYPE_TEMPLATE));
        form.addAttributeWithHelp(templateKeyLabel, templateKeyLabel, GuidedRuleEditorResources.CONSTANTS.TemplateKeyTip(), templateKeyButton);
    }
    // Divider, if we have any advanced options
    if (showVariableSelector || showFormulaSelector || showExpressionSelector) {
        form.addRow(new HTML("<hr/>"));
        form.addRow(new SmallLabel(GuidedRuleEditorResources.CONSTANTS.AdvancedOptions()));
    }
    // Show variables selector, if there are any variables in scope
    if (showVariableSelector) {
        List<String> bindingsInScope = this.model.getBoundVariablesInScope(this.constraint);
        if (bindingsInScope.size() > 0 || DataType.TYPE_COLLECTION.equals(this.fieldType)) {
            final Button bindingButton = new Button(GuidedRuleEditorResources.CONSTANTS.BoundVariable());
            // This Set is used as a 1flag to know whether the button has been added; due to use of callbacks
            final Set<Button> bindingButtonContainer = new HashSet<Button>();
            for (String var : bindingsInScope) {
                helper.isApplicableBindingsInScope(var, new Callback<Boolean>() {

                    @Override
                    public void callback(final Boolean result) {
                        if (Boolean.TRUE.equals(result)) {
                            if (!bindingButtonContainer.contains(bindingButton)) {
                                bindingButtonContainer.add(bindingButton);
                                bindingButton.addClickHandler(getValueTypeFormOnClickHandler(con, form, SingleFieldConstraint.TYPE_VARIABLE));
                                form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.AVariable(), GuidedRuleEditorResources.CONSTANTS.ABoundVariable(), GuidedRuleEditorResources.CONSTANTS.BoundVariableTip(), bindingButton);
                            }
                        }
                    }
                });
            }
        }
    }
    // Formula selector
    if (showFormulaSelector) {
        Button formula = new Button(GuidedRuleEditorResources.CONSTANTS.NewFormula());
        formula.addClickHandler(getValueTypeFormOnClickHandler(con, form, SingleFieldConstraint.TYPE_RET_VALUE));
        form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.AFormula(), GuidedRuleEditorResources.CONSTANTS.AFormula(), GuidedRuleEditorResources.CONSTANTS.FormulaExpressionTip(), formula);
    }
    // Expression selector
    if (showExpressionSelector) {
        Button expression = new Button(GuidedRuleEditorResources.CONSTANTS.ExpressionEditor());
        expression.addClickHandler(getValueTypeFormOnClickHandler(con, form, SingleFieldConstraint.TYPE_EXPR_BUILDER_VALUE));
        form.addAttributeWithHelp(GuidedRuleEditorResources.CONSTANTS.ExpressionEditor(), GuidedRuleEditorResources.CONSTANTS.ExpressionEditor(), GuidedRuleEditorResources.CONSTANTS.ExpressionEditorTip(), expression);
    }
    form.show();
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CustomFormConfiguration(org.guvnor.common.services.workingset.client.factconstraints.customform.CustomFormConfiguration) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) HTML(com.google.gwt.user.client.ui.HTML) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Button(org.gwtbootstrap3.client.ui.Button) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) HashSet(java.util.HashSet)

Example 27 with ConnectiveConstraint

use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools-wb by kiegroup.

the class Connectives method connectives.

public Widget connectives(final SingleFieldConstraint c) {
    final HorizontalPanel hp = new HorizontalPanel();
    if (c.getConnectives() != null && c.getConnectives().length > 0) {
        hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
        hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        for (int i = 0; i < c.getConnectives().length; i++) {
            final int index = i;
            final ConnectiveConstraint con = c.getConnectives()[i];
            connectiveOperatorDropDown(con, new Callback<Widget>() {

                @Override
                public void callback(final Widget w) {
                    hp.add(w);
                    hp.add(connectiveValueEditor(con));
                    if (!isReadOnly) {
                        Image clear = GuidedRuleEditorImages508.INSTANCE.DeleteItemSmall();
                        clear.setAltText(GuidedRuleEditorResources.CONSTANTS.RemoveThisRestriction());
                        clear.setTitle(GuidedRuleEditorResources.CONSTANTS.RemoveThisRestriction());
                        clear.addClickHandler(createClickHandlerForClearImageButton(c, index));
                        hp.add(clear);
                    }
                }
            });
        }
    }
    return hp;
}
Also used : HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel) Widget(com.google.gwt.user.client.ui.Widget) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) Image(com.google.gwt.user.client.ui.Image) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 28 with ConnectiveConstraint

use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools-wb by kiegroup.

the class OperatorsBaseTest method setUp.

@Before
public void setUp() throws Exception {
    ApplicationPreferences.setUp(new HashMap() {

        {
            put(ApplicationPreferences.DATE_FORMAT, "dd/MM/YYYY");
        }
    });
    serviceCaller = new CallerMock<>(service);
    oracle = new AsyncPackageDataModelOracleImpl(serviceCaller, null);
    final ModelField[] modelFields = new ModelField[] { modelField("street", DataType.TYPE_STRING), modelField("number", DataType.TYPE_NUMERIC_INTEGER) };
    Map<String, ModelField[]> fields = new HashMap<>();
    fields.put("org.Address", modelFields);
    oracle.addModelFields(fields);
    connectives = spy(new Connectives(modeller, eventBus, pattern, false));
    doReturn(oracle).when(connectives).getDataModelOracle();
    doReturn(oracle).when(modeller).getDataModelOracle();
    doReturn(Stream.of(connectiveConstraint).toArray(ConnectiveConstraint[]::new)).when(singleFieldConstraint).getConnectives();
}
Also used : Connectives(org.drools.workbench.screens.guided.rule.client.editor.factPattern.Connectives) AsyncPackageDataModelOracleImpl(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleImpl) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) Before(org.junit.Before)

Aggregations

ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)28 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)25 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)21 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)15 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)15 Test (org.junit.Test)15 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)14 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)13 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)9 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)9 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)7 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)7 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)7 HashMap (java.util.HashMap)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)4 InterpolationVariable (org.drools.workbench.models.datamodel.rule.InterpolationVariable)4 Map (java.util.Map)3 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)3 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)3 HashSet (java.util.HashSet)2