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.mgwt.imustlearn.client.ui.CellListWithButtons.java

License:Apache License

/**
 * Render a List of models in this cell list
 *
 * @param models the list of models to render
 *//*from ww w. j  ava 2  s. co m*/
public void render(List<T> models, final CellButton... widgets) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();

    for (int i = 0; i < models.size(); i++) {

        final T model = models.get(i);

        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();

        String clazz = "";

        if (group) {
            clazz += css.group() + " ";
        }

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

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

        cellBuilder.append(new SafeHtml() {
            @Override
            public String asString() {
                return cell.getDisplayString(model);
            }
        });

        sb.append(LI_TEMPLATE.li(i, clazz, cellBuilder.toSafeHtml(), widgetsBuilder.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.msco.mil.client.com.sencha.gxt.desktop.client.widget.StartMenu.java

License:sencha.com license

/**
 * Creates a start menu with the specified appearance.
 * // ww w .j  av  a2s  .c o  m
 * @param appearance the start menu appearance
 */
public StartMenu(StartMenuDefaultAppearance appearance) {

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

    XElement element = XDOM.create(builder.toSafeHtml());
    setElement(element);

    appearance.setHeading(element, getHeading());
    appearance.setMainMenu(element, getMainMenu());
    appearance.setToolMenu(element, getToolMenu());

    sinkEvents(Event.MOUSEEVENTS | Event.ONCLICK);
}

From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.dnd.BasicDndExample.java

License:sencha.com license

private void addSources(FlowLayoutContainer container) {
    for (int i = 0; i < 5; i++) {
        final SafeHtmlBuilder builder = new SafeHtmlBuilder();
        builder.appendHtmlConstant("<div style=\"border:1px solid #ddd;cursor:default\" class=\""
                + SafeHtmlUtils.htmlEscape(ExampleStyles.get().paddedText()) + "\">");
        builder.appendHtmlConstant("Drag Me " + i);
        builder.appendHtmlConstant("</div>");
        final HTML html = new HTML(builder.toSafeHtml());
        container.add(html, new MarginData(3));

        DragSource source = new DragSource(html) {
            @Override/*from  w w w  . j a  va 2s . c  o m*/
            protected void onDragStart(DndDragStartEvent event) {
                super.onDragStart(event);
                // by default drag is allowed
                event.setData(html);
                event.getStatusProxy().update(builder.toSafeHtml());
            }

        };
        // group is optional
        source.setGroup("test");
    }
}

From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.model.Example.java

License:sencha.com license

public SafeHtml getImage() {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.appendHtmlConstant(AbstractImagePrototype.create(icon).getHTML());
    return builder.toSafeHtml();
}

From source file:com.pronoiahealth.olhie.client.features.dialogs.ErrorDisplayDialog.java

License:Open Source License

private void displayError(String msg, boolean reloadWindow) {
    this.reloadWindow = reloadWindow;
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    if (msg == null) {
        msg = "No error message was reported.";
    }/*from   www .jav a  2 s.  c om*/
    errorMsg.setHTML(builder.appendEscaped(msg).toSafeHtml());
    errorDisplayModal.show();
}

From source file:com.roughindustries.commonwealthcocktails.client.application.ApplicationPresenter.java

License:Apache License

@Override
protected void onBind() {

    step.setValue(25);/*from   w w w.  ja va  2s  . c o  m*/
    current.setValue(25);
    next.setValue(current.intValue() + step.intValue());
    prev.setValue(0);

    lastScrollPos.setValue(0);
    lastMaxScrollTop.setValue(0);

    list.addAll(Collections.nCopies(current.intValue(), new ccCocktail()));

    final HTML f = new HTML("");
    Column<ccCocktail, SafeHtml> text = new Column<ccCocktail, SafeHtml>(new SafeHtmlCell()) {

        public SafeHtml getValue(ccCocktail cocktail) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            if (cocktail == null || cocktail.getCocktailName() == null) {
                sb.appendHtmlConstant("Loading ...");
                return sb.toSafeHtml();
            } else {
                sb.appendHtmlConstant(
                        "<table border='0' cellpadding='1' cellspacing='1' style='width: 100%;'>");
                sb.appendHtmlConstant("<tbody>");
                sb.appendHtmlConstant("<tr>");
                sb.appendHtmlConstant(
                        "<td><img alt='Cocktail' src='https://s3.amazonaws.com/commonwealthcocktailbucket/noun_320760_cc.png' style='border-width: 0px; border-style: solid; margin: 0px; width: 100px; height: 100px;' /></td>");
                sb.appendHtmlConstant(
                        "<td border='0' cellpadding='1' cellspacing='1' style='width: 100%;' table=''>");
                sb.appendHtmlConstant(
                        "<table border='0' cellpadding='1' cellspacing='1' style='width: 100%;'>");
                sb.appendHtmlConstant("<tbody>");
                sb.appendHtmlConstant("<tr>");
                sb.appendHtmlConstant("<td><b>" + cocktail.getCocktailName() + "</b></td>");
                sb.appendHtmlConstant("</tr>");
                sb.appendHtmlConstant("<tr>");
                sb.appendHtmlConstant(
                        "<td><b>Origin: </b>"
                                + ((cocktail.getCocktailOrigin() == null)
                                        || (cocktail.getCocktailOrigin().length() == 0) ? ""
                                                : (cocktail.getCocktailOrigin().substring(0, 150) + "..."))
                                + "</td>");
                sb.appendHtmlConstant("</tr>");
                sb.appendHtmlConstant("<tr>");
                sb.appendHtmlConstant("<td><b>Method: </b>"
                        + ((cocktail.getCocktailMethod() == null) || (cocktail.getCocktailMethod() == null) ? ""
                                : (cocktail.getCocktailMethod().substring(0, 150) + "..."))
                        + "</td>");
                sb.appendHtmlConstant("</tr>");
                sb.appendHtmlConstant("</tbody>");
                sb.appendHtmlConstant("</table>");
                sb.appendHtmlConstant("</td>");
                sb.appendHtmlConstant("</tr>");
                sb.appendHtmlConstant("</tbody>");
                sb.appendHtmlConstant("</table>");
                return sb.toSafeHtml();
            }
        }

    };
    getView().getCocktailGrid().addColumn(text);
    data.addAll(list);
    getView().getCocktailGrid().setRowData(0, data);
    getView().getCocktailGrid().setVisibleRange(new Range(0, current.intValue()));
    getView().getCocktailGrid().setHeight(Integer.toString(Window.getClientHeight()) + "px");
    getView().getScroll().setHeight(Integer.toString(Window.getClientHeight()) + "px");
    getView().getScroll().setWidth(Integer.toString(Window.getClientWidth()) + "px");
    if (Window.getClientWidth() <= 768) {
        getView().getBrand().setMarginLeft((Window.getClientWidth() / 2) - 125);
    } else {
        getView().getBrand().setMarginLeft(0);
    }
    if (Window.getClientWidth() > (800)
            && (Window.getClientWidth() <= (800 + NativeVerticalScrollbar.getNativeScrollbarWidth()))) {
        getView().getHeaderContainer()
                .setWidth((800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) + "px");
        getView().getCocktailGrid().setWidth((800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) + "px");
        if (getView().getLeftBuffer().isVisible()) {
            getView().getLeftBuffer().setVisible(false);
            getView().getRightBuffer().setVisible(false);
        }
    } else if (Window.getClientWidth() <= (800 - NativeVerticalScrollbar.getNativeScrollbarWidth())) {
        getView().getHeaderContainer().setWidth(
                Integer.toString(Window.getClientWidth() - NativeVerticalScrollbar.getNativeScrollbarWidth())
                        + "px");
        getView().getCocktailGrid().setWidth(
                Integer.toString(Window.getClientWidth() - NativeVerticalScrollbar.getNativeScrollbarWidth())
                        + "px");

        if (getView().getLeftBuffer().isVisible()) {
            getView().getLeftBuffer().setVisible(false);
            getView().getRightBuffer().setVisible(false);
        }
    } else {
        getView().getHeaderContainer().setWidth("800px");
        getView().getCocktailGrid().setWidth("800px");
        if (!getView().getLeftBuffer().isVisible()) {
            getView().getLeftBuffer().setVisible(true);
            getView().getRightBuffer().setVisible(true);
        }
        getView().getLeftBuffer()
                .setWidth(Integer.toString(
                        (Window.getClientWidth() - 800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) / 2)
                        + "px");
        getView().getRightBuffer()
                .setWidth(Integer.toString(
                        (Window.getClientWidth() - 800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) / 2)
                        + "px");
    }
    getView().getScroll().addScrollHandler(new ScrollHandler() {

        @Override
        public void onScroll(ScrollEvent ev) {
            int oldScrollPos = lastScrollPos.intValue();
            lastScrollPos.setValue(getView().getScroll().getVerticalScrollPosition());

            // If scrolling up, ignore the event.
            if (oldScrollPos >= lastScrollPos.intValue()) {
                return;
            }

            // Height of grid contents (including outside the viewable area)
            // - height of the scroll panel
            int maxScrollTop = getView().getScroll().getWidget().getOffsetHeight()
                    - getView().getScroll().getOffsetHeight();
            if (lastScrollPos.intValue() == maxScrollTop) {
                if ((data.size() + step.intValue()) <= queryResultsCount.intValue()) {
                    prev.setValue(current);
                    current.setValue(next);
                    next.setValue(next.intValue() + step.intValue());
                    data.addAll(
                            new ArrayList<ccCocktail>(Collections.nCopies(step.intValue(), new ccCocktail())));
                } else {
                    int diff = queryResultsCount.intValue() - data.size();
                    if (diff > 0) {
                        step.setValue(diff);
                        prev.setValue(current);
                        current.setValue(next);
                        next.setValue(next.intValue() + step.intValue());
                        data.addAll(new ArrayList<ccCocktail>(Collections.nCopies(diff, new ccCocktail())));
                    } else {
                        step.setValue(0);
                    }
                }
                getView().getCocktailGrid().setRowData(0, data);
                getView().getCocktailGrid().setVisibleRange(new Range(0, current.intValue()));
                getView().getCocktailGrid().redraw();
                if (step.intValue() != 0) {
                    cocktailService.cocktailServer("", prev.intValue(), step.intValue(),
                            new AsyncCallback<ccCocktail[]>() {
                                public void onFailure(Throwable caught) {

                                }

                                public void onSuccess(ccCocktail[] result) {
                                    if (result != null) {
                                        for (ccCocktail item : result) {
                                            data.set(item.getPageRefID(), item);
                                        }
                                        getView().getCocktailGrid().setRowData(0, data);
                                        getView().getCocktailGrid()
                                                .setVisibleRange(new Range(0, current.intValue()));
                                        getView().getCocktailGrid().redraw();

                                    }
                                }
                            });
                }
            }
        }
    });
    Window.addWindowScrollHandler(new Window.ScrollHandler() {
        @Override
        public void onWindowScroll(com.google.gwt.user.client.Window.ScrollEvent event) {
            // Window.alert("Scrolling Window");
        }
    });
    cocktailService.getCount("", new AsyncCallback<Integer>() {
        public void onFailure(Throwable caught) {

        }

        public void onSuccess(Integer result) {
            queryResultsCount.setValue(result.intValue());
            cocktailService.cocktailServer("", prev.intValue(), current.intValue(),
                    new AsyncCallback<ccCocktail[]>() {
                        public void onFailure(Throwable caught) {

                        }

                        public void onSuccess(ccCocktail[] result) {
                            ArrayList<ccCocktail> removed = new ArrayList<ccCocktail>();
                            for (ccCocktail item : result) {
                                if (item != null) {
                                    removed.add(item);
                                }
                            }
                            result = removed.toArray(new ccCocktail[0]);
                            if (result != null) {
                                for (ccCocktail item : result) {
                                    data.set(item.getPageRefID(), item);
                                }
                                getView().getCocktailGrid().setRowData(0, data);
                                getView().getCocktailGrid().setVisibleRange(new Range(0, current.intValue()));
                                getView().getCocktailGrid().redraw();
                            }
                        }
                    });
        }
    });
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            getView().getCocktailGrid().setHeight(Integer.toString(Window.getClientHeight()) + "px");
            getView().getScroll().setHeight(Integer.toString(Window.getClientHeight()) + "px");
            getView().getScroll().setWidth(Integer.toString(Window.getClientWidth()) + "px");

            if (Window.getClientWidth() <= 768) {
                getView().getBrand().setMarginLeft((Window.getClientWidth() / 2) - 125);
            } else {
                getView().getBrand().setMarginLeft(0);
            }

            if (Window.getClientWidth() > (800)
                    && (Window.getClientWidth() <= (800 + NativeVerticalScrollbar.getNativeScrollbarWidth()))) {
                getView().getHeaderContainer()
                        .setWidth((800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) + "px");
                getView().getCocktailGrid()
                        .setWidth((800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) + "px");
                if (getView().getLeftBuffer().isVisible()) {
                    getView().getLeftBuffer().setVisible(false);
                    getView().getRightBuffer().setVisible(false);
                }
            } else if (Window.getClientWidth() <= (800 + NativeVerticalScrollbar.getNativeScrollbarWidth())) {
                getView().getHeaderContainer()
                        .setWidth(Integer.toString(
                                Window.getClientWidth() - NativeVerticalScrollbar.getNativeScrollbarWidth())
                                + "px");
                getView().getCocktailGrid()
                        .setWidth(Integer.toString(
                                Window.getClientWidth() - NativeVerticalScrollbar.getNativeScrollbarWidth())
                                + "px");
                if (getView().getLeftBuffer().isVisible()) {
                    getView().getLeftBuffer().setVisible(false);
                    getView().getRightBuffer().setVisible(false);
                }
            } else {
                getView().getHeaderContainer().setWidth("800px");
                getView().getCocktailGrid().setWidth("800px");
                if (!getView().getLeftBuffer().isVisible()) {
                    getView().getLeftBuffer().setVisible(true);
                    getView().getRightBuffer().setVisible(true);
                }
                getView().getLeftBuffer().setWidth(Integer.toString(
                        (Window.getClientWidth() - 800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) / 2)
                        + "px");
                getView().getRightBuffer().setWidth(Integer.toString(
                        (Window.getClientWidth() - 800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) / 2)
                        + "px");
            }
        }

    });
}

