Example usage for com.google.gwt.safecss.shared SafeStylesBuilder appendTrustedString

List of usage examples for com.google.gwt.safecss.shared SafeStylesBuilder appendTrustedString

Introduction

In this page you can find the example usage for com.google.gwt.safecss.shared SafeStylesBuilder appendTrustedString.

Prototype

public SafeStylesBuilder appendTrustedString(String styles) 

Source Link

Document

Appends SafeStyles constructed from a trusted string, i.e., without escaping the string.

Usage

From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.layout.PortalLayoutContainerUiBinderExample.java

License:sencha.com license

@UiFactory()
public Grid<Stock> createGrid() {
    final NumberFormat number = NumberFormat.getFormat("0.00");

    ColumnConfig<Stock, String> nameCol = new ColumnConfig<Stock, String>(props.name(), 200, "Company");
    ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
    ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

    ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change");
    changeCol.setCell(new AbstractCell<Double>() {

        @Override//from w  w  w  .  ja va  2  s . c o  m
        public void render(Context context, Double value, SafeHtmlBuilder sb) {
            SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();
            stylesBuilder.appendTrustedString("color:" + (value < 0 ? "red" : "green") + ";");
            String v = number.format(value);
            CellTemplates cellTemplates = GWT.create(CellTemplates.class);
            SafeHtml template = cellTemplates.template(stylesBuilder.toSafeStyles(), v, v);
            sb.append(template);
        }
    });

    ColumnConfig<Stock, Date> lastTransCol = new ColumnConfig<Stock, Date>(props.lastTrans(), 100,
            "Last Updated");
    lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy")));

    List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
    l.add(nameCol);
    l.add(symbolCol);
    l.add(lastCol);
    l.add(changeCol);
    l.add(lastTransCol);
    ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

    ListStore<Stock> store = new ListStore<Stock>(props.key());
    store.addAll(TestData.getStocks());

    final Grid<Stock> grid = new Grid<Stock>(store, cm);
    grid.getView().setAutoExpandColumn(nameCol);
    grid.setBorders(false);
    grid.getView().setStripeRows(true);
    grid.getView().setColumnLines(true);

    // needed to enable quicktips (qtitle for the heading and qtip for the
    // content) that are setup in the change GridCellRenderer
    new QuickTip(grid);

    return grid;
}

From source file:com.novartis.pcs.ontology.webapp.client.view.ActionIconCellDecorator.java

License:Apache License

private SafeHtml getImageHtml(ImageResource res, VerticalAlignmentConstant valign) {
    AbstractImagePrototype proto = AbstractImagePrototype.create(res);
    SafeHtml image = SafeHtmlUtils.fromTrustedString(proto.getHTML());

    // Create the wrapper based on the vertical alignment.
    SafeStylesBuilder cssStyles = new SafeStylesBuilder().appendTrustedString(direction + ":0px;");
    if (HasVerticalAlignment.ALIGN_TOP == valign) {
        return templates.imageWrapperTop(cssStyles.toSafeStyles(), image);
    } else if (HasVerticalAlignment.ALIGN_BOTTOM == valign) {
        return templates.imageWrapperBottom(cssStyles.toSafeStyles(), image);
    } else {//from   w  ww .j  ava 2 s  .co m
        int halfHeight = (int) Math.round(res.getHeight() / 2.0);
        cssStyles.appendTrustedString("margin-top:-" + halfHeight + "px;");
        return templates.imageWrapperMiddle(cssStyles.toSafeStyles(), image);
    }
}

From source file:com.sencha.gxt.theme.base.client.button.ButtonCellDefaultAppearance.java

License:sencha.com license

