コード例 #1
0
  /**
   * Paints the given WMenu.
   *
   * @param component the WMenu to paint.
   * @param renderContext the RenderContext to paint to.
   */
  @Override
  public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMenu menu = (WMenu) component;
    XmlStringBuilder xml = renderContext.getWriter();
    int rows = menu.getRows();

    xml.appendTagOpen("ui:menu");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");

    switch (menu.getType()) {
      case BAR:
        xml.appendAttribute("type", "bar");
        break;

      case FLYOUT:
        xml.appendAttribute("type", "flyout");
        break;

      case TREE:
        xml.appendAttribute("type", "tree");
        break;

      case COLUMN:
        xml.appendAttribute("type", "column");
        break;

      default:
        throw new IllegalStateException("Invalid menu type: " + menu.getType());
    }

    xml.appendOptionalAttribute("disabled", menu.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", menu.isHidden(), "true");
    xml.appendOptionalAttribute("rows", rows > 0, rows);

    switch (menu.getSelectMode()) {
      case NONE:
        break;

      case SINGLE:
        xml.appendAttribute("selectMode", "single");
        break;

      case MULTIPLE:
        xml.appendAttribute("selectMode", "multiple");
        break;

      default:
        throw new IllegalStateException("Invalid select mode: " + menu.getSelectMode());
    }

    xml.appendClose();

    // Render margin
    MarginRendererUtil.renderMargin(menu, renderContext);

    paintChildren(menu, renderContext);

    xml.appendEndTag("ui:menu");
  }
コード例 #2
0
  /**
   * Paint the ajax container response.
   *
   * @param renderContext the render context
   * @param operation the ajax operation
   */
  private void paintContainerResponse(
      final RenderContext renderContext, final AjaxOperation operation) {
    WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
    XmlStringBuilder xml = webRenderContext.getWriter();

    // Get trigger's context
    ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
    if (trigger == null) {
      throw new SystemException("No context available for trigger " + operation.getTriggerId());
    }

    xml.appendTagOpen("ui:ajaxTarget");
    xml.appendAttribute("id", operation.getTargetContainerId());
    xml.appendAttribute("action", "replaceContent");
    xml.appendClose();

    // Paint targets - Assume targets are in the same context as the trigger
    UIContextHolder.pushContext(trigger.getContext());
    try {
      for (String targetId : operation.getTargets()) {
        ComponentWithContext target = null;
        if (targetId.equals(operation.getTriggerId())) {
          target = trigger;
        } else {
          target = WebUtilities.getComponentById(targetId, true);
          if (target == null) {
            log.warn("Could not find ajax target to render " + target);
            continue;
          }
        }
        target.getComponent().paint(renderContext);
      }
    } finally {
      UIContextHolder.popContext();
    }

    xml.appendEndTag("ui:ajaxTarget");
  }
コード例 #3
0
  /**
   * Renders a single option within the check box select.
   *
   * @param select the check box select being rendered.
   * @param option the option to render.
   * @param optionIndex the index of the option. OptionGroups are not counted.
   * @param html the XmlStringBuilder to paint to.
   * @param selections the list of selected options.
   * @param renderSelectionsOnly true to only render selected options, false to render all options.
   * @param encode true if the option description should be encoded, false if not.
   */
  private void renderOption(
      final WCheckBoxSelect select,
      final Object option,
      final int optionIndex,
      final XmlStringBuilder html,
      final List<?> selections,
      final boolean renderSelectionsOnly,
      final boolean encode) {
    boolean selected = selections.contains(option);

    if (selected || !renderSelectionsOnly) {
      // Get Code and Desc
      String code = select.getCode(option, optionIndex);
      String desc = select.getDesc(option, optionIndex);

      // Render Option
      html.appendTagOpen("ui:option");
      html.appendAttribute("value", code);
      html.appendOptionalAttribute("selected", selected, "true");
      html.appendClose();
      html.append(desc, encode);
      html.appendEndTag("ui:option");
    }
  }
コード例 #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");
  }
コード例 #5
0
  /**
   * Paints the given WCheckBoxSelect.
   *
   * @param component the WCheckBoxSelect to paint.
   * @param renderContext the RenderContext to paint to.
   */
  @Override
  public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WCheckBoxSelect select = (WCheckBoxSelect) component;
    XmlStringBuilder xml = renderContext.getWriter();
    int tabIndex = select.getTabIndex();
    int cols = select.getButtonColumns();
    boolean encode = select.getDescEncode();
    boolean readOnly = select.isReadOnly();
    int min = select.getMinSelect();
    int max = select.getMaxSelect();

    xml.appendTagOpen("ui:checkBoxSelect");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("disabled", select.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", select.isHidden(), "true");
    xml.appendOptionalAttribute("required", select.isMandatory(), "true");
    xml.appendOptionalAttribute("readOnly", readOnly, "true");
    xml.appendOptionalAttribute("submitOnChange", select.isSubmitOnChange(), "true");
    xml.appendOptionalAttribute("tabIndex", component.hasTabIndex(), tabIndex);
    xml.appendOptionalAttribute("toolTip", component.getToolTip());
    xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
    xml.appendOptionalAttribute("frameless", select.isFrameless(), "true");

    switch (select.getButtonLayout()) {
      case COLUMNS:
        xml.appendAttribute("layout", "column");
        xml.appendOptionalAttribute("layoutColumnCount", cols > 0, cols);
        break;
      case FLAT:
        xml.appendAttribute("layout", "flat");
        break;
      case STACKED:
        xml.appendAttribute("layout", "stacked");
        break;
      default:
        throw new SystemException("Unknown layout type: " + select.getButtonLayout());
    }

    xml.appendOptionalAttribute("min", min > 0, min);
    xml.appendOptionalAttribute("max", max > 0, max);

    xml.appendClose();

    // Options
    List<?> options = select.getOptions();
    boolean renderSelectionsOnly = readOnly;

    if (options != null) {
      int optionIndex = 0;
      List<?> selections = select.getSelected();

      for (Object option : options) {
        if (option instanceof OptionGroup) {
          throw new SystemException("Option groups not supported in WCheckBoxSelect.");
        } else {
          renderOption(
              select, option, optionIndex++, xml, selections, renderSelectionsOnly, encode);
        }
      }
    }

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