@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");
  }
  protected void doLayout() {

    int row = 0;
    if (pattern.getFactPattern() != null) {
      FactPattern fact = pattern.getFactPattern();
      if (fact != null) {
        this.layout.setWidget(row++, 0, createFactPatternWidget(fact));
      }
    }

    this.layout.setWidget(row++, 0, getCompositeLabel());
  }
  @Test
  public void testValidFromCompositeFactPattern() throws Exception {

    FactPattern factPattern = new FactPattern("SomeList");
    factPattern.setBoundName("list");

    FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
    fromCompositeFactPattern.setFactPattern(new FactPattern("Person"));
    ExpressionFormLine expression = new ExpressionFormLine();
    expression.appendPart(new ExpressionVariable("list", "SomeList", "SomeList"));
    fromCompositeFactPattern.setExpression(expression);
    model.lhs = new IPattern[] {fromCompositeFactPattern};

    assertTrue(validator.isValid());
  }
  @Test
  public void testMissingRHSPartInFrom() throws Exception {

    FactPattern pattern = new FactPattern("Address");

    SingleFieldConstraint constraint = new SingleFieldConstraint("street");
    pattern.addConstraint(constraint);

    FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
    fromCompositeFactPattern.setFactPattern(pattern);
    ExpressionFormLine expression = new ExpressionFormLine();
    fromCompositeFactPattern.setExpression(expression);

    model.lhs = new IPattern[] {fromCompositeFactPattern};

    assertFalse(validator.isValid());
    assertEquals(1, validator.getErrors().size());
    assertEquals(MISSING_RHS_FROM, validator.getErrors().get(0));

    verify(constants).WhenUsingFromTheSourceNeedsToBeSet();
  }
  @Test
  public void testWorkingFrom() 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");
    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};

    assertTrue(validator.isValid());
  }
  protected Widget getCompositeLabel() {

    ClickHandler click =
        new ClickHandler() {

          public void onClick(ClickEvent event) {
            Widget w = (Widget) event.getSource();
            showFactTypeSelector(w);
          }
        };
    String lbl =
        "<div class='form-field'>" + HumanReadable.getCEDisplayName("from") + "&nbsp;</div>";

    FlexTable panel = new FlexTable();

    int r = 0;

    if (pattern.getFactPattern() == null) {
      panel.setWidget(
          r,
          0,
          new ClickableLabel(
              "<br> <font color='red'>"
                  + GuidedRuleEditorResources.CONSTANTS.clickToAddPatterns()
                  + "</font>",
              click,
              !this.readOnly));
      r++;
    }

    panel.setWidget(r, 0, new HTML(lbl));
    ExpressionBuilder expressionBuilder =
        new ExpressionBuilder(
            this.getModeller(), this.getEventBus(), this.pattern.getExpression(), this.readOnly);
    expressionBuilder.addOnModifiedCommand(
        new Command() {
          public void execute() {
            setModified(true);
          }
        });
    panel.setWidget(r, 1, expressionBuilder);

    return panel;
  }