@Override
public void render(final ButtonCell<C> cell, Context context, C value, SafeHtmlBuilder sb) {
    String constantHtml = cell.getHTML();
    boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0;
    boolean isBoolean = value != null && value instanceof Boolean;
    // is a boolean always a toggle button?
    SafeHtml valueHtml = SafeHtmlUtils.fromTrustedString(hasConstantHtml ? cell.getText()
            : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : "");

    ImageResource icon = cell.getIcon();
    IconAlign iconAlign = cell.getIconAlign();

    String cls = style.button();// w  ww  .  j  a  v a 2s  .c om
    String arrowCls = "";
    if (cell.getMenu() != null) {

        if (cell instanceof SplitButtonCell) {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.split();
                break;
            case BOTTOM:
                arrowCls = style.splitBottom();
                break;
            default:
                // empty
            }

        } else {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.arrow();
                break;
            case BOTTOM:
                arrowCls = style.arrowBottom();
                break;
            }
        }

    }

    ButtonScale scale = cell.getScale();

    switch (scale) {
    case SMALL:
        cls += " " + style.small();
        break;
    case MEDIUM:
        cls += " " + style.medium();
        break;
    case LARGE:
        cls += " " + style.large();
        break;
    default:
        // empty
    }

    SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();

    int width = -1;

    if (cell.getWidth() != -1) {
        int w = cell.getWidth();
        if (w < cell.getMinWidth()) {
            w = cell.getMinWidth();
        }
        stylesBuilder.appendTrustedString("width:" + w + "px;");
        cls += " " + style.hasWidth() + " x-has-width";
        width = w;
    } else {

        if (cell.getMinWidth() != -1) {
            TextMetrics.get().bind(style.text());
            int length = TextMetrics.get().getWidth(valueHtml);
            length += 6; // frames

            if (icon != null) {
                switch (iconAlign) {
                case LEFT:
                case RIGHT:
                    length += icon.getWidth();
                    break;
                default:
                    // empty
                }
            }

            if (cell.getMinWidth() > length) {
                stylesBuilder.appendTrustedString("width:" + cell.getMinWidth() + "px;");
                cls += " " + style.hasWidth() + " x-has-width";
                width = cell.getMinWidth();
            }
        }
    }

    final int height = cell.getHeight();
    if (height != -1) {
        stylesBuilder.appendTrustedString("height:" + height + "px;");
    }

    if (icon != null) {
        switch (iconAlign) {
        case TOP:
            arrowCls += " " + style.iconTop();
            break;
        case BOTTOM:
            arrowCls += " " + style.iconBottom();
            break;
        case LEFT:
            arrowCls += " " + style.iconLeft();
            break;
        case RIGHT:
            arrowCls += " " + style.iconRight();
            break;
        }

    } else {
        arrowCls += " " + style.noIcon();
    }

    // toggle button
    if (value == Boolean.TRUE) {
        cls += " " + frame.pressedClass();
    }

    sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles()));

    SafeHtmlBuilder inside = new SafeHtmlBuilder();

    String innerWrap = arrowCls;

    inside.appendHtmlConstant("<div class='" + innerWrap + "'>");
    inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>");

    boolean hasText = valueHtml != null && !valueHtml.equals("");

    if (icon != null) {
        switch (iconAlign) {
        case LEFT:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeValue(inside, valueHtml, w, height);
            }
            inside.appendHtmlConstant("</tr>");
            break;
        case RIGHT:
            inside.appendHtmlConstant("<tr>");
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeValue(inside, valueHtml, w, height);
            }
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        case TOP:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeValue(inside, valueHtml, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            break;
        case BOTTOM:
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeValue(inside, valueHtml, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        }

    } else {
        inside.appendHtmlConstant("<tr>");
        if (valueHtml != null) {
            writeValue(inside, valueHtml, width, height);
        }
        inside.appendHtmlConstant("</tr>");
    }
    inside.appendHtmlConstant("</table>");
    inside.appendHtmlConstant("</div>");

    frame.render(sb,
            new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()),
            inside.toSafeHtml());

    sb.appendHtmlConstant("</div>");

}

From source file:com.sencha.gxt.theme.base.client.field.FieldLabelDefaultAppearance.java

License:sencha.com license

@Override
public void render(SafeHtmlBuilder sb, String id, FieldLabelOptions options) {
    int labelWidth = options.getLabelWidth();
    LabelAlign align = options.getLabelAlign();

    int pad = options.getLabelPad();
    if (pad == 0)
        pad = 5;//from  ww  w .  j  ava2 s  .  c o m

    String fieldLabelWidth = align == LabelAlign.TOP ? "auto" : (labelWidth + "px");

    SafeStylesBuilder fieldLabelStylesBuilder = new SafeStylesBuilder()
            .appendTrustedString("width:" + fieldLabelWidth + ";");
    fieldLabelStylesBuilder
            .appendTrustedString("white-space: " + (options.getWordWrap() ? "normal" : "nowrap") + ";");

    SafeStyles fieldLabelStyles = fieldLabelStylesBuilder.toSafeStyles();

    String fieldElementPadding = align == LabelAlign.TOP ? "0" : (labelWidth + pad + "px");
    SafeStyles fieldElementStyles = SafeStylesUtils
            .fromTrustedString("padding-left:" + fieldElementPadding + ";");

    sb.append(template.render(id, style, fieldLabelStyles, fieldElementStyles));
}

