Search in sources :

Example 1 with LookupEntitiesAction

use of edu.stanford.bmir.protege.web.shared.entity.LookupEntitiesAction in project webprotege by protegeproject.

the class CommentAutoCompleter method handleAttemptAtEntityCompletions.

private void handleAttemptAtEntityCompletions(String queryUpToCaret, EditorPosition caretPos, AutoCompletionCallback callback) {
    // Last index of space or 0 if there are not spaces
    int wordStart = queryUpToCaret.lastIndexOf(" ") + 1;
    int wordFragmentLen = queryUpToCaret.length() - wordStart;
    String wordFragment = queryUpToCaret.substring(wordStart);
    if (wordFragment.isEmpty()) {
        callback.completionsReady(new AutoCompletionResult());
        return;
    }
    dispatchServiceManager.execute(new LookupEntitiesAction(projectId, lookUpEntities(wordFragment)), result -> {
        List<AutoCompletionChoice> choices = new ArrayList<>();
        EditorPosition pos = new EditorPosition(caretPos.getLineNumber(), caretPos.getColumnNumber() - wordFragmentLen);
        for (final EntityLookupResult entity : result.getEntityLookupResults()) {
            choices.add(new AutoCompletionChoice(formatReplacementTest(entity), entity.getOWLEntityData().getBrowserText(), "", pos, caretPos));
        }
        AutoCompletionResult autoCompletionResult = new AutoCompletionResult(choices, pos);
        callback.completionsReady(autoCompletionResult);
    });
}
Also used : EditorPosition(edu.stanford.bmir.gwtcodemirror.client.EditorPosition) LookupEntitiesAction(edu.stanford.bmir.protege.web.shared.entity.LookupEntitiesAction) ArrayList(java.util.ArrayList) AutoCompletionResult(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult) EntityLookupResult(edu.stanford.bmir.protege.web.shared.entity.EntityLookupResult) AutoCompletionChoice(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)

Aggregations

AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)1 AutoCompletionResult (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult)1 EditorPosition (edu.stanford.bmir.gwtcodemirror.client.EditorPosition)1 EntityLookupResult (edu.stanford.bmir.protege.web.shared.entity.EntityLookupResult)1 LookupEntitiesAction (edu.stanford.bmir.protege.web.shared.entity.LookupEntitiesAction)1 ArrayList (java.util.ArrayList)1