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