Search in sources :

Example 81 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project gerrit by GerritCodeReview.

the class HighlightSuggestion method getDisplayString.

@Override
public String getDisplayString() {
    int start = 0;
    int keyLen = keyword.length();
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    for (; ; ) {
        int index = value.indexOf(keyword, start);
        if (index == -1) {
            builder.appendEscaped(value.substring(start));
            break;
        }
        builder.appendEscaped(value.substring(start, index));
        builder.appendHtmlConstant("<strong>");
        start = index + keyLen;
        builder.appendEscaped(value.substring(index, start));
        builder.appendHtmlConstant("</strong>");
    }
    return builder.toSafeHtml().asString();
}
Also used : SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 82 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project opennms by OpenNMS.

the class SearchControl method initializeCellAutocompleteWidget.

private void initializeCellAutocompleteWidget() {
    final AbstractSafeHtmlRenderer<NodeMarker> renderer = new AbstractSafeHtmlRenderer<NodeMarker>() {

        @Override
        public SafeHtml render(final NodeMarker marker) {
            final SafeHtmlBuilder builder = new SafeHtmlBuilder();
            final String search = m_inputBox.getValue();
            builder.appendHtmlConstant("<div class=\"autocomplete-label\">");
            builder.appendHtmlConstant(marker.getNodeLabel());
            builder.appendHtmlConstant("</div>");
            String additionalSearchInfo = null;
            if (search != null && (search.contains(":") || search.contains("="))) {
                final String searchKey = search.replaceAll("[\\:\\=].*$", "").toLowerCase();
                LOG.info("searchKey = " + searchKey);
                final Map<String, String> props = marker.getProperties();
                if ("category".equals(searchKey) || "categories".equals(searchKey)) {
                    final String catString = props.get("categories");
                    if (catString != null) {
                        additionalSearchInfo = catString;
                    }
                }
                for (final Map.Entry<String, String> entry : props.entrySet()) {
                    final String key = entry.getKey().toLowerCase();
                    final Object value = entry.getValue();
                    if (key.equals(searchKey) && m_labels.containsKey(key)) {
                        additionalSearchInfo = m_labels.get(key) + ": " + value;
                        break;
                    }
                }
            }
            if (additionalSearchInfo != null) {
                builder.appendHtmlConstant("<div class=\"autocomplete-additional-info\">").appendHtmlConstant(additionalSearchInfo).appendHtmlConstant("</div>");
            }
            return builder.toSafeHtml();
        }
    };
    final AbstractSafeHtmlCell<NodeMarker> cell = new AbstractSafeHtmlCell<NodeMarker>(renderer, "keydown", "click", "dblclick", "touchstart") {

        @Override
        public void onBrowserEvent(final Context context, final com.google.gwt.dom.client.Element parent, final NodeMarker value, final NativeEvent event, final ValueUpdater<NodeMarker> valueUpdater) {
            LOG.info("SearchControl.AutocompleteCell.onBrowserEvent(): context = " + context + ", parent = " + parent + ", value = " + value + ", event = " + event);
            if (m_stateManager.handleAutocompleteEvent(event)) {
                super.onBrowserEvent(context, parent, value, event, valueUpdater);
            }
        }

        @Override
        protected void render(final Context context, final SafeHtml data, final SafeHtmlBuilder builder) {
            builder.appendHtmlConstant("<div class=\"autocomplete-entry\">");
            if (data != null) {
                builder.append(data);
            }
            builder.appendHtmlConstant("</div>");
        }
    };
    m_autoComplete = new CellList<NodeMarker>(cell);
    m_autoComplete.setSelectionModel(m_selectionModel);
    m_autoComplete.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION);
    m_autoComplete.setVisible(false);
    m_autoComplete.addStyleName("search-autocomplete");
    setIdIfMissing(m_autoComplete, "searchControl.autoComplete");
}
Also used : AbstractSafeHtmlRenderer(com.google.gwt.text.shared.AbstractSafeHtmlRenderer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Element(com.google.gwt.user.client.Element) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker) NodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMarker) ValueUpdater(com.google.gwt.cell.client.ValueUpdater) AbstractSafeHtmlCell(com.google.gwt.cell.client.AbstractSafeHtmlCell) HashMap(java.util.HashMap) Map(java.util.Map) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 83 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project kie-wb-common by kiegroup.

the class ProjectItemViewImpl method setProject.

