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

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

Introduction

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

Prototype

public SafeHtmlBuilder() 

Source Link

Document

Constructs an empty SafeHtmlBuilder.

Usage

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//  w  w  w.ja va 2  s  .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.
 * /* w  w  w.j a  v a 2  s  .c  o 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.sample.showcase.client.content.lists.CwStackLayoutPanel.java

License:Apache License

/**
 * Create the list of Contacts.//from   ww w .j av a2  s  .co m
 * 
 * @param images the {@link Images} used in the Contacts
 * @return the list of contacts
 */
@ShowcaseSource
private Widget createContactsItem(Images images) {
    // Create a popup to show the contact info when a contact is clicked
    HorizontalPanel contactPopupContainer = new HorizontalPanel();
    contactPopupContainer.setSpacing(5);
    contactPopupContainer.add(new Image(images.defaultContact()));
    final HTML contactInfo = new HTML();
    contactPopupContainer.add(contactInfo);
    final PopupPanel contactPopup = new PopupPanel(true, false);
    contactPopup.setWidget(contactPopupContainer);

    // Create the list of contacts
    VerticalPanel contactsPanel = new VerticalPanel();
    contactsPanel.setSpacing(4);
    String[] contactNames = constants.cwStackLayoutPanelContacts();
    String[] contactEmails = constants.cwStackLayoutPanelContactsEmails();
    for (int i = 0; i < contactNames.length; i++) {
        final String contactName = contactNames[i];
        final String contactEmail = contactEmails[i];
        final Anchor contactLink = new Anchor(contactName);
        contactsPanel.add(contactLink);

        // Open the contact info popup when the user clicks a contact
        contactLink.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                // Set the info about the contact
                SafeHtmlBuilder sb = new SafeHtmlBuilder();
                sb.appendEscaped(contactName);
                sb.appendHtmlConstant("<br><i>");
                sb.appendEscaped(contactEmail);
                sb.appendHtmlConstant("</i>");
                contactInfo.setHTML(sb.toSafeHtml());

                // Show the popup of contact info
                int left = contactLink.getAbsoluteLeft() + 14;
                int top = contactLink.getAbsoluteTop() + 14;
                contactPopup.setPopupPosition(left, top);
                contactPopup.show();
            }
        });
    }
    return new SimplePanel(contactsPanel);
}

From source file:com.google.gwt.sample.validation.server.GreetingServiceImpl.java

License:Apache License

public SafeHtml greetServer(Person person) throws IllegalArgumentException, ConstraintViolationException {
    // Verify that the input is valid.
    Set<ConstraintViolation<Person>> violations = validator.validate(person, Default.class, ServerGroup.class);
    if (!violations.isEmpty()) {
        Set<ConstraintViolation<?>> temp = new HashSet<ConstraintViolation<?>>(violations);
        throw new ConstraintViolationException(temp);
    }/*from   ww  w  .  j a v a  2 s .com*/

    String serverInfo = getServletContext().getServerInfo();
    String userAgent = getThreadLocalRequest().getHeader("User-Agent");

    // Escape data from the client to avoid cross-site script vulnerabilities.
    SafeHtmlBuilder builder = new SafeHtmlBuilder();

    SafeHtml safeHtml = builder//
            .appendEscapedLines("Hello, " + person.getName() + "!")//
            .appendHtmlConstant("<br>")//
            .appendEscaped("I am running " + serverInfo + ".")//
            .appendHtmlConstant("<br><br>")//
            .appendEscaped("It looks like you are using: ")//
            .appendEscaped(userAgent)//
            .toSafeHtml();
    return safeHtml;
}

From source file:com.google.gwt.uibinder.test.client.UiRendererUi.java

License:Apache License

public SafeHtml render(String value) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    getRenderer().render(sb, new Foo(value));
    return sb.toSafeHtml();
}

From source file:com.google.javascript.jscomp.debugger.gwt.DebuggerGwtMain.java

License:Apache License

private void createCheckboxes(CellPanel checkboxPanel) {
    for (CompilationParam.ParamGroup group : CompilationParam.ParamGroup.values()) {
        SafeHtmlBuilder builder = new SafeHtmlBuilder();
        builder.appendHtmlConstant("<b>");
        builder.appendEscaped(group.name);
        builder.appendHtmlConstant("</b>");

        checkboxPanel.add(new HTML(builder.toSafeHtml()));
        for (final CompilationParam param : CompilationParam.getGroupedSortedValues().get(group)) {
            CheckBox cb = new CheckBox(param.toString());
            if (param.getJavaInfo() != null) {
                cb.setTitle("Java API equivalent: " + param.getJavaInfo());
            }//from w ww. j a  va2 s.  c o m
            cb.setValue(param.getDefaultValue());
            param.apply(options, param.getDefaultValue());
            cb.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    boolean checked = ((CheckBox) event.getSource()).getValue();
                    param.apply(options, checked);
                    doCompile();
                }
            });
            checkboxPanel.add(cb);
        }
    }
}

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());//  ww  w.  jav  a2  s.c om
    returnString.appendHtmlConstant(", ");
    returnString.append(CHICAGO.lng());
    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  .j a v a2 s  . c  o m
        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.java

License:Apache License

/**
 * Render a List of models in this cell list
 * /*from w  w  w . ja  va 2s  .  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);
        }
    }

}

From source file:com.googlecode.mgwt.ui.client.widget.list.celllist.CellList.java

License:Apache License

/**
 * Render a List of models in this cell list
 *
 * @param models the list of models to render
 *///from  ww  w .  java2 s .com
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 = this.appearance.css().entry() + " ";
        if (cell.canBeSelected(model)) {
            clazz += this.appearance.css().canbeSelected() + " ";
        }

        if (i == 0) {
            clazz += this.appearance.css().first() + " ";
        }

        if (models.size() - 1 == i) {
            clazz += this.appearance.css().last() + " ";
        }

        cell.render(cellBuilder, model);

        sb.append(entryTemplate.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);
        }
    }

}