Search in sources :

Example 1 with EditorPosition

use of edu.stanford.bmir.gwtcodemirror.client.EditorPosition 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 EditorPosition

use of edu.stanford.bmir.gwtcodemirror.client.EditorPosition in project webprotege by protegeproject.

the class ManchesterSyntaxFrameEditorImpl method setError.

@Override
public void setError(ManchesterSyntaxFrameParseError error) {
    int line = error.getLine() - 1;
    int col = error.getCol();
    editor.setErrorRange(new EditorPosition(line, col), new EditorPosition(line, col + error.getToken().length()));
    errorMessageView.setErrorMessage(error.getMessage());
    errorMessageView.setCurrentToken(error.getToken());
    errorMessageView.setExpectedEntityTypes(error.getExpectedEntityTypes());
    showErrorMessageView();
}
Also used : EditorPosition(edu.stanford.bmir.gwtcodemirror.client.EditorPosition)

Example 3 with EditorPosition

use of edu.stanford.bmir.gwtcodemirror.client.EditorPosition in project webprotege by protegeproject.

the class GetManchesterSyntaxFrameCompletionsActionHandler method execute.

@Nonnull
@Override
public GetManchesterSyntaxFrameCompletionsResult execute(@Nonnull GetManchesterSyntaxFrameCompletionsAction action, @Nonnull ExecutionContext executionContext) {
    String syntax = action.getSyntax();
    int from = action.getFrom();
    String triggerText = syntax.substring(0, from) + "\u0000";
    ManchesterSyntaxFrameParser parser = manchesterSyntaxFrameParserProvider.get();
    try {
        parser.parse(triggerText, action);
    } catch (ParserException e) {
        // ManchesterOWLSyntaxTokenizer tokenizer = new ManchesterOWLSyntaxTokenizer(syntax);
        // List<ManchesterOWLSyntaxTokenizer.Token> tokens = tokenizer.tokenize();
        // ManchesterOWLSyntaxTokenizer.Token intersectingToken;
        // for(ManchesterOWLSyntaxTokenizer.Token token : tokens) {
        // int tokenPos = token.getPos();
        // if(tokenPos <= from && from <= tokenPos + token.getToken().length()) {
        // intersectingToken = token;
        // break;
        // }
        // }
        int lastWordStartIndex = getLastWordIndex(syntax, from);
        int lastWordEndIndex = getWordEnd(syntax, from);
        int fromLineNumber = action.getFromPos().getLineNumber();
        int fromColumnNumber = (action.getFromPos().getColumnNumber() - (from - lastWordStartIndex));
        EditorPosition fromPos = new EditorPosition(fromLineNumber, fromColumnNumber);
        EditorPosition toPos = new EditorPosition(fromLineNumber, action.getFromPos().getColumnNumber() + (lastWordEndIndex - from));
        String lastWordPrefix = syntax.substring(lastWordStartIndex, from).toLowerCase();
        List<AutoCompletionChoice> choices = Lists.newArrayList();
        List<AutoCompletionChoice> entityChoices = getEntityAutocompletionChoices(action, e, fromPos, toPos, lastWordPrefix);
        choices.addAll(entityChoices);
        List<AutoCompletionChoice> expectedKeywordChoices = getKeywordAutoCompletionChoices(e, fromPos, toPos, lastWordPrefix);
        choices.addAll(expectedKeywordChoices);
        List<AutoCompletionChoice> ontologyNameChoices = getNameOntologyAutocompletionChoices(e, fromPos, toPos, lastWordPrefix);
        choices.addAll(ontologyNameChoices);
        return new GetManchesterSyntaxFrameCompletionsResult(new AutoCompletionResult(choices, fromPos));
    }
    return new GetManchesterSyntaxFrameCompletionsResult(AutoCompletionResult.emptyResult());
}
Also used : ParserException(org.semanticweb.owlapi.manchestersyntax.renderer.ParserException) GetManchesterSyntaxFrameCompletionsResult(edu.stanford.bmir.protege.web.shared.frame.GetManchesterSyntaxFrameCompletionsResult) ManchesterSyntaxFrameParser(edu.stanford.bmir.protege.web.server.mansyntax.ManchesterSyntaxFrameParser) EditorPosition(edu.stanford.bmir.gwtcodemirror.client.EditorPosition) AutoCompletionResult(edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult) Nonnull(javax.annotation.Nonnull)

Example 4 with EditorPosition

use of edu.stanford.bmir.gwtcodemirror.client.EditorPosition 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

EditorPosition (edu.stanford.bmir.gwtcodemirror.client.EditorPosition)4 AutoCompletionResult (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult)3 AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)2 ArrayList (java.util.ArrayList)2 MatchResult (com.google.gwt.regexp.shared.MatchResult)1 ManchesterSyntaxFrameParser (edu.stanford.bmir.protege.web.server.mansyntax.ManchesterSyntaxFrameParser)1 EntityLookupResult (edu.stanford.bmir.protege.web.shared.entity.EntityLookupResult)1 LookupEntitiesAction (edu.stanford.bmir.protege.web.shared.entity.LookupEntitiesAction)1 GetManchesterSyntaxFrameCompletionsResult (edu.stanford.bmir.protege.web.shared.frame.GetManchesterSyntaxFrameCompletionsResult)1 GetUserIdCompletionsAction (edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 Nonnull (javax.annotation.Nonnull)1 ParserException (org.semanticweb.owlapi.manchestersyntax.renderer.ParserException)1