From source file:com.seanchenxi.gwt.serenity.client.view.impl.DiscussionViewImpl.java

License:Apache License

public void setMessage(boolean isPending, String message) {
    SafeHtml shtml;/*w  ww.j  av  a2  s .co  m*/
    if (isPending) {
        SafeHtmlBuilder shb = new SafeHtmlBuilder();
        shb.appendHtmlConstant("<p class=\"").appendHtmlConstant(getStyle().pendingDiscussion())
                .appendHtmlConstant("\">")
                .appendHtmlConstant(SerenityResources.MSG.msg_yourCommentIsAwaitingMod())
                .appendHtmlConstant("</p>").appendHtmlConstant(message);
        shtml = shb.toSafeHtml();
    } else {
        shtml = SafeHtmlUtils.fromTrustedString(message);
    }
    content.setHTML(shtml);
}

From source file:com.seanchenxi.gwt.serenity.client.view.impl.SerenityLayoutImpl.java

License:Apache License

public SerenityLayoutImpl() {
    SerenityResources.COMMON.commonCSS().ensureInjected();
    initWidget(UIBINDER.createAndBindUi(this));
    getElement().setId("main");
    resource.style().ensureInjected();/*from   ww  w . java 2  s.c  o  m*/
    header.setText(SerenityResources.MSG.page_Title());
    header.setSubText(SerenityResources.MSG.page_subTitle());
    header.getElement().setId("header");
    sidebarContainer.getElement().setId("sidebar");
    contentListContainer.getElement().setId("contents");
    SafeHtmlBuilder shb = new SafeHtmlBuilder();
    shb.append(FOOTER_TEMPLATE.copyright(
            DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR).format(new Date()),
            UriUtils.fromSafeConstant(SerenityUtil.getWpBaseUrl()), Window.Location.getHost()));
    shb.append(FOOTER_TEMPLATE.poweredBy(UriUtils.fromSafeConstant(SerenityResources.MSG.wordpress_URL()),
            SerenityResources.MSG.wordpress_URL(), SerenityUtil.getWpNaming()));
    footer.setHTML(shb.toSafeHtml());
    footer.getElement().setId("footer");
}

