use of com.google.gwt.cell.client.AbstractSafeHtmlCell 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");
}
Aggregations