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));
});
}
}
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));
}
});
}
Aggregations