@Override
public void onFindActivity(final Request request, final Callback callback)
{
final String query = request.getQuery();
final Highlighter highlighter = new Highlighter(query);
dispatcher.execute(new FindActivityAction(query), new KarakaCallback<FindActivityResult>(getEventBus())
{
@Override
public void onSuccess(final FindActivityResult result)
{
List<Activity> activities = result.getActivities();
if (!activities.isEmpty())
{
List<NamedModelSuggestion<Activity>> suggestions = new ArrayList<NamedModelSuggestion<Activity>>();
for (Activity activity : activities)
{
StringBuilder displayString = new StringBuilder();
displayString.append(activity.getName());
if (activity.getDescription() != null)
{
displayString.append(": ").append(activity.getDescription());
}
if (activity.getProject() != null)
{
displayString.append(", (Project: ").append(activity.getProject().getName()).append(")");
}
NamedModelSuggestion<Activity> suggestion = new NamedModelSuggestion<Activity>(activity,
activity.getName(), highlighter.highlight(displayString.toString()));
suggestions.add(suggestion);
}
callback.onSuggestionsReady(request, new Response(suggestions));
}
}