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.studio.client.workbench.views.environment.view.EnvironmentObjectList.java

License:Open Source License

private void createExpandColumn() {
    // the column containing the expand command; available only on objects
    // with contents (such as lists and data frames).
    SafeHtmlRenderer<String> expanderRenderer = new AbstractSafeHtmlRenderer<String>() {
        @Override//from ww  w.  ja v  a 2s.  c om
        public SafeHtml render(String object) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            sb.appendHtmlConstant(object);
            return sb.toSafeHtml();
        }
    };
    objectExpandColumn_ = new Column<RObjectEntry, String>(new ClickableTextCell(expanderRenderer)) {
        @Override
        public String getValue(RObjectEntry object) {
            String imageUri = "";
            String imageStyle = style_.expandIcon();
            if (object.canExpand()) {
                imageStyle = imageStyle + " " + ThemeStyles.INSTANCE.handCursor();
                ImageResource expandImage = object.isExpanding ? CoreResources.INSTANCE.progress()
                        : object.expanded ? EnvironmentResources.INSTANCE.collapseIcon()
                                : EnvironmentResources.INSTANCE.expandIcon();

                imageUri = expandImage.getSafeUri().asString();
            } else if (object.hasTraceInfo()) {
                imageUri = EnvironmentResources.INSTANCE.tracedFunction().getSafeUri().asString();
                imageStyle += (" " + style_.unclickableIcon());
            }
            if (imageUri.length() > 0) {
                return "<input type=\"image\" src=\"" + imageUri + "\" " + "class=\"" + imageStyle + "\" />";
            }
            return "";
        }
    };
    objectExpandColumn_.setFieldUpdater(new FieldUpdater<RObjectEntry, String>() {
        @Override
        public void update(int index, RObjectEntry object, String value) {
            if (!object.canExpand())
                return;
            expandObject(index, object);
        }
    });
}

From source file:org.rstudio.studio.client.workbench.views.output.find.FindOutputPane.java

License:Open Source License

@Override
public void updateSearchLabel(String query, String path) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.appendEscaped("Results for ").appendHtmlConstant("<strong>").appendEscaped(query)
            .appendHtmlConstant("</strong>").appendEscaped(" in ").appendEscaped(path);
    searchLabel_.getElement().setInnerHTML(builder.toSafeHtml().asString());
}

From source file:org.rstudio.studio.client.workbench.views.output.find.model.FindResult.java

License:Open Source License

public final SafeHtml getLineHTML() {
    SafeHtmlBuilder out = new SafeHtmlBuilder();

    ArrayList<Integer> on = getMatchOns();
    ArrayList<Integer> off = getMatchOffs();
    ArrayList<Pair<Boolean, Integer>> parts = new ArrayList<Pair<Boolean, Integer>>();
    while (on.size() + off.size() > 0) {
        int onVal = on.size() == 0 ? Integer.MAX_VALUE : on.get(0);
        int offVal = off.size() == 0 ? Integer.MAX_VALUE : off.get(0);
        if (onVal <= offVal)
            parts.add(new Pair<Boolean, Integer>(true, on.remove(0)));
        else//ww w  .j ava  2s  .  c o m
            parts.add(new Pair<Boolean, Integer>(false, off.remove(0)));
    }

    String line = getLineValue();

    // Use a counter to ensure tags are balanced.
    int openTags = 0;

    for (int i = 0; i < line.length(); i++) {
        while (parts.size() > 0 && parts.get(0).second == i) {
            if (parts.remove(0).first) {
                out.appendHtmlConstant("<strong>");
                openTags++;
            } else if (openTags > 0) {
                out.appendHtmlConstant("</strong>");
                openTags--;
            }
        }
        out.append(line.charAt(i));
    }

    while (openTags > 0) {
        openTags--;
        out.appendHtmlConstant("</strong>");
    }

    return out.toSafeHtml();
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget.java

License:Open Source License

private MenuItem createMenuItemForType(final TextFileType type) {
    SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
    labelBuilder.appendEscaped(type.getLabel());

    MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {
        public void execute() {
            docUpdateSentinel_.changeFileType(type.getTypeId(), new SaveProgressIndicator(null, type, null));

            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override/*from w w w .ja va  2s. co  m*/
                public void execute() {
                    focus();
                }
            });
        }
    });

    return menuItem;
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget.java

