Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml.

Prototype

public SafeHtml toSafeHtml() 

Source Link

Document

Returns the safe HTML accumulated in the builder as a SafeHtml .

Usage

From source file:com.sencha.gxt.widget.core.client.form.FileUploadField.java

License:sencha.com license

/**
 * Creates a new file upload field.//from w w  w . java  2 s .  c  om
 * 
 * @param appearance the appearance
 */
public FileUploadField(FileUploadFieldAppearance appearance) {
    this.appearance = appearance;

    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    this.appearance.render(builder);

    setElement((Element) XDOM.create(builder.toSafeHtml()));

    input = new TextField();
    input.setReadOnly(true);
    input.setTabIndex(-1);
    getElement().appendChild(input.getElement());

    sinkEvents(Event.ONCHANGE | Event.ONCLICK | Event.MOUSEEVENTS | Event.KEYEVENTS);

    createFileInput();

    button = new TextButton(getMessages().browserText());
    DivElement wrapper = Document.get().createDivElement();
    wrapper.addClassName(appearance.buttonClass());
    XElement buttonElement = button.getElement();
    if (GXT.isIE8()) {
        buttonElement.removeClassName(CommonStyles.get().inlineBlock());
    }
    wrapper.appendChild(buttonElement);
    getElement().appendChild(wrapper);

    ensureVisibilityOnSizing = true;
    setWidth(150);

    addGestureRecognizer(new TapGestureRecognizer() {
        @Override
        protected void onTap(TouchData touchData) {
            super.onTap(touchData);
            FileUploadField.this.onTap(touchData);
        }
    });
}

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

License:sencha.com license

protected SafeHtml doRender() {
    int colCount = cm.getColumnCount();

    // root builder
    SafeHtmlBuilder buf = new SafeHtmlBuilder();

    int rows = cm.getAggregationRows().size();

    String cellInner = styles.cellInner() + " " + gridView.getStateStyles().cellInner();

    SafeStyles empty = XDOM.EMPTY_SAFE_STYLE;

    for (int j = 0; j < rows; j++) {
        AggregationRowConfig<M> config = cm.getAggregationRow(j);

        SafeHtmlBuilder trBuilder = new SafeHtmlBuilder();

        // loop each cell per row
        for (int i = 0; i < colCount; i++) {
            String cellClass = styles.cell() + " " + gridView.getStateStyles().cell();
            String cs = config.getCellStyle(cm.getColumn(i));
            if (cs != null) {
                cellClass += " " + cs;
            }/*  w ww. ja  va2s  .c  o m*/
            HorizontalAlignmentConstant align = cm.getColumnHorizontalAlignment(i);
            SafeStyles s = empty;
            if (align != null) {
                s = SafeStylesUtils.fromTrustedString("text-align:" + align.getTextAlignString() + ";");
            }
            trBuilder.append(tpls.td(i, cellClass, empty, cellInner, s, getRenderedValue(j, i)));
        }
        buf.append(tpls.tr("", trBuilder.toSafeHtml()));
    }

    return buf.toSafeHtml();
}

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

License:sencha.com license

/**
 * Creates a new column header./*from w w w  . j  a  v a2s . c  o m*/
 *
 * @param container the containing widget
 * @param cm the column model
 * @param appearance the column header appearance
 */
public ColumnHeader(Grid<M> container, ColumnModel<M> cm, ColumnHeaderAppearance appearance) {
    this.container = container;
    this.cm = cm;
    this.appearance = appearance;
    rightAlignOffset = 2 + getAppearance().getColumnMenuWidth();
    setAllowTextSelection(false);

    styles = appearance.styles();

    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    this.appearance.render(builder);

    setElement((Element) XDOM.create(builder.toSafeHtml()));

    table.setCellPadding(0);
    table.setCellSpacing(0);

    table.getElement().getStyle().setTableLayout(TableLayout.FIXED);

    getElement().selectNode(appearance.columnsWrapSelector()).appendChild(table.getElement());

    quickTip = new QuickTip(this);
}

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   w ww .  ja  va 2 s  .c o  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.editing.GridInlineEditing.java

License:sencha.com license

@Override
protected SafeHtml getErrorHtml() {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    sb.appendHtmlConstant("<ul>");
    ColumnConfig<M, ?> c = columnModel.getColumn(activeCell.getCol());
    IsField<?> f = getEditor(c);// ww  w.  jav a  2 s.  co  m

    getErrorMessage(f, sb, c.getHeader());

    sb.appendHtmlConstant("</ul>");
    return sb.toSafeHtml();
}

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

License:sencha.com license

