Search in sources :

Example 1 with GetUserIdCompletionsAction

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

the class CommentAutoCompleter method handleAutocomplete.

public void handleAutocomplete(@Nonnull String query, @Nonnull EditorPosition caretPosition, int caretPos, @Nonnull AutoCompletionCallback callback) {
    String upToCarent = query.substring(0, caretPos);
    MatchResult result = nameRegExp.exec(upToCarent);
    if (result == null) {
        handleAttemptAtEntityCompletions(upToCarent, caretPosition, callback);
    } else {
        String matchedPartialName = result.getGroup(NAME_GROUP);
        EditorPosition replaceTextFrom = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber() - result.getGroup(0).length());
        dispatchServiceManager.execute(new GetUserIdCompletionsAction(matchedPartialName), userIdsResult -> {
            List<AutoCompletionChoice> suggestions = new ArrayList<>();
            List<UserId> userIds = userIdsResult.getPossibleItemCompletions();
            for (UserId userId : userIds) {
                String userName = userId.getUserName();
                String replacement = getReplacementStringFromUserName(userName);
                EditorPosition replaceTextTo = new EditorPosition(caretPosition.getLineNumber(), caretPosition.getColumnNumber());
                suggestions.add(new AutoCompletionChoice(replacement, userName, "", replaceTextFrom, replaceTextTo));
            }
            callback.completionsReady(new AutoCompletionResult(suggestions, replaceTextFrom));
        });
    }
}
Also used : EditorPosition(edu.stanford.bmir.gwtcodemirror.client.EditorPosition) GetUserIdCompletionsAction(edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) ArrayList(java.util.ArrayList) AutoCompletionResult(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult) AutoCompletionChoice(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 2 with GetUserIdCompletionsAction

use of edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction 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

GetUserIdCompletionsAction (edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction)2 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)2 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)1 AutoCompletionResult (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult)1 EditorPosition (edu.stanford.bmir.gwtcodemirror.client.EditorPosition)1 GetPossibleItemCompletionsResult (edu.stanford.bmir.protege.web.shared.itemlist.GetPossibleItemCompletionsResult)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1