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:org.rstudio.core.client.cellview.TriStateCheckboxCell.java

License:Open Source License

@Override
public void setValue(Context context, Element parent, Boolean value) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    render(context, value, builder);/*from  w w  w .  j a v a  2 s  . c o  m*/
    parent.setInnerHTML(builder.toSafeHtml().asString());
}

From source file:org.rstudio.core.client.resources.ImageResource2x.java

License:Open Source License

public SafeHtml getSafeHtml() {
    if (html_ == null) {
        SafeHtmlBuilder sb = new SafeHtmlBuilder();

        sb.appendHtmlConstant("<img src=\"");
        sb.appendHtmlConstant(getSafeUri().asString());
        sb.appendHtmlConstant("\" width=\"");
        sb.appendHtmlConstant(new Integer(getWidth()).toString());
        sb.appendHtmlConstant("\" height=\"");
        sb.appendHtmlConstant(new Integer(getHeight()).toString());
        sb.appendHtmlConstant("\">");

        html_ = sb.toSafeHtml();
    }/*  w ww. j a  v  a2  s  . co m*/

    return html_;
}

From source file:org.rstudio.core.client.resources.ImageResourceUrl.java

License:Open Source License

public SafeHtml getSafeHtml() {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();

    sb.appendHtmlConstant("<img src=\"");
    sb.appendHtmlConstant(getSafeUri().asString());
    sb.appendHtmlConstant("\" width=\"");
    sb.appendHtmlConstant(new Integer(getWidth()).toString());
    sb.appendHtmlConstant("\" height=\"");
    sb.appendHtmlConstant(new Integer(getHeight()).toString());
    sb.appendHtmlConstant("\">");

    return sb.toSafeHtml();
}

From source file:org.rstudio.core.client.VirtualConsole.java

License:Open Source License

public SafeHtml toSafeHtml() {
    // convert to a plain-text string
    String plainText = toString();
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    String lastClass = null;/*from ww  w.  j a  v a2 s . com*/
    int len = plainText.length();
    padCharClass(len);

    // iterate in lockstep over the plain-text string and character class
    // assignment list; emit the appropriate tags when switching classes
    for (int i = 0; i < len; i++) {
        if (!charClass.get(i).equals(lastClass)) {
            if (lastClass != null)
                sb.appendHtmlConstant("</span>");
            lastClass = charClass.get(i);
            if (lastClass != null)
                sb.appendHtmlConstant("<span class=\"" + lastClass + "\">");
        }
        sb.appendEscaped(plainText.substring(i, i + 1));
    }
    if (lastClass != null)
        sb.appendHtmlConstant("</span>");

    return sb.toSafeHtml();
}

From source file:org.rstudio.core.client.widget.ShortcutInfoPanel.java

License:Open Source License

protected Widget getShortcutContent() {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    List<ShortcutInfo> shortcuts = ShortcutManager.INSTANCE.getActiveShortcutInfo();
    String[][] groupNames = { new String[] { "Tabs/Panes", "Files", "Console" },
            new String[] { "Source Navigation", "Execute" }, new String[] { "Source Editor", "Debug" },
            new String[] { "Source Control", "Build", "Other" } };
    int pctWidth = 100 / groupNames.length;
    sb.appendHtmlConstant("<table width='100%'><tr>");
    for (String[] colGroupNames : groupNames) {
        sb.appendHtmlConstant("<td width='" + pctWidth + "%'>");
        for (String colGroupName : colGroupNames) {
            sb.appendHtmlConstant("<h2>");
            sb.appendEscaped(colGroupName);
            sb.appendHtmlConstant("</h2><table>");
            for (int i = 0; i < shortcuts.size(); i++) {
                ShortcutInfo info = shortcuts.get(i);
                if (info.getDescription() == null || info.getShortcuts().size() == 0
                        || !info.getGroupName().equals(colGroupName)) {
                    continue;
                }/*from w w w  .  j  av a2s.  c om*/
                sb.appendHtmlConstant("<tr><td><strong>");
                sb.appendHtmlConstant(StringUtil.joinStrings(info.getShortcuts(), ", "));
                sb.appendHtmlConstant("</strong></td><td>");
                sb.appendEscaped(info.getDescription());
                sb.appendHtmlConstant("</td></tr>");
            }
            sb.appendHtmlConstant("</table>");
        }
        sb.appendHtmlConstant("</td>");
    }
    sb.appendHtmlConstant("</td></tr></table>");
    HTMLPanel panel = new HTMLPanel(sb.toSafeHtml());
    return panel;
}

From source file:org.rstudio.studio.client.common.presentation.SlideNavigationPresenter.java

License:Open Source License

