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:org.rstudio.studio.client.workbench.views.output.markers.MarkerSetsToolbarButton.java

License:Open Source License

public void updateAvailableMarkerSets(String[] sets) {
    ToolbarPopupMenu menu = getMenu();//from  w  w w.jav a 2s. c  o  m
    menu.clearItems();
    for (final String set : sets) {
        // command for selection
        Scheduler.ScheduledCommand cmd = new Scheduler.ScheduledCommand() {
            @Override
            public void execute() {
                ValueChangeEvent.fire(MarkerSetsToolbarButton.this, set);
            }
        };

        SafeHtml menuHTML = new SafeHtmlBuilder().appendHtmlConstant(set).toSafeHtml();
        menu.addItem(new MenuItem(menuHTML, cmd));

    }
}

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

License:Open Source License

private MenuItem createMenuItemForType(final AppCommand command, final String chunkType) {
    SafeHtml menuHTML = new SafeHtmlBuilder().appendHtmlConstant(command.getMenuHTML(false)).toSafeHtml();

    MenuItem menuItem = new MenuItem(menuHTML, new Command() {
        public void execute() {
            host_.switchChunk(chunkType);
        }/*from  w w  w . j  a va2  s .  c om*/
    });

    return menuItem;
}

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  ww. jav a  2 s. c om
                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);//  w  w w .  j  av a2 s .  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/*from  www.  ja v  a2  s  .  c  o 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);// w  w  w. ja v  a 2  s  .c  om
    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/*from w  w  w. j  a v a 2s  .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();
    }
}

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

License:Open Source License

@Override
public void setDownloadLocations(List<LocationData> locations, String md5) {
    if (locations != null && locations.size() > 0) {
        // build a list of links in HTML
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        String displayString = "Download"; // TODO : add display to LocationData
        for (int i = 0; i < locations.size(); i++) {
            LocationData dl = locations.get(i);
            sb.appendHtmlConstant("<a href=\"" + dl.getPath() + "\" target=\"new\">")
                    .appendEscaped(displayString)
                    .appendHtmlConstant("</a> " + AbstractImagePrototype.create(icons.external16()).getHTML());
            if (md5 != null) {
                sb.appendHtmlConstant("&nbsp;<small>md5 checksum: ").appendEscaped(md5)
                        .appendHtmlConstant("</small>");
            }//from w  w w.  ja v a  2  s .  c o  m
            sb.appendHtmlConstant("<br/>");
        }
        safeDownloadHtml = sb.toSafeHtml();

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