Search in sources :

Example 6 with ExpressionText

use of org.drools.workbench.models.datamodel.rule.ExpressionText 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 7 with ExpressionText

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

the class RuleModelDRLPersistenceTest method testLHSExpressionString1.

@Test
public void testLHSExpressionString1() {
    RuleModel m = new RuleModel();
    m.name = "test expressionsString1";
    FactPattern p = new FactPattern("Person");
    SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
    con.getExpressionLeftSide().appendPart(new ExpressionText("field1"));
    con.setOperator("==");
    con.setValue("goo");
    con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    p.addConstraint(con);
    m.addLhsItem(p);
    String expected = "rule \"test expressionsString1\"" + "\tdialect \"mvel\"\n when " + "     Person( field1 == \"goo\" )" + " then " + "end";
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) 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) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 8 with ExpressionText

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

the class CopyExpressionVisitor method visit.

public void visit(ExpressionText part) {
    add(new ExpressionText(part.getName(), part.getClassType(), part.getGenericType()));
    moveNext(part);
}
Also used : ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText)

Example 9 with ExpressionText

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

the class CopyExpressionVisitorTest method testExpressionFormLineCopy.

@Test
public void testExpressionFormLineCopy() {
    ExpressionFormLine efl = new ExpressionFormLine();
    efl.appendPart(new ExpressionCollection("collection", "CT", "GT", "PT"));
    efl.appendPart(new ExpressionCollectionIndex("collectionIndex", "CT", "GT"));
    efl.appendPart(new ExpressionField("field", "CT", "FT", "PT"));
    efl.appendPart(new ExpressionFieldVariable("fieldVariable", "Type"));
    efl.appendPart(new ExpressionGlobalVariable("globalVariable", "CT", "GT", "PT"));
    efl.appendPart(new ExpressionMethod("method", "CT", "GT"));
    efl.appendPart(new ExpressionMethodParameter("methodParam", "CT", "GT"));
    efl.appendPart(new ExpressionText("text"));
    efl.appendPart(new ExpressionUnboundFact("FactType"));
    efl.appendPart(new ExpressionVariable("binding", "FactType"));
    // verify that the new instance created with copy constructor is equal to original
    assertEquals(efl, new ExpressionFormLine(efl));
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) ExpressionFieldVariable(org.drools.workbench.models.datamodel.rule.ExpressionFieldVariable) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) ExpressionCollectionIndex(org.drools.workbench.models.datamodel.rule.ExpressionCollectionIndex) ExpressionMethodParameter(org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter) ExpressionCollection(org.drools.workbench.models.datamodel.rule.ExpressionCollection) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) ExpressionGlobalVariable(org.drools.workbench.models.datamodel.rule.ExpressionGlobalVariable) Test(org.junit.Test)

Example 10 with ExpressionText

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

the class RuleModelCloneVisitorTest method buildExpressionFormLine.

private static ExpressionFormLine buildExpressionFormLine() {
    ExpressionFormLine efl = new ExpressionFormLine();
    efl.setBinding("eflBinding");
    efl.appendPart(new ExpressionText("text"));
    efl.appendPart(new ExpressionCollectionIndex("collectionIndex", "CT", "GT"));
    return efl;
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) ExpressionCollectionIndex(org.drools.workbench.models.datamodel.rule.ExpressionCollectionIndex) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText)

Aggregations

ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)10 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)7 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)6 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)6 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)6 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)6 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)6 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)6 Test (org.junit.Test)6 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)5 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)4 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)3 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3 ExpressionCollectionIndex (org.drools.workbench.models.datamodel.rule.ExpressionCollectionIndex)2 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)2 ExpressionMethodParameter (org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter)2 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)2 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1