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

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

Introduction

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

Prototype

public SafeStylesBuilder() 

Source Link

Document

Constructs an empty SafeStylesBuilder .

Usage

From source file:com.arcbees.chosen.client.ChosenImpl.java

License:Apache License

private void setup() {
    boolean isHidden = false;
    containerId = buildContainerId();/*from w ww. j  av  a2s  . c  om*/
    fWidth = $selectElement.outerWidth();

    isRTL = LocaleInfo.getCurrentLocale().isRTL() || $selectElement.hasClass("chzn-rtl");
    // Temporary fix. IIf the select element is inside a hidden container
    // GQuery cannot get the size of the select element.
    if (fWidth == 0) {
        $("body").append("<div id='gwt_chosen_temp_div' style='display:block;position:absolute;"
                + (isRTL ? "right" : "left") + ":-9000px; visibility:hidden'> </div>");
        GQuery tempDiv = $("#gwt_chosen_temp_div");
        tempDiv.append($selectElement.clone());

        fWidth = tempDiv.children("select").outerWidth();

        tempDiv.remove();
        isHidden = fWidth > 0;
    }

    String containerClass = getContainerClass();

    String cssClasses = isRTL ? containerClass + " " + css.chznRtl() : containerClass;

    // recopy classes present on the select element
    cssClasses += " " + selectElement.getClassName();

    GQuery containerTemp = $(ChosenTemplate.templates.container(containerId, cssClasses).asString())
            .width(fWidth);

    final SafeStylesBuilder ssb = new SafeStylesBuilder();
    if (isRTL) {
        ssb.right(HORIZONTAL_OFFSET, Style.Unit.PX);
    } else {
        ssb.left(HORIZONTAL_OFFSET, Style.Unit.PX);
    }
    ssb.top(VERTICAL_OFFSET, Style.Unit.PX);

    containerTemp.html(buildContainerHtml(defaultText, ssb).asString());

    // insert container after the select elements
    $selectElement.hide().after(containerTemp);
    container = $("#" + containerId);
    container.addClass(isMultiple() ? css.chznContainerMulti() : css.chznContainerSingle());

    dropdown = container.find("div." + css.chznDrop()).first();
    int ddWidth = fWidth - getSideBorderPadding(dropdown, isHidden);

    dropdown.css("width", buildDropdownWidth(ddWidth));

    searchField = container.find("input").first();
    searchResults = container.find("ul." + css.chznResults()).first();
    searchFieldScale(fWidth);

    initSearchElement(ddWidth, isHidden);

    resultsBuild(true);

    setTabIndex();

    fireEvent(new ReadyEvent(this));
}

From source file:com.bearsoft.gwt.ui.widgets.grid.cells.RenderedEditorCell.java

@Override
public void render(final Context context, final T value, SafeHtmlBuilder sb) {
    CellsResources.INSTANCE.tablecell().ensureInjected();
    String viewDataId = "";
    if (isEditing(context, null, value)) {
        final ViewData<T> viewData = getViewData(context.getKey());
        viewDataId = viewData.id;//from   www  . j  av a2s  . c o  m
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                if (isEditing(context, null, value)) {
                    Element parent = Document.get().getElementById(viewData.id);
                    if (parent != null) {
                        parent.blur();
                        Element table = parent;
                        while (table != null && !"table".equalsIgnoreCase(table.getTagName())) {
                            table = table.getParentElement();
                        }
                        final Element table1 = table;
                        if (parent.getOwnerDocument() == Document.get()) {
                            startEditing(context, parent, table1.getParentElement(), value, viewData.updater,
                                    new Runnable() {

                                        public void run() {
                                            if (onEditorClose != null && table1 != null) {
                                                onEditorClose.closed(table1);
                                            }
                                        }

                                    });
                        }
                    }
                }
            }

        });
    }
    if (renderer == null || !renderer.render(context, viewDataId, value, sb)) {
        SafeHtmlBuilder content = new SafeHtmlBuilder();
        renderCell(context, value, content);
        sb.append(PaddedCell.INSTANCE.generate(viewDataId, CellsResources.INSTANCE.tablecell().padded(),
                new SafeStylesBuilder().padding(CELL_PADDING, Style.Unit.PX).toSafeStyles(),
                content.toSafeHtml()));
    }
}