From source file:com.sencha.gxt.widget.core.client.grid.ColumnHeader.java

License:sencha.com license

protected SafeHtml renderHiddenHeaders(int[] columnWidths) {
    SafeHtmlBuilder heads = new SafeHtmlBuilder();
    for (int i = 0; i < columnWidths.length; i++) {
        // unlike GridView, we do NOT render TH's for hidden elements because of support of
        // rowspan and colspan with header configs
        if (cm.isHidden(i)) {
            continue;
        }/*from  ww w  . ja  v a2 s .  co  m*/

        SafeStylesBuilder builder = new SafeStylesBuilder();
        builder.appendTrustedString("height: 0px;");
        builder.appendTrustedString("width:" + columnWidths[i] + "px;");
        heads.append(tpls.th("", builder.toSafeStyles()));
    }

    return tpls.tr("", heads.toSafeHtml());
}

From source file:com.sencha.gxt.widget.core.client.grid.GridView.java

License:sencha.com license

/**
 * Renders the hidden TH elements that keep the column widths.
 *
 * @param columnWidths the column widths
 * @return markup representing the hidden table header elements
 *///w  ww .j a v  a 2  s. c  o  m
protected SafeHtml renderHiddenHeaders(int[] columnWidths) {
    SafeHtmlBuilder heads = new SafeHtmlBuilder();
    for (int i = 0; i < columnWidths.length; i++) {
        int w = cm.isHidden(i) ? 0 : columnWidths[i];
        SafeStylesBuilder builder = new SafeStylesBuilder();
        builder.appendTrustedString("height: 0px;");
        builder.appendTrustedString("width:" + w + "px;");
        heads.append(tpls.th("", builder.toSafeStyles()));
    }
    return tpls.tr(appearance.styles().headerRow(), heads.toSafeHtml());
}

From source file:com.tmc.client.ui.field.LookupFieldAppearance.java

License:sencha.com license

@Override
public void render(SafeHtmlBuilder sb, String value, FieldAppearanceOptions options) {
    int width = options.getWidth();
    boolean hideTrigger = options.isHideTrigger();

    if (width == -1) {
        width = 150;/*from w ww  . jav  a 2s  . co  m*/
    }

    SafeStylesBuilder inputStylesBuilder = new SafeStylesBuilder();
    inputStylesBuilder.appendTrustedString("width:100%;");

    // outer div needed for widgets like comboBox that need the full width to set for listview width
    sb.appendHtmlConstant("<div style='width:" + width + "px;'>");

    if (hideTrigger) {
        sb.appendHtmlConstant("<div class='" + style.wrap() + "'>");
        renderInput(sb, value, inputStylesBuilder.toSafeStyles(), options);
    } else {
        FieldDetails fieldDetails = getResources().theme().field();
        int rightPadding = fieldDetails.padding().right();
        sb.appendHtmlConstant("<div class='" + style.wrap() + "' style='padding-right:"
                + (getResources().triggerArrow().getWidth() + rightPadding) + "px;'>");
        renderInput(sb, value, inputStylesBuilder.toSafeStyles(), options);

        int fieldHeight = fieldDetails.height();
        int right = fieldDetails.borderWidth() + 1;

        StringBuilder triggerStyleSB = new StringBuilder();
        // default height to the height of the input element for both desktop and touch
        triggerStyleSB.append("height:").append(fieldHeight).append("px;");
        // default right position for both desktop and touch
        triggerStyleSB.append("right:").append(right).append("px;");
        /*
         * The height/width of the trigger is generated based off the dimensions of the image, which can negatively impact
         * user experience on touch devices. For touch devices, we're going to use the height of the input element to create
         * a large square around the trigger.
         */
        if (GXT.isTouch()) {
            // default width to height of input element to give touch users some extra width to work with
            triggerStyleSB.append("width:").append(fieldHeight).append("px;");
            // now that we've widened the trigger field, need to apply a margin so that it's positioned correctly
            int deltaWidth = fieldHeight - getResources().triggerArrow().getWidth();
            int rightMargin = -1 * (deltaWidth / 2);
            triggerStyleSB.append("margin-right:").append(rightMargin).append("px;");
        }
        SafeStyles triggerStyle = SafeStylesUtils.fromTrustedString(triggerStyleSB.toString());
        sb.appendHtmlConstant(
                "<div class='" + getStyle().trigger() + "' style='" + triggerStyle.asString() + "'></div>");
    }

    sb.appendHtmlConstant("</div></div>");
}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.button.Css3ButtonCellAppearance.java