License:Open Source License

private MenuItem addFunctionsToMenu(StatusBarPopupMenu menu, final JsArray<Scope> funcs, String indent,
        Scope defaultFunction, boolean includeNoFunctionsMessage) {
    MenuItem defaultMenuItem = null;

    if (funcs.length() == 0 && includeNoFunctionsMessage) {
        String type = fileType_.canExecuteChunks() ? "chunks" : "functions";
        MenuItem noFunctions = new MenuItem("(No " + type + " defined)", false, (Command) null);
        noFunctions.setEnabled(false);/*from   ww w  . j av a 2s  . c o m*/
        noFunctions.getElement().addClassName("disabled");
        menu.addItem(noFunctions);
    }

    for (int i = 0; i < funcs.length(); i++) {
        final Scope func = funcs.get(i);

        String childIndent = indent;
        if (!StringUtil.isNullOrEmpty(func.getLabel())) {
            SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
            labelBuilder.appendHtmlConstant(indent);
            labelBuilder.appendEscaped(func.getLabel());

            final MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {
                public void execute() {
                    docDisplay_.navigateToPosition(toSourcePosition(func), true);
                }
            });
            menu.addItem(menuItem);

            childIndent = indent + "&nbsp;&nbsp;";

            if (defaultFunction != null && defaultMenuItem == null
                    && func.getLabel().equals(defaultFunction.getLabel())
                    && func.getPreamble().getRow() == defaultFunction.getPreamble().getRow()
                    && func.getPreamble().getColumn() == defaultFunction.getPreamble().getColumn()) {
                defaultMenuItem = menuItem;
            }
        }

        MenuItem childDefaultMenuItem = addFunctionsToMenu(menu, func.getChildren(), childIndent,
                defaultMenuItem == null ? defaultFunction : null, false);
        if (childDefaultMenuItem != null)
            defaultMenuItem = childDefaultMenuItem;
    }

    return defaultMenuItem;
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTargetPresentationHelper.java

License:Open Source License

