Search in sources :

Example 71 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class FileWidgetRendererUtil method renderFileElement.

/**
 * @param widget the multi file widget
 * @param xml the xml string builder
 * @param file the file to render
 * @param idx the index of the file
 */
public static void renderFileElement(final WMultiFileWidget widget, final XmlStringBuilder xml, final FileWidgetUpload file, final int idx) {
    xml.appendTagOpen("ui:file");
    xml.appendAttribute("id", file.getFileId());
    xml.appendAttribute("name", file.getFile().getName());
    xml.appendAttribute("type", file.getFile().getMimeType());
    xml.appendAttribute("size", String.valueOf(file.getFile().getSize()));
    xml.appendClose();
    // Link to file
    xml.appendTagOpen("ui:link");
    xml.appendAttribute("id", widget.getId() + "-" + idx);
    xml.appendUrlAttribute("url", widget.getFileUrl(file.getFileId()));
    // Thumb nail (if used)
    if (widget.isUseThumbnails()) {
        xml.appendUrlAttribute("imageUrl", widget.getFileThumbnailUrl(file.getFileId()));
        // Position (if provided)
        ImagePosition thumbnailPosition = widget.getThumbnailPosition();
        if (thumbnailPosition != null) {
            switch(thumbnailPosition) {
                case NORTH:
                    xml.appendAttribute("imagePosition", "n");
                    break;
                case EAST:
                    xml.appendAttribute("imagePosition", "e");
                    break;
                case SOUTH:
                    xml.appendAttribute("imagePosition", "s");
                    break;
                case WEST:
                    xml.appendAttribute("imagePosition", "w");
                    break;
                default:
                    throw new SystemException("Unknown image position: " + thumbnailPosition);
            }
        }
    }
    xml.appendClose();
    if (widget.getFileAjaxAction() == null) {
        xml.appendTagOpen("ui:windowAttributes");
        xml.appendAttribute("name", "uploadfile");
        xml.appendEnd();
    }
    xml.appendEscaped(file.getFile().getName());
    xml.appendEndTag("ui:link");
    xml.appendEndTag("ui:file");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) ImagePosition(com.github.bordertech.wcomponents.WLink.ImagePosition)

Example 72 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class WButtonRenderer method doRender.