@Override
public void setProject(final ExampleProject project, boolean selected) {
    final SafeHtmlBuilder shb = new SafeHtmlBuilder();
    shb.appendEscaped(project.getName());
    projectName.setInnerSafeHtml(shb.toSafeHtml());
    projectSelected.setChecked(selected);
    if (project.getTags() != null) {
        for (String tagName : project.getTags()) {
            TagItemView tagItemView = tagItemViewInstance.get();
            tagItemView.setName(tagName);
            tagItemView.hideCloseIcon();
            Node tagNode = tagItemView.asWidget().getElement();
            tagList.appendChild(tagNode);
        }
    }
}
Also used : Node(com.google.gwt.dom.client.Node) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 84 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project kie-wb-common by kiegroup.

the class NotificationMessageUtilsTest method testDiagramValidationMessage.

@Test
@SuppressWarnings("unchecked")
public void testDiagramValidationMessage() {
    final ConstraintViolation<?> rootViolation = mock(ConstraintViolation.class);
    final Path propertyPath = mock(Path.class);
    when(propertyPath.toString()).thenReturn("path1");
    when(rootViolation.getPropertyPath()).thenReturn(propertyPath);
    when(rootViolation.getMessage()).thenReturn("message1");
    final ModelBeanViolation beanViolation = ModelBeanViolationImpl.Builder.build(rootViolation);
    final RuleViolation ruleViolation = mock(RuleViolation.class);
    final DiagramElementViolation<RuleViolation> diagramViolation = mock(DiagramElementViolation.class);
    when(diagramViolation.getUUID()).thenReturn("uuid1");
    when(diagramViolation.getModelViolations()).thenReturn(Collections.singletonList(beanViolation));
    when(diagramViolation.getGraphViolations()).thenReturn(Collections.singletonList(ruleViolation));
    when(ruleViolation.getViolationType()).thenReturn(Violation.Type.WARNING);
    when(translationService.getViolationMessage(eq(ruleViolation))).thenReturn("rv1");
    when(translationService.getValue(eq("aKey"))).thenReturn("aValue");
    String message = NotificationMessageUtils.getDiagramValidationsErrorMessage(translationService, "aKey", Collections.singleton(diagramViolation));
    message = new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().asString();
    assertEquals("aValue." + HTML_NEW_LINE + "R" + COLON + HTML_NEW_LINE + OPEN_BRA + "E" + COLON + "uuid1" + CLOSE_BRA + HTML_NEW_LINE + "(WARNING) " + HTML_OPEN_COMMENT + "path1" + HTML_CLOSE_COMMENT + "message1" + HTML_NEW_LINE + "(WARNING) rv1" + HTML_NEW_LINE, message);
}
Also used : Path(javax.validation.Path) ModelBeanViolation(org.kie.workbench.common.stunner.core.validation.ModelBeanViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Test(org.junit.Test)

Example 85 with SafeHtmlBuilder

use of com.google.gwt.safehtml.shared.SafeHtmlBuilder in project activityinfo by bedatadriven.

the class SiteRenderer method formatValue.

protected String formatValue(IndicatorDTO indicator, Object value) {
    if (indicator.getType() == FieldTypeClass.QUANTITY) {
        if (value instanceof Double) {
            return indicatorValueFormatter.format((Double) value);
        }
    } else if (indicator.getType() == FieldTypeClass.FREE_TEXT) {
        if (value instanceof String) {
            return htmlEscape((String) value);
        }
    } else if (indicator.getType() == FieldTypeClass.NARRATIVE) {
        if (value instanceof String) {
            SafeHtmlBuilder html = new SafeHtmlBuilder();
            html.appendEscapedLines((String) value);
            return html.toSafeHtml().asString();
        }
    }
    return "-";
}
Also used : SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Aggregations

SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)143 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)26 Test (org.junit.Test)18 Column (com.google.gwt.user.cellview.client.Column)17 Cell (com.google.gwt.cell.client.Cell)14 BaseColumnFieldDiff (org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff)12 Context (com.google.gwt.cell.client.Cell.Context)7 MenuItem (com.google.gwt.user.client.ui.MenuItem)7 NativeEvent (com.google.gwt.dom.client.NativeEvent)6 Command (com.google.gwt.user.client.Command)6 ArrayList (java.util.ArrayList)6 ValueUpdater (com.google.gwt.cell.client.ValueUpdater)5 GWT (com.google.gwt.core.client.GWT)5 Element (com.google.gwt.dom.client.Element)5 AbstractCell (com.google.gwt.cell.client.AbstractCell)4 ClickableTextCell (com.google.gwt.cell.client.ClickableTextCell)4 TextCell (com.google.gwt.cell.client.TextCell)4 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)4 ImageResource (com.google.gwt.resources.client.ImageResource)4 Map (java.util.Map)4