Search in sources :

Example 76 with XmlStringBuilder

use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.

the class WImageEditorRenderer method doRender.

/**
 * Paints the given {@link WImageEditor}.
 *
 * @param component the WImageEditor to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WImageEditor editorComponent = (WImageEditor) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("wc-imageedit");
    xml.appendAttribute("id", editorComponent.getId());
    xml.appendOptionalAttribute("class", editorComponent.getHtmlClass());
    xml.appendOptionalUrlAttribute("overlay", editorComponent.getOverlayUrl());
    xml.appendOptionalAttribute("camera", editorComponent.getUseCamera());
    xml.appendOptionalAttribute("face", editorComponent.getIsFace());
    xml.appendOptionalAttribute("inline", editorComponent.getRenderInline());
    // Check for size information on the image
    Dimension size = editorComponent.getSize();
    if (size != null) {
        if (size.getHeight() >= 0) {
            xml.appendAttribute("height", size.height);
        }
        if (size.getWidth() >= 0) {
            xml.appendAttribute("width", size.width);
        }
    }
    xml.appendEnd();
}
Also used : WImageEditor(com.github.bordertech.wcomponents.WImageEditor) Dimension(java.awt.Dimension) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 77 with XmlStringBuilder

use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.

the class WLabelRenderer method doRender.

/**
 * Paints the given {@link WLabel}.
 *
 * @param component the WLabel to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WLabel label = (WLabel) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:label");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("for", label.getLabelFor());
    WComponent what = label.getForComponent();
    String whatFor = null;
    if (what instanceof MultiInputComponent) {
        whatFor = "group";
    } else if (what instanceof Labelable) {
        whatFor = "input";
    }
    boolean isReadOnly = ((what instanceof Input) && ((Input) what).isReadOnly()) || (what instanceof WRadioButton && ((WRadioButton) what).isReadOnly());
    boolean isMandatory = (what instanceof Input) && ((Input) what).isMandatory();
    xml.appendOptionalAttribute("what", whatFor);
    xml.appendOptionalAttribute("readonly", isReadOnly, "true");
    xml.appendOptionalAttribute("required", isMandatory, "true");
    xml.appendOptionalAttribute("hiddencomponent", (what != null && what.isHidden()), "true");
    xml.appendOptionalAttribute("hint", label.getHint());
    xml.appendOptionalAttribute("accessKey", Util.upperCase(label.getAccessKeyAsString()));
    xml.appendOptionalAttribute("hidden", label.isHidden(), "true");
    xml.appendOptionalAttribute("toolTip", label.getToolTip());
    xml.appendOptionalAttribute("accessibleText", label.getAccessibleText());
    xml.appendClose();
    xml.append(label.getText(), label.isEncodeText());
    paintChildren(label, renderContext);
    xml.appendEndTag("ui:label");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Labelable(com.github.bordertech.wcomponents.Labelable) MultiInputComponent(com.github.bordertech.wcomponents.MultiInputComponent) Input(com.github.bordertech.wcomponents.Input) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 78 with XmlStringBuilder

use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.

the class WMenuItemRenderer method doRender.

/**
 * Paints the given WMenuItem.
 *
 * @param component the WMenuItem to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMenuItem item = (WMenuItem) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:menuitem");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    if (item.isSubmit()) {
        xml.appendAttribute("submit", "true");
    } else {
        xml.appendOptionalUrlAttribute("url", item.getUrl());
        xml.appendOptionalAttribute("targetWindow", item.getTargetWindow());
    }
    xml.appendOptionalAttribute("disabled", item.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", item.isHidden(), "true");
    xml.appendOptionalAttribute("selected", item.isSelected(), "true");
    xml.appendOptionalAttribute("role", getRole(item));
    xml.appendOptionalAttribute("cancel", item.isCancel(), "true");
    xml.appendOptionalAttribute("msg", item.getMessage());
    xml.appendOptionalAttribute("toolTip", item.getToolTip());
    if (item.isTopLevelItem()) {
        xml.appendOptionalAttribute("accessKey", item.getAccessKeyAsString());
    }
    xml.appendClose();
    item.getDecoratedLabel().paint(renderContext);
    xml.appendEndTag("ui:menuitem");
}
Also used : WMenuItem(com.github.bordertech.wcomponents.WMenuItem) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 79 with XmlStringBuilder

use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.

the class WMultiFileWidgetRenderer method doRender.

/**
 * Paints the given WMultiFileWidget.
 *
 * @param component the WMultiFileWidget to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMultiFileWidget widget = (WMultiFileWidget) component;
    XmlStringBuilder xml = renderContext.getWriter();
    // Check if rendering a file upload response
    String uploadId = widget.getFileUploadRequestId();
    if (uploadId != null) {
        handleFileUploadRequest(widget, xml, uploadId);
        return;
    }
    boolean readOnly = widget.isReadOnly();
    xml.appendTagOpen(TAG_NAME);
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", widget.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        long maxFileSize = widget.getMaxFileSize();
        int maxFiles = widget.getMaxFiles();
        WComponent dropzone = widget.getDropzone();
        WImageEditor editor = widget.getEditor();
        xml.appendOptionalAttribute("disabled", widget.isDisabled(), "true");
        xml.appendOptionalAttribute("required", widget.isMandatory(), "true");
        xml.appendOptionalAttribute("toolTip", widget.getToolTip());
        xml.appendOptionalAttribute("accessibleText", widget.getAccessibleText());
        xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(widget.getFileTypes()));
        xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
        xml.appendOptionalAttribute("maxFiles", maxFiles > 0, maxFiles);
        if (dropzone != null) {
            xml.appendAttribute("dropzone", dropzone.getId());
        }
        if (editor != null) {
            xml.appendAttribute("editor", editor.getId());
            if (editor.getUseCamera()) {
                xml.appendAttribute("camera", true);
            }
        }
    }
    if (widget.getColumns() != null) {
        xml.appendAttribute("cols", widget.getColumns());
    }
    if (widget.getFileAjaxAction() != null) {
        xml.appendAttribute("ajax", "true");
    }
    List<Diagnostic> diags = readOnly ? null : widget.getDiagnostics(Diagnostic.ERROR);
    if (widget.getFiles().isEmpty()) {
        if (readOnly || diags == null || diags.isEmpty()) {
            xml.appendEnd();
            return;
        }
        xml.appendClose();
    } else {
        xml.appendClose();
        // Render files
        int i = 0;
        for (FileWidgetUpload file : widget.getFiles()) {
            FileWidgetRendererUtil.renderFileElement(widget, xml, file, i++);
        }
    }
    if (!readOnly && diags != null && !diags.isEmpty()) {
        DiagnosticRenderUtil.renderDiagnostics(widget, renderContext);
    }
    xml.appendEndTag(TAG_NAME);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WImageEditor(com.github.bordertech.wcomponents.WImageEditor) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WMultiFileWidget(com.github.bordertech.wcomponents.WMultiFileWidget) FileWidgetUpload(com.github.bordertech.wcomponents.WMultiFileWidget.FileWidgetUpload) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 80 with XmlStringBuilder

use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.

the class WMultiSelectPairRenderer method doRender.

/**
 * Paints the given WMultiSelectPair.
 *
 * @param component the WMultiSelectPair to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMultiSelectPair multiSelectPair = (WMultiSelectPair) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = multiSelectPair.isReadOnly();
    xml.appendTagOpen("ui:multiselectpair");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", multiSelectPair.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        int rows = multiSelectPair.getRows();
        int min = multiSelectPair.getMinSelect();
        int max = multiSelectPair.getMaxSelect();
        xml.appendAttribute("size", rows < 2 ? WMultiSelectPair.DEFAULT_ROWS : rows);
        xml.appendOptionalAttribute("disabled", multiSelectPair.isDisabled(), "true");
        xml.appendOptionalAttribute("required", multiSelectPair.isMandatory(), "true");
        xml.appendOptionalAttribute("shuffle", multiSelectPair.isShuffle(), "true");
        xml.appendOptionalAttribute("fromListName", multiSelectPair.getAvailableListName());
        xml.appendOptionalAttribute("toListName", multiSelectPair.getSelectedListName());
        xml.appendOptionalAttribute("accessibleText", multiSelectPair.getAccessibleText());
        xml.appendOptionalAttribute("min", min > 0, min);
        xml.appendOptionalAttribute("max", max > 0, max);
    }
    xml.appendClose();
    // Options
    List<?> options = multiSelectPair.getOptions();
    boolean renderSelectionsOnly = readOnly;
    if (options != null) {
        if (multiSelectPair.isShuffle()) {
            // We need to render the selected options in order
            renderOrderedOptions(multiSelectPair, options, 0, xml, renderSelectionsOnly);
        } else {
            renderUnorderedOptions(multiSelectPair, options, 0, xml, renderSelectionsOnly);
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(multiSelectPair, renderContext);
    }
    xml.appendEndTag("ui:multiselectpair");
}
Also used : WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Aggregations

XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)102 WComponent (com.github.bordertech.wcomponents.WComponent)30 SystemException (com.github.bordertech.wcomponents.util.SystemException)17 Size (com.github.bordertech.wcomponents.Size)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)6 UIContext (com.github.bordertech.wcomponents.UIContext)5 WPanel (com.github.bordertech.wcomponents.WPanel)5 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 WButton (com.github.bordertech.wcomponents.WButton)4 WSuggestions (com.github.bordertech.wcomponents.WSuggestions)4 WTable (com.github.bordertech.wcomponents.WTable)4 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)4 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)3 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)3 WDataTable (com.github.bordertech.wcomponents.WDataTable)3 WRepeater (com.github.bordertech.wcomponents.WRepeater)3 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2