License:sencha.com license

@Override
public void render(ButtonCell<M> cell, Context context, M value, SafeHtmlBuilder sb) {
    String constantHtml = cell.getHTML();
    boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0;
    boolean isBoolean = value != null && value instanceof Boolean;
    // is a boolean always a toggle button?
    String text = hasConstantHtml ? cell.getText()
            : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : "";

    ImageResource icon = cell.getIcon();
    IconAlign iconAlign = cell.getIconAlign();

    String arrowClass = "";
    String scaleClass = "";
    String iconClass = "";

    int width = cell.getWidth();
    int height = cell.getHeight();
    boolean hasIcon = cell.getIcon() != null;
    boolean isSplitButton = cell instanceof SplitButtonCell;
    boolean hasMenu = cell.getMenu() != null;

    boolean hasWidth = width != -1;

    if (cell.getMenu() != null) {

        if (cell instanceof SplitButtonCell) {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowClass = style.split();
                break;
            case BOTTOM:
                arrowClass = style.splitBottom();
                break;
            }//from w ww.java  2s.c  o m

        } else {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowClass = style.arrow();
                break;
            case BOTTOM:
                arrowClass = style.arrowBottom();
                break;
            }
        }

    }

    ButtonScale scale = cell.getScale();

    switch (scale) {
    case SMALL:
        scaleClass = style.small();
        break;

    case MEDIUM:
        scaleClass = style.medium();
        break;

    case LARGE:
        scaleClass = style.large();
        break;
    }

    if (icon != null) {
        switch (iconAlign) {
        case TOP:
            iconClass = style.iconTop();
            break;
        case BOTTOM:
            iconClass = style.iconBottom();
            break;
        case LEFT:
            iconClass = style.iconLeft();
            break;
        case RIGHT:
            iconClass = style.iconRight();
            break;
        }
    }

    String buttonClass = style.button();
    boolean hasText = text != null && !text.equals("");
    if (!hasText) {
        buttonClass += " " + style.noText();
    }

    // toggle button
    if (value == Boolean.TRUE) {
        buttonClass += " " + style.pressed();
    }

    String innerClass = style.buttonInner() + " " + iconClass;

    innerClass += " " + arrowClass;
    innerClass += " " + scaleClass;

    SafeHtmlBuilder builder = new SafeHtmlBuilder();

    SafeStylesBuilder ss = new SafeStylesBuilder();

    if (height != -1) {
        ButtonDetails bd = resources.theme().button();
        EdgeDetails padding = bd.padding();
        EdgeDetails paddingInner = bd.radiusMinusBorderWidth();
        int ah = height;
        ah -= padding.top();
        ah -= padding.bottom();
        ah -= paddingInner.top();
        ah -= paddingInner.bottom();

        ss.appendTrustedString("line-height: " + ah + "px;");
    }

    builder.appendHtmlConstant("<div class='" + buttonClass + "'>");

    // get iconbuilder ready
    SafeHtmlBuilder iconBuilder = new SafeHtmlBuilder();
    if (icon != null) {
        int iconWidth = icon != null ? icon.getWidth() : 0;
        int iconHeight = icon != null ? icon.getHeight() : 0;
        String styles = "width: " + iconWidth + "px; height: " + iconHeight + "px;";

        iconBuilder.appendHtmlConstant("<div class='" + iconClass + "' style='" + styles + "'>");
        iconBuilder.append(AbstractImagePrototype.create(icon).getSafeHtml());
        iconBuilder.appendHtmlConstant("</div>");
    }

    // for left / right aligned icons with a fixed button width we render the icon outside of the inner div
    if (hasWidth && hasIcon && iconAlign == IconAlign.LEFT) {
        builder.append(iconBuilder.toSafeHtml());
    }

    if (hasWidth && hasIcon && (iconAlign == IconAlign.LEFT)) {
        int tw = width - (resources.theme().button().borderRadius() * 2);
        if (isSplitButton && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) {
            tw -= resources.split().getWidth() + 10;
        }

        if (!isSplitButton && iconAlign == IconAlign.LEFT && hasMenu
                && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) {
            tw -= resources.arrow().getWidth() + 10;
        }

        if (hasIcon && iconAlign == IconAlign.LEFT) {
            tw -= icon.getWidth();
        }

        ss.appendTrustedString("width: " + tw + "px;");
    }

    builder.appendHtmlConstant("<div class='" + innerClass + "' style='" + ss.toSafeStyles().asString() + "'>");

    if (icon != null) {
        if ((!hasWidth && iconAlign == IconAlign.LEFT) || iconAlign == IconAlign.TOP) {
            builder.append(iconBuilder.toSafeHtml());
        }
        builder.appendHtmlConstant(text);
        if (iconAlign == IconAlign.RIGHT || iconAlign == IconAlign.BOTTOM) {
            builder.append(iconBuilder.toSafeHtml());
        }
    } else {
        builder.appendHtmlConstant(text);
    }

    builder.appendHtmlConstant("</div></div>");
    sb.append(builder.toSafeHtml());
}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.field.Css3TriggerFieldAppearance.java