From source file:com.seanchenxi.serenity.client.view.impl.SerenityLayoutImpl.java

License:Apache License

public SerenityLayoutImpl() {
    SerenityResources.COMMON.commonCSS().ensureInjected();
    initWidget(UIBINDER.createAndBindUi(this));
    resource.style().ensureInjected();//from  www.j  av a  2s. c  o m
    header.setText(SerenityResources.MSG.page_Title());
    header.setSubText(SerenityResources.MSG.page_subTitle());
    SafeHtmlBuilder shb = new SafeHtmlBuilder();
    shb.append(FOOTER_TEMPLATE.copyright(
            DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR).format(new Date()),
            UriUtils.fromSafeConstant(SerenityUtil.getWpBaseUrl()), Window.Location.getHost()));
    shb.append(FOOTER_TEMPLATE.poweredBy(UriUtils.fromSafeConstant(SerenityResources.MSG.wordpress_URL()),
            SerenityResources.MSG.wordpress_URL(), SerenityUtil.getWpNaming()));
    footer.setHTML(shb.toSafeHtml());
}

From source file:com.sencha.gxt.cell.core.client.LabelProviderSafeHtmlRenderer.java

License:sencha.com license

@Override
public SafeHtml render(T object) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    sb.appendEscaped(labelProvider.getLabel(object));
    return sb.toSafeHtml();
}