Search in sources :

Example 1 with ImagePosition

use of com.github.bordertech.wcomponents.WLink.ImagePosition 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 2 with ImagePosition

use of com.github.bordertech.wcomponents.WLink.ImagePosition 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)

Aggregations

ImagePosition (com.github.bordertech.wcomponents.WLink.ImagePosition)2 SystemException (com.github.bordertech.wcomponents.util.SystemException)2 WImage (com.github.bordertech.wcomponents.WImage)1 WLink (com.github.bordertech.wcomponents.WLink)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1