Search in sources :

Example 11 with XmlStringBuilder

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

the class WLinkRenderer method doRender.

/**
 * Paints the given {@link WLink}.
 *
 * @param component the WLink to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WLink link = (WLink) component;
    XmlStringBuilder xml = renderContext.getWriter();
    String text = link.getText();
    String targetWindowName = link.getOpenNewWindow() ? link.getTargetWindowName() : null;
    String imageUrl = link.getImageUrl();
    xml.appendTagOpen("ui:link");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("disabled", link.isDisabled(), "true");
    xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
    xml.appendOptionalAttribute("toolTip", link.getToolTip());
    xml.appendOptionalAttribute("accessibleText", link.getAccessibleText());
    xml.appendUrlAttribute("url", link.getUrl());
    xml.appendOptionalAttribute("rel", link.getRel());
    xml.appendOptionalAttribute("accessKey", Util.upperCase(link.getAccessKeyAsString()));
    if (imageUrl != null) {
        xml.appendUrlAttribute("imageUrl", imageUrl);
        ImagePosition imagePosition = link.getImagePosition();
        if (imagePosition != null) {
            switch(imagePosition) {
                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: " + imagePosition);
            }
        }
        // we have an image. We must have a text equivalent
        if (Util.empty(text) && Util.empty(link.getToolTip()) && Util.empty(link.getAccessibleText())) {
            // If the link has an umageUrl but no text equivalent get the text equivalent off of the image
            WImage linkImage = link.getImageHolder();
            if (null != linkImage) {
                xml.appendOptionalAttribute("toolTip", linkImage.getAlternativeText());
            }
        }
    }
    if (link.isRenderAsButton()) {
        xml.appendAttribute("type", "button");
    }
    xml.appendClose();
    if (targetWindowName != null) {
        xml.appendTagOpen("ui:windowAttributes");
        xml.appendAttribute("name", targetWindowName);
        WLink.WindowAttributes attributes = link.getWindowAttrs();
        if (attributes != null) {
            xml.appendOptionalAttribute("top", attributes.getTop() >= 0, attributes.getTop());
            xml.appendOptionalAttribute("left", attributes.getLeft() >= 0, attributes.getLeft());
            xml.appendOptionalAttribute("width", attributes.getWidth() > 0, attributes.getWidth());
            xml.appendOptionalAttribute("height", attributes.getHeight() > 0, attributes.getHeight());
            xml.appendOptionalAttribute("resizable", attributes.isResizable(), "true");
            xml.appendOptionalAttribute("showMenubar", attributes.isMenubar(), "true");
            xml.appendOptionalAttribute("showToolbar", attributes.isToolbars(), "true");
            xml.appendOptionalAttribute("showLocation", attributes.isLocation(), "true");
            xml.appendOptionalAttribute("showStatus", attributes.isStatus(), "true");
            xml.appendOptionalAttribute("showScrollbars", attributes.isScrollbars(), "true");
            xml.appendOptionalAttribute("showDirectories", attributes.isDirectories(), "true");
        }
        xml.appendEnd();
    }
    if (text != null) {
        xml.appendEscaped(text);
    }
    xml.appendEndTag("ui:link");
    // Paint the AJAX trigger if the link has an action
    if (link.getAction() != null) {
        paintAjaxTrigger(link, xml);
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) ImagePosition(com.github.bordertech.wcomponents.WLink.ImagePosition) WImage(com.github.bordertech.wcomponents.WImage) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WLink(com.github.bordertech.wcomponents.WLink)

Example 12 with XmlStringBuilder

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

the class WListRenderer method paintRows.

/**
 * Paints the rows.
 *
 * @param list the WList to paint the rows for.
 * @param renderContext the RenderContext to paint to.
 */
protected void paintRows(final WList list, final WebXmlRenderContext renderContext) {
    List<?> beanList = list.getBeanList();
    WComponent row = list.getRepeatedComponent();
    XmlStringBuilder xml = renderContext.getWriter();
    for (int i = 0; i < beanList.size(); i++) {
        Object rowData = beanList.get(i);
        // Each row has its own context. This is why we can reuse the same
        // WComponent instance for each row.
        UIContext rowContext = list.getRowContext(rowData, i);
        UIContextHolder.pushContext(rowContext);
        try {
            xml.appendTag("ui:cell");
            row.paint(renderContext);
            xml.appendEndTag("ui:cell");
        } finally {
            UIContextHolder.popContext();
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 13 with XmlStringBuilder

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

the class WListRenderer method doRender.

/**
 * Paints the given WList.
 *
 * @param component the WList to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WList list = (WList) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WList.Type type = list.getType();
    WList.Separator separator = list.getSeparator();
    Size gap = list.getSpace();
    String gapString = gap == null ? null : gap.toString();
    xml.appendTagOpen("ui:panel");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("type", list.isRenderBorder(), "box");
    xml.appendClose();
    // Render margin
    MarginRendererUtil.renderMargin(list, renderContext);
    xml.appendTagOpen("ui:listlayout");
    xml.appendOptionalAttribute("gap", gapString);
    if (type != null) {
        switch(type) {
            case FLAT:
                xml.appendAttribute("type", "flat");
                break;
            case STACKED:
                xml.appendAttribute("type", "stacked");
                break;
            case STRIPED:
                xml.appendAttribute("type", "striped");
                break;
            default:
                throw new SystemException("Unknown list type: " + type);
        }
    }
    if (separator != null) {
        switch(separator) {
            case BAR:
                xml.appendAttribute("separator", "bar");
                break;
            case DOT:
                xml.appendAttribute("separator", "dot");
                break;
            case NONE:
                break;
            default:
                throw new SystemException("Unknown list type: " + type);
        }
    }
    xml.appendClose();
    paintRows(list, renderContext);
    xml.appendEndTag("ui:listlayout");
    xml.appendEndTag("ui:panel");
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) Size(com.github.bordertech.wcomponents.Size) WList(com.github.bordertech.wcomponents.WList) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 14 with XmlStringBuilder

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

the class WMenuItemGroupRenderer method doRender.

/**
 * Paints the given WMenuItemGroup.
 *
 * @param component the WMenuItemGroup to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WMenuItemGroup group = (WMenuItemGroup) component;
    XmlStringBuilder xml = renderContext.getWriter();
    xml.appendTagOpen("ui:menugroup");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendClose();
    paintChildren(group, renderContext);
    xml.appendEndTag("ui:menugroup");
}
Also used : WMenuItemGroup(com.github.bordertech.wcomponents.WMenuItemGroup) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 15 with XmlStringBuilder

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

the class WMenuRenderer method doRender.

/**
 * 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("class", component.getHtmlClass());
    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.getSelectionMode()) {
        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");
}
Also used : WMenu(com.github.bordertech.wcomponents.WMenu) 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