use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testCompositeFactPatternWithFrom.
@Test
public void testCompositeFactPatternWithFrom() {
final RuleModel m = new RuleModel();
m.name = "model";
final FactPattern fp1 = new FactPattern("Data");
fp1.setBoundName("$d");
m.addLhsItem(fp1);
final FactPattern fp2 = new FactPattern("Person");
final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern();
ffp1.setExpression(new ExpressionFormLine(new ExpressionVariable(fp1.getBoundName(), fp1.getFactType())));
ffp1.setFactPattern(fp2);
m.addLhsItem(ffp1);
final String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
final String expected = "rule \"model\"\n" + "dialect \"mvel\"\n" + "when\n" + "$d : Data( )\n" + "(Person( ) from $d)\n" + "\n" + "then\n" + "end\n";
assertEqualsIgnoreWhitespace(expected, actual);
}
use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testCompositeFactPatternWithFromWithDSL.
@Test
public void testCompositeFactPatternWithFromWithDSL() {
final RuleModel m = new RuleModel();
m.name = "model";
final DSLSentence sen = new DSLSentence();
sen.setDefinition("A DSL phrase");
m.addLhsItem(sen);
final FactPattern fp1 = new FactPattern("Data");
fp1.setBoundName("$d");
m.addLhsItem(fp1);
final CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_NOT);
final FactPattern fp2 = new FactPattern("Person");
final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern();
ffp1.setExpression(new ExpressionFormLine(new ExpressionVariable(fp1.getBoundName(), fp1.getFactType())));
ffp1.setFactPattern(fp2);
cp.addFactPattern(ffp1);
m.addLhsItem(cp);
final String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
final String expected = "rule \"model\"\n" + "dialect \"mvel\"\n" + "when\n" + "A DSL phrase\n" + ">$d : Data( )\n" + ">not ( Person( ) from $d\n" + ")\n" + "then\n" + "end\n";
assertEqualsIgnoreWhitespace(expected, actual);
}
use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine in project drools-wb by kiegroup.
the class ConstraintValueEditor method wrap.
// Wrap a Constraint Value Editor with an icon to remove the type
Widget wrap(Widget widget) {
if (this.readOnly) {
return widget;
}
HorizontalPanel wrapper = new HorizontalPanel();
Image clear = GuidedRuleEditorImages508.INSTANCE.DeleteItemSmall();
clear.setTitle(GuidedRuleEditorResources.CONSTANTS.RemoveConstraintValueDefinition());
clear.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// Reset Constraint's value and value type
if (Window.confirm(GuidedRuleEditorResources.CONSTANTS.RemoveConstraintValueDefinitionQuestion())) {
constraint.setConstraintValueType(BaseSingleFieldConstraint.TYPE_UNDEFINED);
constraint.setValue(null);
constraint.clearParameters();
constraint.setExpressionValue(new ExpressionFormLine());
doTypeChosen();
}
}
});
wrapper.add(widget);
if (!this.readOnly) {
wrapper.add(clear);
wrapper.setCellVerticalAlignment(clear, HasVerticalAlignment.ALIGN_MIDDLE);
}
return wrapper;
}
use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine 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.ExpressionFormLine in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testMissingValueInFrom.
@Test
public void testMissingValueInFrom() throws Exception {
FactPattern boundPattern = new FactPattern("Person");
boundPattern.setBoundName("person");
boundPattern.addConstraint(new SingleFieldConstraint("addresses"));
FactPattern pattern = new FactPattern("Address");
SingleFieldConstraint constraint = new SingleFieldConstraint("street");
constraint.setOperator("!=");
pattern.addConstraint(constraint);
FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
fromCompositeFactPattern.setFactPattern(pattern);
ExpressionFormLine expression = new ExpressionFormLine();
expression.setBinding("person.addresses");
fromCompositeFactPattern.setExpression(expression);
model.lhs = new IPattern[] { boundPattern, fromCompositeFactPattern };
assertFalse(validator.isValid());
assertEquals(1, validator.getErrors().size());
assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0));
verify(constants).FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator("Address", "street");
}
Aggregations