List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant
public SafeHtmlBuilder appendHtmlConstant(String html)
From source file:org.rstudio.core.client.widget.Base64ImageCell.java
License:Open Source License
@Override public void render(com.google.gwt.cell.client.Cell.Context ctx, String value, SafeHtmlBuilder builder) { if (value != null) { builder.appendHtmlConstant("<img src=\"" + value + "\""); // apply width and height if specified if (width_ > 0) builder.appendHtmlConstant(" width=\"" + width_ + "\""); if (height_ > 0) builder.appendHtmlConstant(" height=\"" + height_ + "\""); builder.appendHtmlConstant("/>"); }/*from w w w.j a v a 2s . c o m*/ }
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; }/* www . j a v a 2 s. c o m*/ 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 w w w. j ava 2s .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(" "); 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.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 w w w . j ava 2s . com*/ 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;//from w w w.j av a 2s.c o m 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(); } }; }
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 w w w. j ava 2 s. com*/ 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.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//from ww w. j ava2s . 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 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 a v 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 + " "; 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 w ww . jav a 2 s . com 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(" "); 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 av 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; }