@Override
protected SafeHtml getErrorHtml() {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    sb.appendHtmlConstant("<ul>");

    ColumnModel<M> cm = getEditableGrid().getColumnModel();

    for (int i = 0; i < cm.getColumnCount(); i++) {
        ColumnConfig<M, ?> columnConfig = cm.getColumn(i);

        IsField<?> f = (IsField<?>) getEditor(columnConfig);
        ;/* w w w . j av a2  s .  co  m*/

        if (f == null) {
            continue;
        }

        getErrorMessage(f, sb, columnConfig.getHeader());
    }

    sb.appendHtmlConstant("</ul>");
    return sb.toSafeHtml();
}

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

License:sencha.com license

/**
 * Creates a new grid with the given data store and column model.
 * /*from w  ww .j a v  a  2 s  .com*/
 * @param store the data store
 * @param cm the column model
 */
@UiConstructor
public Grid(ListStore<M> store, ColumnModel<M> cm, GridView<M> view) {
    this.store = store;
    this.cm = cm;
    this.view = view;
    this.view.grid = this;
    this.view.ds = store;

    disabledStyle = null;
    setSelectionModel(new GridSelectionModel<M>());

    setAllowTextSelection(false);

    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    view.getAppearance().render(builder);

    setElement((Element) XDOM.create(builder.toSafeHtml()));
    getElement().makePositionable();
    getElement().setTabIndex(0);

    sinkCellEvents();

    // use either long press or tap to select
    addGestureRecognizer(new LongPressOrTapGestureRecognizer() {
        @Override
        protected void onLongPress(TouchData touchData) {
            Event event = touchData.getLastNativeEvent().cast();
            onMouseDown(event);
            super.onLongPress(touchData);
        }

        @Override
        protected void onTap(TouchData touchData) {
            Event event = touchData.getLastNativeEvent().cast();
            onMouseDown(event);
            onClick(event);
            // need to make sure to call view's mouse methods as well
            // view can be set post-construction - make sure to use Grid's member variable rather than the constructor param
            GridView<M> view = Grid.this.view;
            if (view != null) {
                // since we're not preventingDefault, no reason to call view.onMouseDown
                view.onClick(event);
            }
            super.onTap(touchData);
        }

        @Override
        protected void handlePreventDefault(NativeEvent event) {
            // don't call preventDefault here
        }
    });
}

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

License:sencha.com license

/**
 * Renders the grid view into safe HTML.
 *
 * @param cs the column attributes required for rendering
 * @param rows the data models for the rows to be rendered
 * @param startRow the index of the first row in <code>rows</code>
 *//*from  w  w  w  .  j a va  2 s  .  c  om*/
