コード例 #1
0
  @Test
  public void testExecuteWithWPanel() {
    // Setup targets in a Panel
    WPanel panel = new WPanel();
    MyTarget target1 = new MyTarget();
    MyTarget target2 = new MyTarget();
    MyTarget target3 = new MyTarget();
    panel.add(target1);
    panel.add(target2);
    panel.add(target3);

    AbstractSetMandatory enable = new MyMandatory(panel, Boolean.TRUE);

    // Targets should be optional by default
    Assert.assertFalse("WPanel - Target1 should be optional", target1.isMandatory());
    Assert.assertFalse("WPanel - Target2 should be optional", target2.isMandatory());
    Assert.assertFalse("WPanel - Target3 should be optional", target3.isMandatory());

    enable.execute();

    // Targets should be mandatory
    Assert.assertTrue("WPanel - Target1 should be mandatory", target1.isMandatory());
    Assert.assertTrue("WPanel - Target2 should be mandatory", target2.isMandatory());
    Assert.assertTrue("WPanel - Target3 should be mandatory", target3.isMandatory());
  }
コード例 #2
0
  @Test
  public void testIsDefaultState() {
    WPanel root = new WPanel();
    WTextField component = new WTextField();
    WFieldErrorIndicator indicator = new WFieldErrorIndicator(component);

    root.add(indicator);
    root.add(component);

    root.setLocked(true);
    setActiveContext(createUIContext());
    Assert.assertTrue("Should be in default state by default", indicator.isDefaultState());

    List<Diagnostic> diags = new ArrayList<>();
    root.validate(diags);
    root.showErrorIndicators(diags);

    Assert.assertTrue("Should be in default if there are no errors", indicator.isDefaultState());

    // Add an error by making the field mandatory
    root.reset();
    component.setMandatory(true);
    root.validate(diags);
    root.showErrorIndicators(diags);

    Assert.assertFalse("Should not be in default if there are errors", indicator.isDefaultState());

    root.reset();
    Assert.assertTrue("Should be in default after reset", indicator.isDefaultState());
  }
コード例 #3
0
  /** {@inheritDoc} */
  @Override
  protected void preparePaintComponent(final Request request) {
    super.preparePaintComponent(request);

    if (Cache.getCache().get(DATA_KEY) != null) {
      poller.disablePoll();
    }
  }
コード例 #4
0
  /**
   * Paints the given WPanel's children.
   *
   * @param component the container to paint.
   * @param renderContext the RenderContext to paint to.
   */
  @Override
  public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPanel panel = (WPanel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    ListLayout layout = (ListLayout) panel.getLayout();
    int childCount = panel.getChildCount();
    int hgap = layout.getHgap();
    int vgap = layout.getVgap();

    xml.appendTagOpen("ui:listLayout");

    switch (layout.getType()) {
      case FLAT:
        xml.appendAttribute("type", "flat");
        break;

      case STACKED:
        xml.appendAttribute("type", "stacked");
        break;

      case STRIPED:
        xml.appendAttribute("type", "striped");
        break;

      default:
        throw new IllegalArgumentException("Invalid type: " + layout.getType());
    }

    switch (layout.getAlignment()) {
      case LEFT:
        // left is assumed if omitted
        break;

      case RIGHT:
        xml.appendAttribute("align", "right");
        break;

      case CENTER:
        xml.appendAttribute("align", "center");
        break;

      default:
        throw new IllegalArgumentException("Invalid alignment: " + layout.getAlignment());
    }

    switch (layout.getSeparator()) {
      case NONE:
        // none is assumed if omitted
        break;

      case BAR:
        xml.appendAttribute("separator", "bar");
        break;

      case DOT:
        xml.appendAttribute("separator", "dot");
        break;

      default:
        throw new IllegalArgumentException("Invalid separator: " + layout.getSeparator());
    }

    xml.appendOptionalAttribute("ordered", layout.isOrdered(), "true");

    xml.appendOptionalAttribute("hgap", hgap > 0, hgap);
    xml.appendOptionalAttribute("vgap", vgap > 0, vgap);

    xml.appendClose();

    // Paint children
    for (int i = 0; i < childCount; i++) {
      xml.appendTag("ui:cell");
      panel.getChildAt(i).paint(renderContext);
      xml.appendEndTag("ui:cell");
    }

    xml.appendEndTag("ui:listLayout");
  }