/**
 * Paints the given WButton.
 *
 * @param component the WButton to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    XmlStringBuilder xml = renderContext.getWriter();
    WButton button = (WButton) component;
    String text = button.getText();
    String imageUrl = button.getImageUrl();
    String accessibleText = button.getAccessibleText();
    String toolTip = button.getToolTip();
    if (Util.empty(text) && imageUrl == null && Util.empty(accessibleText) && Util.empty(toolTip)) {
        throw new SystemException("WButton text or imageUrl must be specified");
    }
    xml.appendTagOpen(getTagName(button));
    String buttonId = button.getId();
    ImagePosition pos = button.getImagePosition();
    if (Util.empty(text) && Util.empty(toolTip) && Util.empty(accessibleText)) {
        // If the button has an imageUrl but no text equivalent get the text equivalent off of the image
        WImage imgHolder = button.getImageHolder();
        if (null != imgHolder) {
            toolTip = imgHolder.getAlternativeText();
        }
    }
    xml.appendAttribute("id", buttonId);
    xml.appendAttribute("name", buttonId);
    xml.appendAttribute("value", "x");
    xml.appendAttribute("type", getButtonType(button));
    xml.appendAttribute("class", geHtmlClassName(button));
    xml.appendOptionalAttribute("disabled", button.isDisabled(), "disabled");
    xml.appendOptionalAttribute("hidden", button.isHidden(), "hidden");
    xml.appendOptionalAttribute("title", toolTip);
    xml.appendOptionalAttribute("aria-label", accessibleText);
    xml.appendOptionalAttribute("aria-haspopup", button.isPopupTrigger(), "true");
    xml.appendOptionalAttribute("accesskey", Util.upperCase(button.getAccessKeyAsString()));
    xml.appendOptionalAttribute("data-wc-btnmsg", button.getMessage());
    if (button.isCancel()) {
        xml.appendAttribute("formnovalidate", "formnovalidate");
    } else {
        Action action = button.getAction();
        if (action instanceof ValidatingAction) {
            WComponent validationTarget = ((ValidatingAction) action).getComponentToValidate();
            xml.appendAttribute("data-wc-validate", validationTarget.getId());
        }
    }
    xml.appendClose();
    if (imageUrl != null) {
        xml.appendTagOpen("span");
        String imageHolderClass = "wc_nti";
        if (pos != null) {
            StringBuffer imageHolderClassBuffer = new StringBuffer("wc_btn_img wc_btn_img");
            switch(pos) {
                case NORTH:
                    imageHolderClassBuffer.append("n");
                    break;
                case EAST:
                    imageHolderClassBuffer.append("e");
                    break;
                case SOUTH:
                    imageHolderClassBuffer.append("s");
                    break;
                case WEST:
                    imageHolderClassBuffer.append("w");
                    break;
                default:
                    throw new SystemException("Unknown image position: " + pos);
            }
            imageHolderClass = imageHolderClassBuffer.toString();
        }
        xml.appendAttribute("class", imageHolderClass);
        xml.appendClose();
        if (pos != null && text != null) {
            xml.appendTag("span");
            xml.appendEscaped(text);
            xml.appendEndTag("span");
        }
        xml.appendTagOpen("img");
        xml.appendUrlAttribute("src", imageUrl);
        String alternateText = pos == null ? text : "";
        xml.appendAttribute("alt", alternateText);
        xml.appendEnd();
        xml.appendEndTag("span");
    } else if (text != null) {
        xml.appendEscaped(text);
    }
    xml.appendEndTag(getTagName(button));
    if (button.isAjax()) {
        paintAjax(button, xml);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) SystemException(com.github.bordertech.wcomponents.util.SystemException) ImagePosition(com.github.bordertech.wcomponents.WButton.ImagePosition) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) WImage(com.github.bordertech.wcomponents.WImage) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WButton(com.github.bordertech.wcomponents.WButton)

Example 73 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class WCheckBoxSelectRenderer method doRender.

/**
 * 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 cols = select.getButtonColumns();
    boolean readOnly = select.isReadOnly();
    xml.appendTagOpen("ui:checkboxselect");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", select.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        int min = select.getMinSelect();
        int max = select.getMaxSelect();
        xml.appendOptionalAttribute("disabled", select.isDisabled(), "true");
        xml.appendOptionalAttribute("required", select.isMandatory(), "true");
        xml.appendOptionalAttribute("submitOnChange", select.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", component.getToolTip());
        xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
        xml.appendOptionalAttribute("min", min > 0, min);
        xml.appendOptionalAttribute("max", max > 0, max);
    }
    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.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);
            }
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(select, renderContext);
    }
    xml.appendEndTag("ui:checkboxselect");
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect)

Example 74 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class WDataTableRenderer method doRender.

/**
 * Paints the given WDataTable.
 *
 * @param component the WDataTable to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WDataTable table = (WDataTable) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:table");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", table.isHidden(), "true");
    xml.appendOptionalAttribute("caption", table.getCaption());
    switch(table.getType()) {
        case TABLE:
            xml.appendAttribute("type", "table");
            break;
        case HIERARCHIC:
            xml.appendAttribute("type", "hierarchic");
            break;
        default:
            throw new SystemException("Unknown table type: " + table.getType());
    }
    switch(table.getStripingType()) {
        case ROWS:
            xml.appendAttribute("striping", "rows");
            break;
        case COLUMNS:
            xml.appendAttribute("striping", "cols");
            break;
        case NONE:
            break;
        default:
            throw new SystemException("Unknown striping type: " + table.getStripingType());
    }
    switch(table.getSeparatorType()) {
        case HORIZONTAL:
            xml.appendAttribute("separators", "horizontal");
            break;
        case VERTICAL:
            xml.appendAttribute("separators", "vertical");
            break;
        case BOTH:
            xml.appendAttribute("separators", "both");
            break;
        case NONE:
            break;
        default:
            throw new SystemException("Unknown separator type: " + table.getSeparatorType());
    }
    xml.appendClose();
    if (table.getPaginationMode() != PaginationMode.NONE) {
        paintPaginationElement(table, xml);
    }
    if (table.getSelectMode() != SelectMode.NONE) {
        paintRowSelectionElement(table, xml);
    }
    if (table.getExpandMode() != ExpandMode.NONE) {
        paintRowExpansionElement(table, xml);
    }
    if (table.isSortable()) {
        paintSortElement(table, xml);
    }
    paintColumnHeadings(table, renderContext);
    paintRows(table, renderContext);
    paintTableActions(table, renderContext);
    xml.appendEndTag("ui:table");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) WDataTable(com.github.bordertech.wcomponents.WDataTable) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 75 with SystemException

use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.

the class WRadioButtonSelectRenderer method doRender.

/**
 * Paints the given WRadioButtonSelect.
 *
 * @param component the WRadioButtonSelect to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WRadioButtonSelect rbSelect = (WRadioButtonSelect) component;
    XmlStringBuilder xml = renderContext.getWriter();
    int cols = rbSelect.getButtonColumns();
    boolean readOnly = rbSelect.isReadOnly();
    xml.appendTagOpen("ui:radiobuttonselect");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", rbSelect.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendOptionalAttribute("disabled", rbSelect.isDisabled(), "true");
        xml.appendOptionalAttribute("required", rbSelect.isMandatory(), "true");
        xml.appendOptionalAttribute("submitOnChange", rbSelect.isSubmitOnChange(), "true");
        xml.appendOptionalAttribute("toolTip", component.getToolTip());
        xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
    }
    xml.appendOptionalAttribute("frameless", rbSelect.isFrameless(), "true");
    switch(rbSelect.getButtonLayout()) {
        case COLUMNS:
            xml.appendAttribute("layout", "column");
            xml.appendOptionalAttribute("layoutColumnCount", cols > 0, String.valueOf(cols));
            break;
        case FLAT:
            xml.appendAttribute("layout", "flat");
            break;
        case STACKED:
            xml.appendAttribute("layout", "stacked");
            break;
        default:
            throw new SystemException("Unknown radio button layout: " + rbSelect.getButtonLayout());
    }
    xml.appendClose();
    // Options
    List<?> options = rbSelect.getOptions();
    boolean renderSelectionsOnly = readOnly;
    if (options != null) {
        int optionIndex = 0;
        Object selectedOption = rbSelect.getSelected();
        for (Object option : options) {
            if (option instanceof OptionGroup) {
                throw new SystemException("Option groups not supported in WRadioButtonSelect.");
            } else {
                renderOption(rbSelect, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
            }
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(rbSelect, renderContext);
    }
    xml.appendEndTag("ui:radiobuttonselect");
    if (rbSelect.isAjax()) {
        paintAjax(rbSelect, xml);
    }
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) SystemException(com.github.bordertech.wcomponents.util.SystemException) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Aggregations

SystemException (com.github.bordertech.wcomponents.util.SystemException)91 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)17 WComponent (com.github.bordertech.wcomponents.WComponent)15 UIContext (com.github.bordertech.wcomponents.UIContext)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 Test (org.junit.Test)9 WebElement (org.openqa.selenium.WebElement)8 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 IOException (java.io.IOException)5 Select (org.openqa.selenium.support.ui.Select)5 Environment (com.github.bordertech.wcomponents.Environment)4 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3 Date (java.util.Date)3 List (java.util.List)3 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)2 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)2