License:sencha.com license

@Override
public void render(SafeHtmlBuilder sb, String value, FieldAppearanceOptions options) {
    int width = options.getWidth();
    boolean hideTrigger = options.isHideTrigger();

    if (width == -1) {
        width = 150;/*w ww  .ja v  a  2s  .  c om*/
    }

    SafeStylesBuilder inputStylesBuilder = new SafeStylesBuilder();
    inputStylesBuilder.appendTrustedString("width:100%;");

    // outer div needed for widgets like comboBox that need the full width to set for listview width
    sb.appendHtmlConstant("<div style='width:" + width + "px;'>");

    if (hideTrigger) {
        sb.appendHtmlConstant("<div class='" + style.wrap() + "'>");
        renderInput(sb, value, inputStylesBuilder.toSafeStyles(), options);
    } else {
        FieldDetails fieldDetails = getResources().theme().field();

        int rightPadding = fieldDetails.padding().right();
        sb.appendHtmlConstant("<div class='" + style.wrap() + "' style='padding-right:"
                + (getResources().triggerArrow().getWidth() + rightPadding) + "px;'>");
        renderInput(sb, value, inputStylesBuilder.toSafeStyles(), options);

        int right = fieldDetails.borderWidth() + 1;
        int halfHeight = getResources().triggerArrow().getHeight() / 2;
        SafeStyles triggerStyle = SafeStylesUtils
                .fromTrustedString("margin-top:-" + halfHeight + "px;right:" + right + "px;");
        sb.appendHtmlConstant(
                "<div class='" + getStyle().trigger() + "' style='" + triggerStyle.asString() + "'></div>");
    }

    sb.appendHtmlConstant("</div></div>");
}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.field.Css3TwinTriggerFieldAppearance.java

License:sencha.com license

@Override
public void render(SafeHtmlBuilder sb, String value, FieldAppearanceOptions options) {
    int width = options.getWidth();
    boolean hideTrigger = options.isHideTrigger();

    if (width == -1) {
        width = 150;//  w  w  w  .  ja  va 2  s  . c  o m
    }

    SafeStylesBuilder inputStylesBuilder = new SafeStylesBuilder();
    inputStylesBuilder.appendTrustedString("width:100%;");

    sb.appendHtmlConstant("<div style='width:" + width + "px;'>");

    if (hideTrigger) {
        sb.appendHtmlConstant("<div class='" + style.wrap() + "'>");
        renderInput(sb, value, inputStylesBuilder.toSafeStyles(), options);
    } else {
        FieldDetails fieldDetails = getResources().theme().field();

        int rightPadding = fieldDetails.padding().right();
        sb.appendHtmlConstant("<div class='" + style.wrap() + "' style='padding-right:"
                + (getResources().triggerArrow().getWidth() + rightPadding) + "px;'>");
        renderInput(sb, value, inputStylesBuilder.toSafeStyles(), options);

        int triggerWrapTopMargin = -(getTriggerWrapHeight() / 2);

        sb.appendHtmlConstant("<div class='" + getStyle().triggerWrap() + "' style='margin-top:"
                + triggerWrapTopMargin + "px;'>");
        sb.appendHtmlConstant("<div class='" + getStyle().trigger() + "'></div>");
        sb.appendHtmlConstant("<div class='" + getStyle().twinTrigger() + "'></div>");
        sb.appendHtmlConstant("</div>");
    }

    sb.appendHtmlConstant("</div></div>");
}