@Override
public void onSuccess(List<SearchSuggestion> results) {
try {
ListGrid searchBarPickListGrid = searchBar.getPickListGrid();
DataSource ds = searchBarPickListGrid.getDataSource();
// create the datasource if needed
if (null == ds) {
ds = new DataSource();
ds.setClientOnly(true);
DataSourceTextField idField = new DataSourceTextField(ATTR_ID, "Id");
idField.setPrimaryKey(true);
idField.setCanView(false);
DataSourceTextField valueField = new DataSourceTextField(ATTR_VALUE, "Value");
ds.setFields(idField, valueField);
searchBarPickListGrid.setDataSource(ds);
searchBarPickListGrid.getField(ATTR_VALUE).setShowHover(true);
searchBarPickListGrid.getField(ATTR_VALUE).setHoverCustomizer(new HoverCustomizer() {
public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
if (null == record) {
return "";
}
String kind = record.getAttribute(ATTR_KIND);
if (kind.equals("SAVED") || kind.equals("GLOBAL")) {
String pattern = record.getAttribute(ATTR_PATTERN);
if (!(null == pattern || pattern.isEmpty())) {
return pattern;
}
}
return "";
}
});
} else {
ds.invalidateCache();
}
for (SearchSuggestion searchSuggestion : results) {
Log.debug("search tab aware Suggestions: " + searchSuggestion.getKind() + ", "
+ searchSuggestion.getValue() + ", " + searchSuggestion.getLabel());
ListGridRecord record = new ListGridRecord();
record.setAttribute(ATTR_ID, searchSuggestion.getValue());
if (null != searchSuggestion.getKind()) {
record.setAttribute(ATTR_KIND, searchSuggestion.getKind().getDisplayName());
}
record.setAttribute(ATTR_NAME, searchSuggestion.getLabel());
record.setAttribute(ATTR_VALUE, searchSuggestion.getValue());
String pattern = searchSuggestion.getOptional();
record.setAttribute(ATTR_PATTERN, (null == pattern) ? "" : pattern);
ds.addData(record);
}
try {
searchBarPickListGrid.setData(new ListGridRecord[] {});
searchBarPickListGrid.fetchData();