Search in sources :

Example 1 with ExpressionPart

use of org.drools.workbench.models.datamodel.rule.ExpressionPart in project drools by kiegroup.

the class RuleModelDRLPersistenceUnmarshallingTest method testSingleFieldConstraintEBLeftSide.

@Test
public void testSingleFieldConstraintEBLeftSide() throws Exception {
    String drl = "" + "rule \" broken \"\n" + "dialect \"mvel\"\n" + "  when\n" + "    Customer( contact != null , contact.tel1 > \"15\" )\n" + "  then\n" + "end";
    addModelField("Customer", "contact", "Contact", "Contact");
    addModelField("Contact", "tel1", "String", "String");
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    FactPattern pattern = (FactPattern) m.lhs[0];
    SingleFieldConstraint constraint = (SingleFieldConstraint) pattern.getFieldConstraints()[0];
    assertEquals("Customer", constraint.getFactType());
    assertEquals("contact", constraint.getFieldName());
    assertEquals("Contact", constraint.getFieldType());
    SingleFieldConstraintEBLeftSide constraint2 = (SingleFieldConstraintEBLeftSide) pattern.getFieldConstraints()[1];
    assertEquals("tel1", constraint2.getFieldName());
    assertEquals("String", constraint2.getFieldType());
    assertEquals("15", constraint2.getValue());
    assertEquals(">", constraint2.getOperator());
    assertEquals(3, constraint2.getExpressionLeftSide().getParts().size());
    ExpressionPart part1 = constraint2.getExpressionLeftSide().getParts().get(0);
    assertEquals("Customer", part1.getName());
    assertEquals("Customer", part1.getClassType());
    assertEquals("Customer", part1.getGenericType());
    ExpressionPart part2 = constraint2.getExpressionLeftSide().getParts().get(1);
    assertEquals("contact", part2.getName());
    assertEquals("Contact", part2.getClassType());
    assertEquals("Contact", part2.getGenericType());
    ExpressionPart part3 = constraint2.getExpressionLeftSide().getParts().get(2);
    assertEquals("tel1", part3.getName());
    assertEquals("String", part3.getClassType());
    assertEquals("String", part3.getGenericType());
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) ExpressionPart(org.drools.workbench.models.datamodel.rule.ExpressionPart) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 2 with ExpressionPart

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

the class ExpressionBuilder method createWidgetForExpression.

// Render Widgets for the Expression. ExpressionMethodParameter and ExpressionText parts
// are represented by a TextBox to allow the User to edit the values, Updates are
// reflected in the model.
private Widget createWidgetForExpression() {
    final HorizontalPanel container = new HorizontalPanel();
    container.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    container.setStylePrimaryName(GuidedRuleEditorResources.INSTANCE.css().container());
    for (ExpressionPart expressionPart : expression.getParts()) {
        if (expressionPart instanceof ExpressionUnboundFact) {
            continue;
        } else if (this.readOnly) {
            container.add(new Label(expressionPart.getName()));
        } else if (expressionPart instanceof ExpressionMethod) {
            container.add(new Label(expressionPart.getName()));
            container.add(new Label("("));
            final ExpressionMethod em = (ExpressionMethod) expressionPart;
            final List<ExpressionFormLine> emParams = em.getOrderedParams();
            for (int index = 0; index < emParams.size(); index++) {
                final ExpressionFormLine paramValueHolder = emParams.get(index);
                final String paramDataType = em.getParameterDataType(paramValueHolder);
                final ExpressionMethodParameter paramValue = ((ExpressionMethodParameter) paramValueHolder.getRootExpression());
                final TextBox paramValueEditor = TextBoxFactory.getTextBox(paramDataType);
                paramValueEditor.addValueChangeHandler(new ValueChangeHandler<String>() {

                    @Override
                    public void onValueChange(ValueChangeEvent<String> event) {
                        paramValue.setText(event.getValue());
                    }
                });
                paramValueEditor.setText(paramValue.getName());
                container.add(paramValueEditor);
                if (index < emParams.size() - 1) {
                    container.add(new Label(", "));
                }
            }
            container.add(new Label(")"));
        } else if (!(expressionPart instanceof ExpressionText)) {
            container.add(new Label(expressionPart.getName()));
        } else {
            final TextBox tb = new TextBox();
            final ExpressionText expressionTextPart = (ExpressionText) expressionPart;
            tb.setText(expressionTextPart.getName());
            tb.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(final ChangeEvent changeEvent) {
                    expressionTextPart.setText(tb.getText());
                }
            });
            container.add(tb);
        }
        container.add(new Label("."));
    }
    return container;
}
Also used : ExpressionMethodParameter(org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter) ExpressionPart(org.drools.workbench.models.datamodel.rule.ExpressionPart) Label(com.google.gwt.user.client.ui.Label) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) TextBox(org.gwtbootstrap3.client.ui.TextBox) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ExpressionTypeChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeEvent) ExpressionChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionChangeEvent) ExpressionChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionChangeHandler) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ExpressionTypeChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeHandler) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel)

Example 3 with ExpressionPart

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

the class ExpressionBuilder method onStartPointChange.

private void onStartPointChange(final String value) {
    setModified(true);
    panel.clear();
    final int dotPos = value.indexOf('.');
    final String prefix = value.substring(0, dotPos);
    final String attrib = value.substring(dotPos + 1);
    if (prefix.equals(VARIABLE_VALUE_PREFIX)) {
        FactPattern fact = getRuleModel().getLHSBoundFact(attrib);
        ExpressionPart variable;
        if (fact != null) {
            variable = new ExpressionVariable(fact.getBoundName(), fact.getFactType());
        } else {
            // if the variable is not bound to a Fact Pattern then it must be bound to a Field
            String lhsBindingType = getRuleModel().getLHSBindingType(attrib);
            variable = new ExpressionFieldVariable(attrib, lhsBindingType);
        }
        expression.appendPart(variable);
        onStartPointChangeUpdateWidget();
    } else if (prefix.equals(GLOBAL_VARIABLE_VALUE_PREFIX)) {
        ExpressionPartHelper.getExpressionPartForGlobalVariable(getDataModelOracle(), attrib, new Callback<ExpressionPart>() {

            @Override
            public void callback(final ExpressionPart part) {
                expression.appendPart(part);
                onStartPointChangeUpdateWidget();
            }
        });
    }
}
Also used : ExpressionFieldVariable(org.drools.workbench.models.datamodel.rule.ExpressionFieldVariable) Callback(org.uberfire.client.callbacks.Callback) ExpressionPart(org.drools.workbench.models.datamodel.rule.ExpressionPart) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable)

Aggregations

ExpressionPart (org.drools.workbench.models.datamodel.rule.ExpressionPart)3 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)1 Label (com.google.gwt.user.client.ui.Label)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)1 ExpressionFieldVariable (org.drools.workbench.models.datamodel.rule.ExpressionFieldVariable)1 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)1 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)1 ExpressionMethodParameter (org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter)1 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)1 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)1 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)1 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)1 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)1 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)1