From source file:com.bearsoft.gwt.ui.widgets.grid.cells.TreeExpandableCell.java

@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
    if (treeProvider != null) {
        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        cell.render(context, value, cellBuilder);
        int deepness = getDeepness(context);
        int outerDivPadding = indent * (deepness + 1);
        SafeStyles styles = new SafeStylesBuilder()
                .trustedNameAndValue("background-position", indent * deepness, Style.Unit.PX)
                .paddingLeft(outerDivPadding, Style.Unit.PX).position(Style.Position.RELATIVE)
                .height(100, Style.Unit.PCT).toSafeStyles();
        sb.append(template.outerDiv(outerDivClasses(context), styles, cellBuilder.toSafeHtml()));
    } else {//w w  w  . j  a v a2s  .  co m
        cell.render(context, value, sb);
    }
}

From source file:com.eas.grid.cells.RenderedEditorCell.java

@Override
public void render(final Context context, final T value, SafeHtmlBuilder sb) {
    String viewDataId = "";
    if (isEditing(context, null, value)) {
        final ViewData<T> viewData = getViewData(context.getKey());
        viewDataId = viewData.id;/*from   ww w  .  j  av a 2s  . c o m*/
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {

            @Override
            public void execute() {
                if (isEditing(context, null, value)) {
                    Element identifiedCellTextSection = Document.get().getElementById(viewData.id);
                    if (identifiedCellTextSection != null) {
                        identifiedCellTextSection.blur();
                        Element table = identifiedCellTextSection;
                        while (table != null && !"table".equalsIgnoreCase(table.getTagName())) {
                            table = table.getParentElement();
                        }
                        final Element table1 = table;
                        if (identifiedCellTextSection.getOwnerDocument() == Document.get()) {
                            startEditing(context, identifiedCellTextSection.getParentElement(),
                                    table1.getParentElement(), value, viewData.updater, new Runnable() {

                                        public void run() {
                                            if (onEditorClose != null && table1 != null) {
                                                onEditorClose.closed(table1);
                                            }
                                        }

                                    });
                        }
                    }
                }
            }

        });
    }
    if (renderer == null || !renderer.render(context, viewDataId, value, sb)) {
        SafeHtmlBuilder content = new SafeHtmlBuilder();
        renderCell(context, value, content);
        sb.append(PaddedCell.INSTANCE.generate(new SafeStylesBuilder().toSafeStyles(), viewDataId,
                content.toSafeHtml()));
    }
}

From source file:com.eas.grid.cells.TreeExpandableCell.java

@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
    if (treeProvider != null) {
        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        cell.render(context, value, cellBuilder);
        int deepness = getDeepness(context);
        int outerDivPadding = indent * deepness;
        SafeStylesBuilder styles = new SafeStylesBuilder();
        if (deepness > 0) {
            styles.paddingLeft(outerDivPadding, Style.Unit.PX);
        }//from   ww  w . jav a  2  s. c  o m
        styles.position(Style.Position.RELATIVE).height(100, Style.Unit.PCT).toSafeStyles();
        sb.append(template.outerDiv(outerDivClasses(context), styles.toSafeStyles(), cellBuilder.toSafeHtml()));
    } else {
        cell.render(context, value, sb);
    }
}

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  v  a2  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  www . j  a v  a 2s  .  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 .  ja v  a  2 s . co m
    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.button.ButtonCellDefaultAppearance.java

License:sencha.com license

protected void writeValue(SafeHtmlBuilder builder, SafeHtml value, int width, int height) {
    SafeStylesBuilder sb = new SafeStylesBuilder();
    if (height > 0) {
        int adjustedHeight = height - heightOffset;
        sb.append(SafeStylesUtils.fromTrustedString("height:" + adjustedHeight + "px;"));
    }//from   www.j  a v  a2 s . co m
    if (width > 0) {
        sb.append(SafeStylesUtils.fromTrustedString("width:" + width + "px;"));
    }
    builder.append(templates.textWithStyles(style.text(), sb.toSafeStyles(), value));
}

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;/*w  w w .j a va2  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));
}