List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder append
public SafeHtmlBuilder append(SafeHtml html)
From source file:com.sencha.gxt.widget.core.client.grid.editing.AbstractGridEditing.java
License:sencha.com license
protected void getErrorMessage(IsField<?> field, SafeHtmlBuilder sb, SafeHtml title) { boolean result = true; if (field instanceof ValueBaseField) { ValueBaseField<?> vfield = (ValueBaseField<?>) field; result = vfield.isCurrentValid(true); }/*from ww w . j av a 2 s. c o m*/ if (!result || !field.isValid(true)) { sb.appendHtmlConstant("<li><b>"); sb.append(title); sb.appendHtmlConstant("</b>: "); sb.appendEscaped(field.getErrors().get(0).getMessage()); sb.appendHtmlConstant("</li>"); } }
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> */// w ww. jav a2 s . com 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 hidden TH elements that keep the column widths. * * @param columnWidths the column widths * @return markup representing the hidden table header elements *//* www . j a va 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.sencha.gxt.widget.core.client.grid.GroupingView.java
License:sencha.com license
protected void renderGroup(SafeHtmlBuilder buf, GroupingData<M> g, SafeHtml renderedRows) { String groupClass = groupAppearance.style().group(); String bodyClass = ""; if (g.isCollapsed()) { groupClass += " " + groupAppearance.style().groupCollapsed(); bodyClass = groupAppearance.style().bodyCollapsed(); }//from w w w .j ava2 s . c om String headClass = groupAppearance.style().groupHead(); final SafeHtml groupHtml; String cellClasses = headClass + " " + styles.cell() + " " + states.cell(); if (selectable) { groupHtml = (tpls.tr(groupClass, tpls.tdWrap(cm.getColumnCount(), cellClasses, styles.cellInner() + " " + states.cellInner(), renderGroupHeader(g)))); } else { String innerCellClasses = styles.cellInner() + " " + states.cellInner() + " " + styles.noPadding(); if (GXT.isIE()) { groupHtml = (tpls.tr(groupClass, tpls.tdWrapUnselectable(cm.getColumnCount(), cellClasses, innerCellClasses, renderGroupHeader(g)))); } else { groupHtml = (tpls.tr(groupClass, tpls.tdWrap(cm.getColumnCount(), cellClasses, innerCellClasses, renderGroupHeader(g)))); } } buf.append(groupHtml); buf.append(tpls.tr(bodyClass, tpls.tdWrap(cm.getColumnCount(), "", "", renderedRows))); }
From source file:com.sencha.gxt.widget.core.client.grid.GroupSummaryView.java
License:sencha.com license
@Override protected void renderGroup(SafeHtmlBuilder buf, GroupingData<M> g, SafeHtml renderedRows) { super.renderGroup(buf, g, renderedRows); buf.append(renderGroupSummary(g)); }
From source file:com.sencha.gxt.widget.core.client.grid.GroupSummaryView.java
License:sencha.com license
protected SafeHtml renderSummary(GroupingData<M> groupInfo, Map<ValueProvider<? super M, ?>, Number> data) { int colCount = cm.getColumnCount(); int last = colCount - 1; String unselectableClass = " " + unselectable; String cellClass = styles.cell() + " " + states.cell(); String cellInner = styles.cellInner() + " " + states.cellInner(); String cellFirstClass = " x-grid-cell-first"; String cellLastClass = " x-grid-cell-last"; SafeHtmlBuilder trBuilder = new SafeHtmlBuilder(); for (int i = 0, len = colCount; i < len; i++) { SummaryColumnConfig<M, ?> cf = (SummaryColumnConfig<M, ?>) cm.getColumn(i); ColumnData cd = getColumnData().get(i); String cellClasses = cellClass; cellClasses += (i == 0 ? cellFirstClass : (i == last ? cellLastClass : "")); if (cf.getCellClassName() != null) { cellClasses += " " + cf.getCellClassName(); }//from w w w .j a v a 2s . c o m Number n = data.get(cm.getValueProvider(i)); SafeHtml value = SafeHtmlUtils.EMPTY_SAFE_HTML; if (cf.getSummaryFormat() != null) { if (n != null) { value = SafeHtmlUtils.fromString(cf.getSummaryFormat().format(n.doubleValue())); } } else if (cf.getSummaryRenderer() != null) { value = cf.getSummaryRenderer().render(n, data); } final SafeHtml tdContent; if (!selectable && GXT.isIE()) { tdContent = tpls.tdUnselectable(i, cellClasses, cd.getStyles(), cellInner, cf.getColumnTextStyle(), value); } else { tdContent = tpls.td(i, cellClasses, cd.getStyles(), cellInner, cf.getColumnTextStyle(), value); } trBuilder.append(tdContent); } String rowClasses = getGroupingAppearance().style().summaryRow(); if (!selectable) { rowClasses += unselectableClass; } SafeHtml cells = trBuilder.toSafeHtml(); return tpls.tr(rowClasses, cells); }
From source file:com.sencha.gxt.widget.core.client.ListView.java
License:sencha.com license
protected void bufferRender(List<M> models, SafeHtmlBuilder sb) { for (int i = 0, len = models.size(); i < len; i++) { M m = models.get(i);/* ww w. j a v a2 s. com*/ SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder(); N v = getValue(m); if (cell == null) { String text = null; if (v != null) { text = v.toString(); } cellBuilder.append(Util.isEmptyString(text) ? Util.NBSP_SAFE_HTML : SafeHtmlUtils.fromString(text)); } else { Context context = new Context(i, 0, store.getKeyProvider().getKey(m)); cell.render(context, v, cellBuilder); } appearance.renderItem(sb, cellBuilder.toSafeHtml()); } }
From source file:com.sencha.gxt.widget.core.client.ListView.java
License:sencha.com license
/** * Is called before a load when a {@link #setLoader(Loader) and {@link #setLoadingIndicator(SafeHtml) or * {@link #setLoadingIndicator(String)} are used the list will display the loading HTML. * <p/>/*from ww w . j ava 2 s .c om*/ * <ul> * <li>The {@link #setLoader(Loader)} has to be set for this to be called. * <li>The css class name 'loading-indicator' can style the loading HTML or text. * </ul> */ protected void onBeforeLoad() { if (loadingIndicator != SafeHtmlUtils.EMPTY_SAFE_HTML) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant("<div class='loading-indicator'>"); sb.append(loadingIndicator); sb.appendHtmlConstant("</div>"); getElement().setInnerSafeHtml(sb.toSafeHtml()); all.removeAll(); } }
From source file:com.sencha.gxt.widget.core.client.tree.Tree.java
License:sencha.com license
protected SafeHtml getCellContent(M model) { C value = getValue(model);//from w w w. j a va2s.com SafeHtmlBuilder sb = new SafeHtmlBuilder(); if (cell == null) { String text = null; if (value != null) { text = value.toString(); } sb.append(Util.isEmptyString(text) ? Util.NBSP_SAFE_HTML : SafeHtmlUtils.fromString(text)); } else { Context context = new Context(store.indexOf(model), 0, store.getKeyProvider().getKey(model)); cell.render(context, value, sb); } return sb.toSafeHtml(); }
From source file:com.sencha.gxt.widget.core.client.tree.Tree.java
License:sencha.com license
protected void onAdd(StoreAddEvent<M> event) { for (M child : event.getItems()) { register(child);/*from w w w.j ava 2s. c o m*/ } if (isOrWasAttached()) { M parent = store.getParent(event.getItems().get(0)); TreeNode<M> pn = findNode(parent); if (parent == null || (pn != null && pn.isChildrenRendered())) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); int parentDepth = parent == null ? 0 : store.getDepth(parent); for (M child : event.getItems()) { TreeViewRenderMode mode = !bufferRender ? TreeViewRenderMode.ALL : TreeViewRenderMode.BUFFER_WRAP; sb.append(renderChild(parent, child, parentDepth, mode)); } int index = event.getIndex(); int parentChildCount = parent == null ? store.getRootCount() : store.getChildCount(parent); if (index == 0) { DomHelper.insertFirst(getContainer(parent), sb.toSafeHtml()); } else if (index == parentChildCount - event.getItems().size()) { DomHelper.insertHtml("beforeEnd", getContainer(parent), sb.toSafeHtml()); } else { DomHelper.insertBefore((Element) getContainer(parent).getChild(index).cast(), sb.toSafeHtml()); } } refresh(parent); update(); } }