List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder append
public SafeHtmlBuilder append(SafeHtml html)
From source file:com.google.code.tree.client.CustomEditTextCell.java
License:Apache License
@Override public void render(Context context, UpdatableTreeNode value, SafeHtmlBuilder sb) { // Get the view data. Object key = context.getKey(); ViewData viewData = getViewData(key); if (viewData != null && !viewData.isEditing() && value != null && value.getLabel().equals(viewData.getText())) { clearViewData(key);// w w w .ja va 2 s.c om viewData = null; } String toRender = value.getLabel(); if (viewData != null) { String text = viewData.getText(); if (viewData.isEditing()) { /* * Do not use the renderer in edit mode because the value of a * text input element is always treated as text. SafeHtml isn't * valid in the context of the value attribute. */ sb.append(template.input(text, charSize)); return; } else { // The user pressed enter, but view data still exists. toRender = text; } } if (toRender != null && toRender.trim().length() > 0) { sb.append(renderer.render(toRender)); } else { /* * Render a blank space to force the rendered element to have a * height. Otherwise it is not clickable. */ sb.appendHtmlConstant("\u00A0"); } }
From source file:com.google.gwt.sample.expenses.client.SortableHeader.java
License:Apache License
@Override public void render(Context context, SafeHtmlBuilder sb) { if (sorted) { sb.append(template.sorted(IMAGE_WIDTH, reverseSort ? DOWN_ARROW : UP_ARROW, text)); } else {/*from w w w .j ava 2 s. c om*/ sb.append(template.unsorted(IMAGE_WIDTH, text)); } }
From source file:com.google.gwt.sample.mobilewebapp.client.mobile.TaskProxyCell.java
License:Apache License
@Override @SuppressWarnings("deprecation") public void render(com.google.gwt.cell.client.Cell.Context context, TaskProxy value, SafeHtmlBuilder sb) { if (value == null) { return;/*from ww w .j a v a2 s .c om*/ } SafeHtml name; if (value.getName() == null) { name = SafeHtmlUtils.fromSafeConstant("<i>Unnamed</i>"); } else { name = SafeHtmlUtils.fromString(value.getName()); } Date date = value.getDueDate(); Date today = new Date(); today.setHours(0); today.setMinutes(0); today.setSeconds(0); if (date == null) { sb.append(template.noDate(name)); } else if (date.before(today)) { sb.append(template.pastDue(name, dateFormat.format(date))); } else { sb.append(template.onTime(name, dateFormat.format(date))); } }
From source file:com.google.gwt.sample.showcase.client.content.cell.CompositeContactCell.java
private static HasCell<ContactInfo, Boolean> createStar(final CwCellList.Images images) { return new HasCell<ContactInfo, Boolean>() { @Override/*from ww w. j av a 2s . c om*/ public Cell<Boolean> getCell() { return new AbstractCell<Boolean>(BrowserEvents.CLICK) { private ImageResourceRenderer renderer = new ImageResourceRenderer(); @Override public void render(Cell.Context context, Boolean value, SafeHtmlBuilder sb) { if (value != null) { sb.append(renderer.render(value ? images.star() : images.starOutline())); } } @Override public void onBrowserEvent(Cell.Context context, Element parent, Boolean value, NativeEvent event, ValueUpdater<Boolean> valueUpdater) { // Let AbstractCell handle the keydown event. super.onBrowserEvent(context, parent, value, event, valueUpdater); // Handle the click event. if (BrowserEvents.CLICK.equals(event.getType())) { // Ignore clicks that occur outside of the outermost element. EventTarget eventTarget = event.getEventTarget(); if (parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))) { boolean newValue = !value; valueUpdater.update(newValue); SafeHtmlBuilder sb = new SafeHtmlBuilder(); render(context, newValue, sb); parent.setInnerSafeHtml(sb.toSafeHtml()); } } } }; } @Override public FieldUpdater<ContactInfo, Boolean> getFieldUpdater() { return new FieldUpdater<ContactInfo, Boolean>() { @Override public void update(int index, ContactInfo contact, Boolean value) { contact.setStarred(value); } }; } @Override public Boolean getValue(ContactInfo contact) { return contact.isStarred(); } }; }
From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackLayoutPanel.java
License:Apache License
/** * Add a {@link TreeItem} to a root item. * //from w w w .j a v a 2 s . co m * @param root the root {@link TreeItem} * @param image the icon for the new child item * @param label the label for the child icon */ @ShowcaseSource private void addItem(TreeItem root, ImageResource image, String label) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.append(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(image).getHTML())); sb.appendEscaped(" ").appendEscaped(label); root.addItem(sb.toSafeHtml()); }
From source file:com.google.gwt.uibinder.test.client.SimpleRenderable.java
License:Apache License
@Override public void render(RenderableStamper stamper, SafeHtmlBuilder safeHtmlBuilder) { safeHtmlBuilder.append(render(stamper)); }
From source file:com.google.maps.gwt.samples.basics.client.MapCoordinates.java
License:Apache License
private String createInfoWindowContent() { int numTiles = 1 << (int) map.getZoom(); MercatorProjection projection = new MercatorProjection(); Point worldCoordinate = projection.fromLatLngToPoint(CHICAGO); Point pixelCoordinate = Point.create(worldCoordinate.getX() * numTiles, worldCoordinate.getY() * numTiles); Point tileCoordinate = Point.create(Math.floor(pixelCoordinate.getX() / TILE_SIZE), Math.floor(pixelCoordinate.getY() / TILE_SIZE)); SafeHtmlBuilder returnString = new SafeHtmlBuilder(); returnString.appendHtmlConstant("Chicago, IL<br>"); returnString.appendHtmlConstant("LatLng: "); returnString.append(CHICAGO.lat()); returnString.appendHtmlConstant(", "); returnString.append(CHICAGO.lng());// w ww.j a va 2 s. c om returnString.appendHtmlConstant("<br />"); returnString.appendHtmlConstant("World Coordinate: "); returnString.append(worldCoordinate.getX()); returnString.appendHtmlConstant(", "); returnString.append(worldCoordinate.getY()); returnString.appendHtmlConstant("<br />"); returnString.appendHtmlConstant("Pixel Coordinate: "); returnString.append(Math.floor(pixelCoordinate.getX())); returnString.appendHtmlConstant(", "); returnString.append(Math.floor(pixelCoordinate.getY())); returnString.appendHtmlConstant("<br />"); returnString.appendHtmlConstant("Tile Coordinate: "); returnString.append(Math.floor(tileCoordinate.getX())); returnString.appendHtmlConstant(", "); returnString.append(Math.floor(tileCoordinate.getY())); returnString.appendHtmlConstant("<br />"); returnString.appendHtmlConstant("at Zoom Level: "); returnString.append(map.getZoom()); return returnString.toSafeHtml().asString(); }
From source file:com.google.maps.gwt.samples.overlays.client.PolygonArrays.java
License:Apache License
private void showArrays(MouseEvent event) { // Since this Polygon only has one path, we can call getPath() // to return the MVCArray of LatLngs MVCArray<LatLng> vertices = bermudaTriangle.getPath(); SafeHtmlBuilder contentString = new SafeHtmlBuilder(); contentString.appendHtmlConstant("<b>Bermuda Triangle Polygon</b><br />"); contentString.appendHtmlConstant("Clicked Location: <br />"); contentString.append(event.getLatLng().lat()); contentString.appendHtmlConstant(","); contentString.append(event.getLatLng().lng()); contentString.appendHtmlConstant("<br />"); // Iterate over the vertices. for (int i = 0; i < vertices.getLength(); i++) { LatLng xy = vertices.getAt(i);/* w ww .jav a2 s.c om*/ contentString.appendHtmlConstant("<br /> Coordinate: "); contentString.append(i); contentString.appendHtmlConstant("<br />"); contentString.append(xy.lat()); contentString.appendHtmlConstant(","); contentString.append(xy.lng()); } // Replace our Info Window's content and position infowindow.setContent(contentString.toSafeHtml().asString()); infowindow.setPosition(event.getLatLng()); infowindow.open(map); }
From source file:com.googlecode.mgwt.ui.client.widget.celllist.BasicCell.java
License:Apache License
@Override public void render(SafeHtmlBuilder safeHtmlBuilder, final T model) { safeHtmlBuilder.append(TEMPLATE.content(styleName, SafeHtmlUtils.htmlEscape(getDisplayString(model)))); }
From source file:com.googlecode.mgwt.ui.client.widget.CellList.java
License:Apache License
/** * Render a List of models in this cell list * /* w ww .j a v a 2 s. c o m*/ * @param models the list of models to render */ public void render(List<T> models) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); for (int i = 0; i < models.size(); i++) { T model = models.get(i); SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder(); String clazz = ""; if (cell.canBeSelected(model)) { clazz = css.group() + " "; } if (i == 0) { clazz += css.first() + " "; } if (models.size() - 1 == i) { clazz += css.last() + " "; } cell.render(cellBuilder, model); sb.append(LI_TEMPLATE.li(i, clazz, cellBuilder.toSafeHtml())); } final String html = sb.toSafeHtml().asString(); getElement().setInnerHTML(html); if (models.size() > 0) { String innerHTML = getElement().getInnerHTML(); if ("".equals(innerHTML.trim())) { fixBug(html); } } }