@Override
public void onSlideNavigationChanged(SlideNavigationChangedEvent event) {
    slideNavigation_ = event.getNavigation();

    SlideNavigationMenu navigationMenu = view_.getNavigationMenu();
    navigationMenu.clear();/*from www.ja v  a  2  s. c o  m*/

    if (slideNavigation_ != null) {
        JsArray<SlideNavigationItem> items = slideNavigation_.getItems();
        for (int i = 0; i < items.length(); i++) {
            // get slide
            final SlideNavigationItem item = items.get(i);

            // build html
            SafeHtmlBuilder menuHtml = new SafeHtmlBuilder();
            for (int j = 0; j < item.getIndent(); j++)
                menuHtml.appendHtmlConstant("&nbsp;&nbsp;&nbsp;");
            menuHtml.appendEscaped(item.getTitle());

            navigationMenu.addItem(new MenuItem(menuHtml.toSafeHtml(), new Command() {
                @Override
                public void execute() {
                    view_.navigate(item.getIndex());
                }
            }));
        }

        navigationMenu.setVisible(true);

        navigationMenu.setDropDownVisible(slideNavigation_.getItems().length() > 1);
    } else {
        navigationMenu.setVisible(false);
    }

}

From source file:org.rstudio.studio.client.rsconnect.ui.DirEntryCheckBox.java

License:Open Source License

public DirEntryCheckBox(String path) {
    // create the appropriate filesystem object for the path
    FileSystemItem fsi = null;/*from ww  w .j a va 2s.  com*/
    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
        fsi = FileSystemItem.createDir(path);
    } else {
        fsi = FileSystemItem.createFile(path);
    }
    path_ = path;

    // add an icon representing the file
    ImageResource icon = RStudioGinjector.INSTANCE.getFileTypeRegistry().getIconForFile(fsi);
    SafeHtmlBuilder hb = new SafeHtmlBuilder();
    hb.append(AbstractImagePrototype.create(icon).getSafeHtml());

    // insert the file/dir name into the checkbox
    hb.appendEscaped(path_);
    checkbox_ = new CheckBox(hb.toSafeHtml());

    initWidget(checkbox_);
}

From source file:org.rstudio.studio.client.workbench.codesearch.CodeSearchSuggestion.java

License:Open Source License

private String createDisplayString(ImageResource image, String imageStyle, String name, String extraInfo,
        String context) {/*w w  w.j  a  v a  2s  .  c om*/
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    SafeHtmlUtil.appendImage(sb, imageStyle, image);
    SafeHtmlUtil.appendSpan(sb, RES.styles().itemName(), name);

    // check for extra info
    if (!StringUtil.isNullOrEmpty(extraInfo)) {
        SafeHtmlUtil.appendSpan(sb, RES.styles().itemName(), extraInfo);
    }

    // check for context
    if (context != null) {
        SafeHtmlUtil.appendSpan(sb, RES.styles().itemContext(), "(" + context + ")");
    }
    return sb.toSafeHtml().asString();
}

From source file:org.rstudio.studio.client.workbench.views.connections.ui.NewConnectionSnippetHost.java

License:Open Source License

private void showFailure(String error) {
    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.addStyleName(RES.styles().dialogMessagePanel());

    SafeHtmlBuilder safeHtmlBuilder = new SafeHtmlBuilder();
    safeHtmlBuilder.appendHtmlConstant("<b>Failure.</b> ");
    safeHtmlBuilder.appendEscaped(error);

    verticalPanel.add(new HTML(safeHtmlBuilder.toSafeHtml()));
    MessageDialog dlg = new MessageDialog(MessageDialog.ERROR, "Test Results", verticalPanel);

    dlg.addButton("OK", new Operation() {
        @Override/*from ww  w .  ja  v a2s  .c  o  m*/
        public void execute() {
        }
    }, true, false);

    dlg.showModal();
}

From source file:org.rstudio.studio.client.workbench.views.environment.view.EnvironmentObjectDisplay.java

License:Open Source License

public EnvironmentObjectDisplay(Host host, EnvironmentObjectsObserver observer, String environmentName) {
    super(EnvironmentObjects.MAX_ENVIRONMENT_OBJECTS, RObjectEntry.KEY_PROVIDER);

    observer_ = observer;/* w  w  w  .j a v a  2  s  .  com*/
    host_ = host;
    environmentStyle_ = EnvironmentResources.INSTANCE.environmentStyle();
    environmentStyle_.ensureInjected();
    environmentName_ = environmentName;
    filterRenderer_ = new AbstractSafeHtmlRenderer<String>() {
        @Override
        public SafeHtml render(String str) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            boolean hasMatch = false;
            String filterText = host_.getFilterText();
            if (filterText.length() > 0) {
                int idx = str.toLowerCase().indexOf(filterText);
                if (idx >= 0) {
                    hasMatch = true;
                    sb.appendEscaped(str.substring(0, idx));
                    sb.appendHtmlConstant("<span class=\"" + environmentStyle_.filterMatch() + "\">");
                    sb.appendEscaped(str.substring(idx, idx + filterText.length()));
                    sb.appendHtmlConstant("</span>");
                    sb.appendEscaped(str.substring(idx + filterText.length(), str.length()));
                }
            }
            if (!hasMatch)
                sb.appendEscaped(str);
            return sb.toSafeHtml();
        }
    };
}