Search in sources :

Example 1 with GetPossibleItemCompletionsResult

use of edu.stanford.bmir.protege.web.shared.itemlist.GetPossibleItemCompletionsResult in project webprotege by protegeproject.

the class UserIdSuggestOracle method requestSuggestions.

@Override
public void requestSuggestions(final Request request, final Callback callback) {
    dispatchServiceManager.execute(new GetUserIdCompletionsAction(request.getQuery()), new DispatchServiceCallback<GetPossibleItemCompletionsResult<UserId>>() {

        @Override
        public void handleSuccess(GetPossibleItemCompletionsResult<UserId> result) {
            Collection<Suggestion> suggestions = new ArrayList<>();
            for (final UserId userId : result.getPossibleItemCompletions()) {
                suggestions.add(new Suggestion() {

                    @Override
                    public String getDisplayString() {
                        String userName = userId.getUserName();
                        String query = request.getQuery();
                        int queryIndex = userName.toLowerCase().indexOf(query.toLowerCase());
                        if (queryIndex != -1) {
                            return userName.substring(0, queryIndex) + "<span style='font-weight: bold;'>" + userName.substring(queryIndex, queryIndex + query.length()) + "</span>" + userName.substring(queryIndex + query.length());
                        } else {
                            return userName;
                        }
                    }

                    @Override
                    public String getReplacementString() {
                        return userId.getUserName();
                    }
                });
            }
            callback.onSuggestionsReady(request, new Response(suggestions));
        }
    });
}
Also used : GetPossibleItemCompletionsResult(edu.stanford.bmir.protege.web.shared.itemlist.GetPossibleItemCompletionsResult) GetUserIdCompletionsAction(edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Collection(java.util.Collection)

Aggregations

GetPossibleItemCompletionsResult (edu.stanford.bmir.protege.web.shared.itemlist.GetPossibleItemCompletionsResult)1 GetUserIdCompletionsAction (edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 Collection (java.util.Collection)1