Example usage for com.google.gwt.safecss.shared SafeStyles asString

List of usage examples for com.google.gwt.safecss.shared SafeStyles asString

Introduction

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

Prototype

String asString();

Source Link

Document

Returns this object's contained CSS as a string.

Usage

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

License:sencha.com license

/**
 * Helper method to render the input in the trigger field.
 *//*from w  w  w .  ja  v  a  2 s . c  om*/
protected void renderInput(SafeHtmlBuilder shb, String value, SafeStyles inputStyles,
        FieldAppearanceOptions options) {
    // Deliberately using a StringBuilder, not SafeHtmlBuilder, as each append isn't adding
    // complete elements, but building up this single element, one attribute at a time.
    StringBuilder sb = new StringBuilder();
    sb.append("<input ");

    if (options.isDisabled()) {
        sb.append("disabled=true ");
    }

    if (options.getName() != null) {
        // if set, escape the name property so it is a valid attribute
        sb.append("name='").append(SafeHtmlUtils.htmlEscape(options.getName())).append("' ");
    }

    if (options.isReadonly() || !options.isEditable()) {
        sb.append("readonly ");
    }

    if (inputStyles != null) {
        sb.append("style='").append(inputStyles.asString()).append("' ");
    }

    sb.append("class='").append(getStyle().field()).append(" ").append(getStyle().text());

    String placeholder = options.getEmptyText() != null
            ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' "
            : "";

    if (value.equals("") && options.getEmptyText() != null) {
        sb.append(" ").append(getStyle().empty());
        if (GXT.isIE8() || GXT.isIE9()) {
            value = options.getEmptyText();
        }
    }

    if (!options.isEditable()) {
        sb.append(" ").append(getStyle().noedit());
    }
    sb.append("' ");
    sb.append(placeholder);

    //escaping the value string so it is a valid attribute
    sb.append("type='text' value='").append(SafeHtmlUtils.htmlEscape(value)).append("'/>");

    // finally, converting stringbuilder into a SafeHtml instance and appending it
    // to the buidler we were given
    shb.append(SafeHtmlUtils.fromTrustedString(sb.toString()));
}

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  w w .ja v  a  2 s  .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 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:com.tmc.client.ui.field.LookupFieldAppearance.java

License:sencha.com license

protected void renderInput(SafeHtmlBuilder shb, String value, SafeStyles inputStyles,
        FieldAppearanceOptions options) {
    StringBuilder sb = new StringBuilder();
    sb.append("<input ");

    if (options.isDisabled()) {
        sb.append("disabled=true ");
    }/* w  w w  .ja v  a 2 s  . c o  m*/

    if (options.getName() != null) {
        sb.append("name='").append(SafeHtmlUtils.htmlEscape(options.getName())).append("' ");
    }

    if (options.isReadonly() || !options.isEditable()) {
        sb.append("readonly ");
    }

    if (inputStyles != null) {
        sb.append("style='").append(inputStyles.asString()).append("' ");
    }

    sb.append("class='").append(getStyle().field()).append(" ").append(getStyle().text());

    String placeholder = options.getEmptyText() != null
            ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' "
            : "";

    if ("".equals(value) && options.getEmptyText() != null) {
        sb.append(" ").append(getStyle().empty());
        if (GXT.isIE8() || GXT.isIE9()) {
            value = options.getEmptyText();
        }
    }

    if (!options.isEditable()) {
        sb.append(" ").append(getStyle().noedit());
    }

    sb.append("' ");
    sb.append(placeholder);

    sb.append("type='text' value='").append(SafeHtmlUtils.htmlEscape(value)).append("' ");

    sb.append("/>");

    shb.append(SafeHtmlUtils.fromTrustedString(sb.toString()));
}

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  w w .  j  ava  2s.c o 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 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.Css3TriggerFieldAppearance.java

License:sencha.com license

protected void renderInput(SafeHtmlBuilder shb, String value, SafeStyles inputStyles,
        FieldAppearanceOptions options) {
    StringBuilder sb = new StringBuilder();
    sb.append("<input ");

    if (options.isDisabled()) {
        sb.append("disabled=true");
    }/*w  w w .  j  a  v  a2  s .  c  om*/

    if (options.getName() != null) {
        sb.append("name='").append(SafeHtmlUtils.htmlEscape(options.getName())).append("' ");
    }

    if (options.isReadonly() || !options.isEditable()) {
        sb.append("readonly ");
    }

    if (inputStyles != null) {
        sb.append("style='").append(inputStyles.asString()).append("' ");
    }

    sb.append("class='").append(getStyle().field()).append(" ").append(getStyle().text());

    String placeholder = options.getEmptyText() != null
            ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' "
            : "";

    if ("".equals(value) && options.getEmptyText() != null) {
        sb.append(" ").append(getStyle().empty());
        if (GXT.isIE8() || GXT.isIE9()) {
            value = options.getEmptyText();
        }
    }

    if (!options.isEditable()) {
        sb.append(" ").append(getStyle().noedit());
    }

    sb.append("' ");
    sb.append(placeholder);

    sb.append("type='text' value='").append(SafeHtmlUtils.htmlEscape(value)).append("' ");

    sb.append("/>");

    shb.append(SafeHtmlUtils.fromTrustedString(sb.toString()));
}

From source file:org.appverse.web.framework.frontend.gwt.theme.bluetouch.client.field.AppverseWebTriggerFieldAppearance.java

License:sencha.com license

/**
 * Helper method to render the input in the trigger field. 
 *///  ww w  .  j a  v  a2s. c  o  m
private void renderInput(SafeHtmlBuilder shb, String value, SafeStyles inputStyles,
        FieldAppearanceOptions options) {
    // Deliberately using a StringBuilder, not SafeHtmlBuilder, as each append isn't adding
    // complete elements, but building up this single element, one attribute at a time.
    StringBuilder sb = new StringBuilder();
    sb.append("<input ");

    if (options.isDisabled()) {
        sb.append("disabled=true ");
    }

    if (options.getName() != null) {
        // if set, escape the name property so it is a valid attribute
        sb.append("name='").append(SafeHtmlUtils.htmlEscape(options.getName())).append("' ");
    }

    if (options.isReadonly() || !options.isEditable()) {
        sb.append("readonly ");
    }

    if (inputStyles != null) {
        sb.append("style='").append(inputStyles.asString()).append("' ");
    }

    sb.append("class='").append(style.field()).append(" ").append(style.text());

    if (value.equals("") && options.getEmptyText() != null) {
        sb.append(" ").append(style.empty());
        value = options.getEmptyText();
    }

    if (!options.isEditable()) {
        sb.append(" ").append(style.noedit());
    }
    sb.append("' ");

    //escaping the value string so it is a valid attribute
    sb.append("type='text' value='").append(SafeHtmlUtils.htmlEscape(value)).append("'/>");

    // finally, converting stringbuilder into a SafeHtml instance and appending it
    // to the buidler we were given
    shb.append(SafeHtmlUtils.fromTrustedString(sb.toString()));
}