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();
}
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");
}
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);
}
}
}
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);
}
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 "-";
}
Aggregations