protected SafeHtml doRender(List<ColumnData> cs, List<M> rows, int startRow) {
    final int colCount = cm.getColumnCount();
    final int last = colCount - 1;

    int[] columnWidths = getColumnWidths();

    // root builder
    SafeHtmlBuilder buf = new SafeHtmlBuilder();

    final SafeStyles rowStyles = SafeStylesUtils.fromTrustedString("width: " + getTotalWidth() + "px;");

    final String unselectableClass = unselectable;
    final String rowAltClass = styles.rowAlt();
    final String rowDirtyClass = styles.rowDirty();

    final String cellClass = styles.cell() + " " + states.cell();
    final String cellInnerClass = styles.cellInner() + " " + states.cellInner();
    final String cellFirstClass = "x-grid-cell-first";
    final String cellLastClass = "x-grid-cell-last";
    final String cellDirty = styles.cellDirty();

    final String rowWrap = styles.rowWrap() + " " + states.rowWrap();
    final String rowBody = styles.rowBody() + " " + states.rowBody();
    final String rowBodyRow = states.rowBodyRow();

    // loop over all rows
    for (int j = 0; j < rows.size(); j++) {
        M model = rows.get(j);

        ListStore<M>.Record r = ds.hasRecord(model) ? ds.getRecord(model) : null;

        int rowBodyColSpanCount = colCount;
        if (enableRowBody) {
            for (ColumnConfig<M, ?> c : cm.getColumns()) {
                if (c instanceof RowExpander) {
                    rowBodyColSpanCount--;
                }
            }
        }

        int rowIndex = (j + startRow);

        String rowClasses = styles.row() + " " + states.row();

        if (!selectable) {
            rowClasses += " " + unselectableClass;
        }
        if (isStripeRows() && ((rowIndex + 1) % 2 == 0)) {
            rowClasses += " " + rowAltClass;
        }

        if (showDirtyCells && r != null && r.isDirty()) {
            rowClasses += " " + rowDirtyClass;
        }

        if (viewConfig != null) {
            rowClasses += " " + viewConfig.getRowStyle(model, rowIndex);
        }

        SafeHtmlBuilder trBuilder = new SafeHtmlBuilder();

        // loop each cell per row
        for (int i = 0; i < colCount; i++) {
            SafeHtml rv = getRenderedValue(rowIndex, i, model, r);
            ColumnConfig<M, ?> columnConfig = cm.getColumn(i);
            ColumnData columnData = cs.get(i);

            String cellClasses = cellClass;
            if (i == 0) {
                cellClasses += " " + cellFirstClass;
            } else if (i == last) {
                cellClasses += " " + cellLastClass;
            }

            String cellInnerClasses = cellInnerClass;
            if (columnConfig.getColumnTextClassName() != null) {
                cellInnerClasses += " " + columnConfig.getColumnTextClassName();
            }
            if (!columnConfig.isCellPadding()) {
                cellInnerClasses += " " + styles.noPadding();
            }

            if (columnData.getClassNames() != null) {
                cellClasses += " " + columnData.getClassNames();
            }

            if (columnConfig.getCellClassName() != null) {
                cellClasses += " " + columnConfig.getCellClassName();
            }

            if (showDirtyCells && r != null && r.getChange(columnConfig.getValueProvider()) != null) {
                cellClasses += " " + cellDirty;
            }

            if (viewConfig != null) {
                cellClasses += " " + viewConfig.getColStyle(model, cm.getValueProvider(i), rowIndex, i);
            }

            final SafeStyles cellStyles = columnData.getStyles();

            final SafeHtml tdContent;
            if (enableRowBody && i == 0) {
                tdContent = tpls.tdRowSpan(i, cellClasses, cellStyles, rowBodyRowSpan, cellInnerClasses, rv);
            } else {
                if (!selectable && GXT.isIE()) {
                    tdContent = tpls.tdUnselectable(i, cellClasses, cellStyles, cellInnerClasses,
                            columnConfig.getColumnTextStyle(), rv);
                } else {
                    tdContent = tpls.td(i, cellClasses, cellStyles, cellInnerClasses,
                            columnConfig.getColumnTextStyle(), rv);
                }

            }
            trBuilder.append(tdContent);
        }

        if (enableRowBody) {
            String cls = styles.dataTable() + " x-grid-resizer";

            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            sb.append(tpls.tr("", trBuilder.toSafeHtml()));
            sb.appendHtmlConstant("<tr class='" + rowBodyRow + "'><td colspan=" + rowBodyColSpanCount
                    + "><div class='" + rowBody + "'></div></td></tr>");

            SafeHtml tdWrap = null;
            if (!selectable && GXT.isIE()) {
                tdWrap = tpls.tdWrapUnselectable(colCount, "", rowWrap,
                        tpls.table(cls, rowStyles, sb.toSafeHtml(), renderHiddenHeaders(columnWidths)));
            } else {
                tdWrap = tpls.tdWrap(colCount, "", rowWrap,
                        tpls.table(cls, rowStyles, sb.toSafeHtml(), renderHiddenHeaders(columnWidths)));
            }
            buf.append(tpls.tr(rowClasses, tdWrap));

        } else {
            buf.append(tpls.tr(rowClasses, trBuilder.toSafeHtml()));
        }

    }
    // end row loop
    return buf.toSafeHtml();

}

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

License:sencha.com license

/**
 * Renders the value of a cell into safe HTML.
 *
 * @param rowIndex the row index//from   w  w  w.  ja  va2s .c  om
 * @param colIndex the column index
 * @param m the data model
 * @param record the optional {@link Record} for this row (may be null)
 * @return the safe HTML representing the cell
 */
protected <N> SafeHtml getRenderedValue(int rowIndex, int colIndex, M m, ListStore<M>.Record record) {
    ValueProvider<? super M, N> valueProvider = cm.getValueProvider(colIndex);
    N val = null;
    if (record != null) {
        val = record.getValue(valueProvider);
    } else {
        val = valueProvider.getValue(m);
    }
    Cell<N> r = cm.getCell(colIndex);
    if (r != null) {
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        r.render(new Context(rowIndex, colIndex, ds.getKeyProvider().getKey(m)), val, sb);
        return sb.toSafeHtml();
    }

    String text = null;
    if (val != null) {
        text = val.toString();
    }
    return Util.isEmptyString(text) ? Util.NBSP_SAFE_HTML : SafeHtmlUtils.fromString(text);
}

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
 *///from   ww w. ja v a  2s .c om
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());
}