public void buildSlideMenu(final String path, boolean isDirty, final EditingTarget editor,
        final CommandWithArg<StatusBarPopupRequest> onCompleted) {
    // rpc response handler
    SimpleRequestCallback<SlideNavigation> requestCallback = new SimpleRequestCallback<SlideNavigation>() {

        @Override/*  www .j a  v a  2s.co  m*/
        public void onResponseReceived(SlideNavigation slideNavigation) {
            // create the menu and make sure we have some slides to return
            StatusBarPopupMenu menu = new StatusBarPopupMenu();
            if (slideNavigation.getTotalSlides() == 0) {
                onCompleted.execute(new StatusBarPopupRequest(menu, null));
                return;
            }

            MenuItem defaultMenuItem = null;
            int length = slideNavigation.getItems().length();
            for (int i = 0; i < length; i++) {
                SlideNavigationItem item = slideNavigation.getItems().get(i);
                String title = item.getTitle();
                if (StringUtil.isNullOrEmpty(title))
                    title = "(Untitled Slide)";

                StringBuilder indentBuilder = new StringBuilder();
                for (int level = 0; level < item.getIndent(); level++)
                    indentBuilder.append("&nbsp;&nbsp;");

                SafeHtmlBuilder labelBuilder = new SafeHtmlBuilder();
                labelBuilder.appendHtmlConstant(indentBuilder.toString());
                labelBuilder.appendEscaped(title);

                final int targetSlide = i;
                final MenuItem menuItem = new MenuItem(labelBuilder.toSafeHtml(), new Command() {
                    public void execute() {
                        navigateToSlide(editor, targetSlide);
                    }
                });
                menu.addItem(menuItem);

                // see if this is the default menu item
                if (defaultMenuItem == null && item.getLine() >= (docDisplay_.getSelectionStart().getRow())) {
                    defaultMenuItem = menuItem;
                }
            }

            StatusBarPopupRequest request = new StatusBarPopupRequest(menu, defaultMenuItem);
            onCompleted.execute(request);
        }
    };

    // send code over the wire if we are dirty
    if (isDirty) {
        server_.getSlideNavigationForCode(docDisplay_.getCode(),
                FileSystemItem.createFile(path).getParentPathString(), requestCallback);
    } else {
        server_.getSlideNavigationForFile(path, requestCallback);
    }
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ui.NewRMarkdownDialog.java

License:Open Source License

private Widget createFormatOption(String name, String description) {
    HTMLPanel formatWrapper = new HTMLPanel("");
    formatWrapper.setStyleName(style.outputFormat());
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    sb.appendHtmlConstant("<span class=\"" + style.outputFormatName() + "\">");
    sb.appendEscaped(name);/*from   w w  w  .j  a  v a  2s  . c  o m*/
    sb.appendHtmlConstant("</span>");
    RadioButton button = new RadioButton("DefaultOutputFormat", sb.toSafeHtml().asString(), true);
    button.addStyleName(style.outputFormatChoice());
    formatOptions_.add(button);
    formatWrapper.add(button);
    Label label = new Label(description);
    label.setStyleName(style.outputFormatDetails());
    formatWrapper.add(label);
    return formatWrapper;
}

From source file:org.rstudio.studio.client.workbench.views.vcs.git.GitStatusRenderer.java

License:Open Source License

@Override
public SafeHtml render(String str) {
    if (str.length() != 2)
        return null;

    ImageResource indexImg = imgForStatus(str.charAt(0));
    ImageResource treeImg = imgForStatus(str.charAt(1));

    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(SafeHtmlUtils.fromTrustedString("<span " + "class=\"" + ctRes_.cellTableStyle().status()
            + "\" " + "title=\"" + SafeHtmlUtils.htmlEscape(descForStatus(str)) + "\">"));

    builder.append(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(indexImg).getHTML()));
    builder.append(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(treeImg).getHTML()));

    builder.appendHtmlConstant("</span>");

    return builder.toSafeHtml();
}

From source file:org.rstudio.studio.client.workbench.views.vcs.svn.SVNStatusRenderer.java

License:Open Source License

@Override
public SafeHtml render(String str) {
    if (str.length() != 1)
        return SafeHtmlUtils.fromString(str);

    ImageResource img = imgForStatus(str.charAt(0));

    if (img == null)
        return SafeHtmlUtils.fromString(str);

    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(SafeHtmlUtils.fromTrustedString("<span " + "class=\"" + ctRes_.cellTableStyle().status()
            + "\" " + "title=\"" + SafeHtmlUtils.htmlEscape(descForStatus(str)) + "\">"));

    builder.append(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(img).getHTML()));

    builder.appendHtmlConstant("</span>");

    return builder.toSafeHtml();
}

From source file:org.sagebionetworks.web.client.widget.licenseddownloader.LicensedDownloaderViewImpl.java

License:Open Source License

@Deprecated
@Override/* ww  w.jav  a  2 s  .  c om*/
public void setDownloadUrls(List<FileDownload> downloads) {
    if (downloads != null && downloads.size() > 0) {
        // build a list of links in HTML
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        for (int i = 0; i < downloads.size(); i++) {
            FileDownload dl = downloads.get(i);
            sb.appendHtmlConstant("<a href=\"" + dl.getUrl() + "\" target=\"new\">")
                    .appendEscaped(dl.getDisplay())
                    .appendHtmlConstant("</a> " + AbstractImagePrototype.create(icons.external16()).getHTML());
            if (dl.getChecksum() != null) {
                sb.appendHtmlConstant("&nbsp;<small>md5 checksum: ").appendEscaped(dl.getChecksum())
                        .appendHtmlConstant("</small>");
            }
            sb.appendHtmlConstant("<br/>");
        }
        safeDownloadHtml = sb.toSafeHtml();

        // replace the view content if this is after initialization
        if (downloadContentContainer != null) {
            safeDownloadHtml = sb.toSafeHtml();
            fillDownloadContentContainer();
        }
    } else {
        setNoDownloads();
    }
}